forked from EragonJ/Kaku
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootup.js
More file actions
83 lines (68 loc) · 2.17 KB
/
bootup.js
File metadata and controls
83 lines (68 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
const path = require('path');
const ShortcutManager = require('electron-localshortcut');
const { app, BrowserWindow } = require('electron');
const iconsFolder = path.join(__dirname, 'src', 'public', 'images', 'icons');
const kakuIcon = path.join(iconsFolder, 'kaku.png');
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the javascript object is GCed.
let mainWindow = null;
let isWindowLoaded = false;
class Bootup {
constructor() {
this._setupBrowserWindow();
}
_setupBrowserWindow() {
// This may help the black screen / option issue
app.disableHardwareAcceleration();
// Quit when all windows are closed.
app.on('window-all-closed', () => {
app.quit();
});
// This method will be called when Electron has done everything
// initialization and ready for creating browser windows.
app.on('ready', () => {
// Create the browser window.
mainWindow = new BrowserWindow({
'icon': kakuIcon,
'width': 1060,
'height': 600,
'minWidth': 1060,
'minHeight': 600,
'frame': false
});
// and load the index.html of the app.
mainWindow.loadURL('file://' + __dirname + '/index.html');
// Emitted when the window is closed.
mainWindow.on('closed', () => {
// 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.webContents.on('did-finish-load', () => {
isWindowLoaded = true;
});
this._bindShortcuts();
});
}
_bindShortcuts() {
const shortcuts = [
'MediaNextTrack',
'MediaPreviousTrack',
'MediaPlayPause',
'Escape'
];
shortcuts.forEach(shortcut => {
ShortcutManager.register(shortcut, () => {
this._emitShortcutEvent(mainWindow, isWindowLoaded, shortcut);
});
});
}
_emitShortcutEvent(win, isLoaded, shortcut) {
if (isLoaded) {
win.webContents.send('key-' + shortcut);
}
}
}
// booting Kaku
new Bootup();