Skip to content

Commit 20dd2c0

Browse files
committed
tidy code
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
1 parent 8a4a6b2 commit 20dd2c0

1 file changed

Lines changed: 29 additions & 29 deletions

File tree

‎electron_app/src/electron-main.js‎

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const checkSquirrelHooks = require('./squirrelhooks');
2323
if (checkSquirrelHooks()) return;
2424

2525
const argv = require('minimist')(process.argv);
26-
const electron = require('electron');
26+
const {app, ipcMain, powerSaveBlocker, BrowserWindow, Menu} = require('electron');
2727
const AutoLaunch = require('auto-launch');
2828

2929
const tray = require('./tray');
@@ -33,8 +33,8 @@ const updater = require('./updater');
3333

3434
const windowStateKeeper = require('electron-window-state');
3535

36-
if (argv.profile) {
37-
electron.app.setPath('userData', `${electron.app.getPath('userData')}-${argv.profile}`);
36+
if (argv['profile']) {
37+
app.setPath('userData', `${app.getPath('userData')}-${argv['profile']}`);
3838
}
3939

4040
let vectorConfig = {};
@@ -62,14 +62,14 @@ process.on('uncaughtException', function(error) {
6262
});
6363

6464
let focusHandlerAttached = false;
65-
electron.ipcMain.on('setBadgeCount', function(ev, count) {
66-
electron.app.setBadgeCount(count);
67-
if (count === 0) {
65+
ipcMain.on('setBadgeCount', function(ev, count) {
66+
app.setBadgeCount(count);
67+
if (count === 0 && mainWindow) {
6868
mainWindow.flashFrame(false);
6969
}
7070
});
7171

72-
electron.ipcMain.on('loudNotification', function() {
72+
ipcMain.on('loudNotification', function() {
7373
if (process.platform === 'win32' && mainWindow && !mainWindow.isFocused() && !focusHandlerAttached) {
7474
mainWindow.flashFrame(true);
7575
mainWindow.once('focus', () => {
@@ -81,26 +81,26 @@ electron.ipcMain.on('loudNotification', function() {
8181
});
8282

8383
let powerSaveBlockerId;
84-
electron.ipcMain.on('app_onAction', function(ev, payload) {
84+
ipcMain.on('app_onAction', function(ev, payload) {
8585
switch (payload.action) {
8686
case 'call_state':
87-
if (powerSaveBlockerId && electron.powerSaveBlocker.isStarted(powerSaveBlockerId)) {
87+
if (powerSaveBlockerId && powerSaveBlocker.isStarted(powerSaveBlockerId)) {
8888
if (payload.state === 'ended') {
89-
electron.powerSaveBlocker.stop(powerSaveBlockerId);
89+
powerSaveBlocker.stop(powerSaveBlockerId);
9090
}
9191
} else {
9292
if (payload.state === 'connected') {
93-
powerSaveBlockerId = electron.powerSaveBlocker.start('prevent-display-sleep');
93+
powerSaveBlockerId = powerSaveBlocker.start('prevent-display-sleep');
9494
}
9595
}
9696
break;
9797
}
9898
});
9999

100100

101-
electron.app.commandLine.appendSwitch('--enable-usermedia-screen-capturing');
101+
app.commandLine.appendSwitch('--enable-usermedia-screen-capturing');
102102

103-
const shouldQuit = electron.app.makeSingleInstance((commandLine, workingDirectory) => {
103+
const shouldQuit = app.makeSingleInstance((commandLine, workingDirectory) => {
104104
// If other instance launched with --hidden then skip showing window
105105
if (commandLine.includes('--hidden')) return;
106106

@@ -114,7 +114,7 @@ const shouldQuit = electron.app.makeSingleInstance((commandLine, workingDirector
114114

115115
if (shouldQuit) {
116116
console.log('Other instance detected: exiting');
117-
electron.app.exit();
117+
app.exit();
118118
}
119119

120120

@@ -139,7 +139,7 @@ const settings = {
139139
},
140140
};
141141

142-
electron.ipcMain.on('settings_get', async function(ev) {
142+
ipcMain.on('settings_get', async function(ev) {
143143
const data = {};
144144

145145
try {
@@ -153,15 +153,15 @@ electron.ipcMain.on('settings_get', async function(ev) {
153153
}
154154
});
155155

156-
electron.ipcMain.on('settings_set', function(ev, key, value) {
156+
ipcMain.on('settings_set', function(ev, key, value) {
157157
console.log(key, value);
158158
if (settings[key] && settings[key].set) {
159159
settings[key].set(value);
160160
}
161161
});
162162

163-
electron.app.on('ready', () => {
164-
if (argv.devtools) {
163+
app.on('ready', () => {
164+
if (argv['devtools']) {
165165
try {
166166
const { default: installExt, REACT_DEVELOPER_TOOLS, REACT_PERF } = require('electron-devtools-installer');
167167
installExt(REACT_DEVELOPER_TOOLS)
@@ -176,9 +176,9 @@ electron.app.on('ready', () => {
176176
}
177177

178178

179-
if (vectorConfig.update_base_url) {
180-
console.log(`Starting auto update with base URL: ${vectorConfig.update_base_url}`);
181-
updater.start(vectorConfig.update_base_url);
179+
if (vectorConfig['update_base_url']) {
180+
console.log(`Starting auto update with base URL: ${vectorConfig['update_base_url']}`);
181+
updater.start(vectorConfig['update_base_url']);
182182
} else {
183183
console.log('No update_base_url is defined: auto update is disabled');
184184
}
@@ -191,7 +191,7 @@ electron.app.on('ready', () => {
191191
defaultHeight: 768,
192192
});
193193

194-
mainWindow = global.mainWindow = new electron.BrowserWindow({
194+
mainWindow = global.mainWindow = new BrowserWindow({
195195
icon: iconPath,
196196
show: false,
197197
autoHideMenuBar: true,
@@ -202,7 +202,7 @@ electron.app.on('ready', () => {
202202
height: mainWindowState.height,
203203
});
204204
mainWindow.loadURL(`file://${__dirname}/../../webapp/index.html`);
205-
electron.Menu.setApplicationMenu(vectorMenu);
205+
Menu.setApplicationMenu(vectorMenu);
206206

207207
// explicitly hide because setApplicationMenu on Linux otherwise shows...
208208
// https://github.com/electron/electron/issues/9621
@@ -217,7 +217,7 @@ electron.app.on('ready', () => {
217217
mainWindow.once('ready-to-show', () => {
218218
mainWindowState.manage(mainWindow);
219219

220-
if (!argv.hidden) {
220+
if (!argv['hidden']) {
221221
console.log("Showing window");
222222
mainWindow.show();
223223
} else {
@@ -254,15 +254,15 @@ electron.app.on('ready', () => {
254254
webContentsHandler(mainWindow.webContents);
255255
});
256256

257-
electron.app.on('window-all-closed', () => {
258-
electron.app.quit();
257+
app.on('window-all-closed', () => {
258+
app.quit();
259259
});
260260

261-
electron.app.on('activate', () => {
261+
app.on('activate', () => {
262262
mainWindow.show();
263263
});
264264

265-
electron.app.on('before-quit', () => {
265+
app.on('before-quit', () => {
266266
global.appQuitting = true;
267267
if (mainWindow) {
268268
mainWindow.webContents.send('before-quit');
@@ -273,4 +273,4 @@ electron.app.on('before-quit', () => {
273273
// installer uses for the shortcut icon.
274274
// This makes notifications work on windows 8.1 (and is
275275
// a noop on other platforms).
276-
electron.app.setAppUserModelId('com.squirrel.riot-web.Riot');
276+
app.setAppUserModelId('com.squirrel.riot-web.Riot');

0 commit comments

Comments
 (0)