Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 18 additions & 19 deletions src/config/actions.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
const {app} = require("electron");

const providers = require("../ServiceProviders/providers");
const fullscreenToggle = require("../lib/fullscreen-toggle");
const { app } = require('electron')

const providers = require('../ServiceProviders/providers')
const fullscreenToggle = require('../lib/fullscreen-toggle')

module.exports = {
keys: [
{
key: "CommandOrControl+Shift+V",
key: 'CommandOrControl+Shift+V',
action: (mainWin) => {
return () => {
providers.run(mainWin);
providers.run(mainWin)
}
}
},
{
key: "CommandOrControl+H+Q",
key: 'CommandOrControl+H+Q',
action: (mainWin) => {
return () => {
app.quit()
Expand All @@ -24,40 +23,40 @@ module.exports = {
},

{
key: "CommandOrControl+Shift+1",
key: 'CommandOrControl+Shift+1',
action: (mainWin) => {
return () => {
mainWin.webContents.send("pause", "ping");
mainWin.webContents.send('pause', 'ping')
}
}
},
{
key: "CommandOrControl+Shift+2",
key: 'CommandOrControl+Shift+2',
action: (mainWin) => {
return () => {
mainWin.webContents.send("play", "ping");
mainWin.webContents.send('play', 'ping')
}
}
},
{
key: "Alt+Shift+F",
key: 'Alt+Shift+F',
action: (mainWin) => {
return () => {
fullscreenToggle(mainWin, false);
fullscreenToggle(mainWin, false)
}
}
},
{
key: "CommandOrControl+Shift+T",
key: 'CommandOrControl+Shift+T',
action: (mainWin) => {
// toggles translucent mode
return () => {
let translucency = 1;
if (mainWin.getOpacity() == 1) {
translucency = 0.7;
let translucency = 1
if (mainWin.getOpacity() === 1) {
translucency = 0.7
}
mainWin.setOpacity(translucency);
mainWin.setIgnoreMouseEvents(translucency < 1);
mainWin.setOpacity(translucency)
mainWin.setIgnoreMouseEvents(translucency < 1)
}
}
}
Expand Down
15 changes: 6 additions & 9 deletions src/core/action-manager.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
const actions = require('../config/actions')
const {globalShortcut} = require("electron");

const { globalShortcut } = require('electron')

/**
* A global action manager, which is responsible for listening
* actions that can be managed by H2
*/
class ActionManager {
constructor(mainWin) {
this.actions = actions;
this.mainWin = mainWin;
this.globals = [];
constructor (mainWin) {
this.actions = actions
this.mainWin = mainWin
this.globals = []
}

applyActions() {
applyActions () {
this.actions['keys'].forEach((key) => {

this.globals.push(
globalShortcut.register(key.key, key.action(this.mainWin))
)

})
}
}
Expand Down
1 change: 1 addition & 0 deletions src/lib/notifications.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* global Notification */
module.exports = function (message, sound = true, onclick = null) {
let notif = new Notification('H2', {
body: message
Expand Down
150 changes: 75 additions & 75 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,20 @@ const {
BrowserWindow,
globalShortcut,
session,
ipcMain,
Notification
} = require("electron");
const providers = require("./ServiceProviders/providers");
const fullscreenToggle = require("./lib/fullscreen-toggle");
const utils = require("./lib/util");
const path = require("path");
const ActionManager = require("./core/action-manager")
ipcMain
} = require('electron')
const providers = require('./ServiceProviders/providers')
const fullscreenToggle = require('./lib/fullscreen-toggle')
const utils = require('./lib/util')
const path = require('path')
const ActionManager = require('./core/action-manager')

// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let mainWindow;
let tray;
let mainWindow
let tray

function createWindow() {
function createWindow () {
// create config
let config = {
width: 400,
Expand All @@ -29,40 +28,40 @@ function createWindow() {
plugins: true,
preload: path.join(__dirname, 'preload.js')
},
titleBarStyle: "customButtonsOnHover",
};
titleBarStyle: 'customButtonsOnHover'
}

// Create the browser window.
mainWindow = new BrowserWindow(config);
mainWindow.setMenu(null);
mainWindow = new BrowserWindow(config)
mainWindow.setMenu(null)

if (process.platform == "darwin") app.dock.hide();
if (process.platform === 'darwin') app.dock.hide()

mainWindow.setVisibleOnAllWorkspaces(true);
mainWindow.setFullScreenable(false);
mainWindow.setVisibleOnAllWorkspaces(true)
mainWindow.setFullScreenable(false)

// and load the index.html of the app.
mainWindow.loadFile('src/index.html');
mainWindow.loadFile('src/index.html')
// mainWindow.loadURL('https://www.netflix.com')

// Open the DevTools.
if (process.env.DEV==1) mainWindow.webContents.openDevTools();
if (process.env.DEV === 1) mainWindow.webContents.openDevTools()

// Emitted when the window is closed.
mainWindow.on("closed", function() {
mainWindow.on('closed', function () {
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.

mainWindow = null;
});
mainWindow = null
})

// Disable new browser windows and popups
mainWindow.webContents.on("new-window", function(e, url) {
e.preventDefault();
providers.run(mainWindow, url);
mainWindow.focus();
});
mainWindow.webContents.on('new-window', function (e, url) {
e.preventDefault()
providers.run(mainWindow, url)
mainWindow.focus()
})

let actionManager = new ActionManager(mainWindow)
actionManager.applyActions()
Expand All @@ -75,89 +74,90 @@ function createWindow() {
}

let createMenuTray = () => {
tray = new Tray(__dirname + "/assets/images/tray.png");

tray = new Tray(path.join(__dirname, 'assets/images/tray.png'))
const trayMenus = [
{ role: "about" },
{ role: 'about' },
{
label: "Exit Fullscreen",
click() {
fullscreenToggle(mainWindow, true);
label: 'Exit Fullscreen',
click () {
fullscreenToggle(mainWindow, true)
}
},
{
label: "Quit",
click() {
app.quit();
label: 'Quit',
click () {
app.quit()
}
},
{
label: "Bring H2 to the front",
click() {
utils.resetWindowToFloat(mainWindow);
label: 'Bring H2 to the front',
click () {
utils.resetWindowToFloat(mainWindow)
}
}
];
]

const contextMenu = Menu.buildFromTemplate(trayMenus);
const contextMenu = Menu.buildFromTemplate(trayMenus)

tray.setToolTip("H2");
tray.setContextMenu(contextMenu);
tray.setTitle("H2");
tray.on("click", function(event) {
console.log("called");
!mainWindow.isFocused() ? mainWindow.focus() : true;
});
};
tray.setToolTip('H2')
tray.setContextMenu(contextMenu)
tray.setTitle('H2')
tray.on('click', function (event) {
console.log('called')
if (!mainWindow.isFocused()) {
mainWindow.focus()
}
})
}

// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.

app.on("ready", () => {
session.defaultSession.clearStorageData();
createWindow();
utils.resetWindowToFloat(mainWindow);
createMenuTray();
});
app.on('ready', () => {
session.defaultSession.clearStorageData()
createWindow()
utils.resetWindowToFloat(mainWindow)
createMenuTray()
})

app.on("will-quit", () => {
app.on('will-quit', () => {
// Unregister all shortcuts.
globalShortcut.unregisterAll();
});
globalShortcut.unregisterAll()
})

// Quit when all windows are closed.
app.on("window-all-closed", function() {
app.on('window-all-closed', function () {
// On OS X it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
// if (process.platform !== 'darwin') {
app.quit();
app.quit()
// }
});
})
// Unregister all shortcuts.
app.on("will-quit", () => {
globalShortcut.unregisterAll();
});
app.on('will-quit', () => {
globalShortcut.unregisterAll()
})

app.on("activate", function() {
app.on('activate', function () {
// On OS X it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (mainWindow === null) {
createWindow();
createWindow()
}
});
})

ipcMain.on("exit-full-screen", () => {
fullscreenToggle(mainWindow, true);
});
ipcMain.on('exit-full-screen', () => {
fullscreenToggle(mainWindow, true)
})

ipcMain.on("openLink", (ev, arg) => {
ipcMain.on('openLink', (ev, arg) => {
console.log(arg)
mainWindow.loadURL(arg)
mainWindow.webContents.on("did-finish-load", (event, url) => {
mainWindow.webContents.on('did-finish-load', (event, url) => {
console.log('asking')
mainWindow.webContents.send("send-full-screen", "ping")
mainWindow.webContents.send('send-full-screen', 'ping')
})
});
})
// In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and require them here.
Loading