-
-
Notifications
You must be signed in to change notification settings - Fork 104
/
bootup.js
147 lines (121 loc) · 3.64 KB
/
bootup.js
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
require('electron-reload')(__dirname);
const autoUpdater = require('electron-updater').autoUpdater;
const path = require('path');
const ShortcutManager = require('electron-localshortcut');
const {
app,
BrowserWindow,
globalShortcut,
ipcMain,
Menu
} = 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;
class Bootup {
constructor(mainWindow) {
this._mainWindow = mainWindow;
this._setupBrowserWindow();
}
_resetMenus() {
// initialize empty menus, all logics will be handled in AppMenus
const menu = Menu.buildFromTemplate([]);
Menu.setApplicationMenu(menu);
}
_setupBrowserWindow() {
// This may help the black screen / option issue
app.disableHardwareAcceleration();
// Quit when all windows are closed.
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', () => {
if (!this._mainWindow) {
this._spawnWindow();
}
});
// This method will be called when Electron has done everything
// initialization and ready for creating browser windows.
app.on('ready', () => {
this._resetMenus();
this._spawnWindow();
this._bindShortcuts();
this._bindAutoUpdate();
});
}
_spawnWindow() {
// Create the browser window.
this._mainWindow = new BrowserWindow({
'icon': kakuIcon,
'width': 1060,
'height': 600,
'minWidth': 1060,
'minHeight': 600,
'frame': false
});
// and load the index.html of the app.
this._mainWindow.loadURL('file://' + __dirname + '/index.html');
// Emitted when the window is closed.
this._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.
this._mainWindow = null;
});
}
_bindShortcuts() {
const localKeys = [
'Escape'
];
const globalKeys = [
'MediaNextTrack',
'MediaPreviousTrack',
'MediaPlayPause'
];
globalKeys.forEach(key => {
globalShortcut.register(key, () => {
this._emitShortcutEvent(this._mainWindow, key);
});
});
localKeys.forEach(key => {
ShortcutManager.register(key, () => {
this._emitShortcutEvent(this._mainWindow, key);
});
});
}
_bindAutoUpdate() {
autoUpdater.on('checking-for-update', (e) => {
this._mainWindow.webContents.send('au-checking-for-update', e);
});
autoUpdater.on('update-available', (e) => {
this._mainWindow.webContents.send('au-update-available', e);
});
autoUpdater.on('update-not-available', (e) => {
this._mainWindow.webContents.send('au-update-not-available', e);
});
autoUpdater.on('error', (e, error) => {
this._mainWindow.webContents.send('au-error', e, error);
});
autoUpdater.on('update-downloaded', (e, info) => {
this._mainWindow.webContents.send('au-update-downloaded', e, info);
});
ipcMain.on('au-check-for-update', (e, isDev) => {
if (!isDev) {
autoUpdater.checkForUpdates();
}
});
ipcMain.on('au-quit-and-install', () => {
autoUpdater.quitAndInstall();
});
}
_emitShortcutEvent(win, shortcut) {
if (win) {
win.webContents.send('key-' + shortcut);
}
}
}
new Bootup(mainWindow);