mirror of
https://github.com/element-hq/element-web
synced 2024-11-28 12:28:50 +03:00
tidy code
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
parent
8a4a6b2023
commit
20dd2c0b58
1 changed files with 29 additions and 29 deletions
|
@ -23,7 +23,7 @@ const checkSquirrelHooks = require('./squirrelhooks');
|
||||||
if (checkSquirrelHooks()) return;
|
if (checkSquirrelHooks()) return;
|
||||||
|
|
||||||
const argv = require('minimist')(process.argv);
|
const argv = require('minimist')(process.argv);
|
||||||
const electron = require('electron');
|
const {app, ipcMain, powerSaveBlocker, BrowserWindow, Menu} = require('electron');
|
||||||
const AutoLaunch = require('auto-launch');
|
const AutoLaunch = require('auto-launch');
|
||||||
|
|
||||||
const tray = require('./tray');
|
const tray = require('./tray');
|
||||||
|
@ -33,8 +33,8 @@ const updater = require('./updater');
|
||||||
|
|
||||||
const windowStateKeeper = require('electron-window-state');
|
const windowStateKeeper = require('electron-window-state');
|
||||||
|
|
||||||
if (argv.profile) {
|
if (argv['profile']) {
|
||||||
electron.app.setPath('userData', `${electron.app.getPath('userData')}-${argv.profile}`);
|
app.setPath('userData', `${app.getPath('userData')}-${argv['profile']}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
let vectorConfig = {};
|
let vectorConfig = {};
|
||||||
|
@ -62,14 +62,14 @@ process.on('uncaughtException', function(error) {
|
||||||
});
|
});
|
||||||
|
|
||||||
let focusHandlerAttached = false;
|
let focusHandlerAttached = false;
|
||||||
electron.ipcMain.on('setBadgeCount', function(ev, count) {
|
ipcMain.on('setBadgeCount', function(ev, count) {
|
||||||
electron.app.setBadgeCount(count);
|
app.setBadgeCount(count);
|
||||||
if (count === 0) {
|
if (count === 0 && mainWindow) {
|
||||||
mainWindow.flashFrame(false);
|
mainWindow.flashFrame(false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
electron.ipcMain.on('loudNotification', function() {
|
ipcMain.on('loudNotification', function() {
|
||||||
if (process.platform === 'win32' && mainWindow && !mainWindow.isFocused() && !focusHandlerAttached) {
|
if (process.platform === 'win32' && mainWindow && !mainWindow.isFocused() && !focusHandlerAttached) {
|
||||||
mainWindow.flashFrame(true);
|
mainWindow.flashFrame(true);
|
||||||
mainWindow.once('focus', () => {
|
mainWindow.once('focus', () => {
|
||||||
|
@ -81,16 +81,16 @@ electron.ipcMain.on('loudNotification', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
let powerSaveBlockerId;
|
let powerSaveBlockerId;
|
||||||
electron.ipcMain.on('app_onAction', function(ev, payload) {
|
ipcMain.on('app_onAction', function(ev, payload) {
|
||||||
switch (payload.action) {
|
switch (payload.action) {
|
||||||
case 'call_state':
|
case 'call_state':
|
||||||
if (powerSaveBlockerId && electron.powerSaveBlocker.isStarted(powerSaveBlockerId)) {
|
if (powerSaveBlockerId && powerSaveBlocker.isStarted(powerSaveBlockerId)) {
|
||||||
if (payload.state === 'ended') {
|
if (payload.state === 'ended') {
|
||||||
electron.powerSaveBlocker.stop(powerSaveBlockerId);
|
powerSaveBlocker.stop(powerSaveBlockerId);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (payload.state === 'connected') {
|
if (payload.state === 'connected') {
|
||||||
powerSaveBlockerId = electron.powerSaveBlocker.start('prevent-display-sleep');
|
powerSaveBlockerId = powerSaveBlocker.start('prevent-display-sleep');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -98,9 +98,9 @@ electron.ipcMain.on('app_onAction', function(ev, payload) {
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
electron.app.commandLine.appendSwitch('--enable-usermedia-screen-capturing');
|
app.commandLine.appendSwitch('--enable-usermedia-screen-capturing');
|
||||||
|
|
||||||
const shouldQuit = electron.app.makeSingleInstance((commandLine, workingDirectory) => {
|
const shouldQuit = app.makeSingleInstance((commandLine, workingDirectory) => {
|
||||||
// If other instance launched with --hidden then skip showing window
|
// If other instance launched with --hidden then skip showing window
|
||||||
if (commandLine.includes('--hidden')) return;
|
if (commandLine.includes('--hidden')) return;
|
||||||
|
|
||||||
|
@ -114,7 +114,7 @@ const shouldQuit = electron.app.makeSingleInstance((commandLine, workingDirector
|
||||||
|
|
||||||
if (shouldQuit) {
|
if (shouldQuit) {
|
||||||
console.log('Other instance detected: exiting');
|
console.log('Other instance detected: exiting');
|
||||||
electron.app.exit();
|
app.exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -139,7 +139,7 @@ const settings = {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
electron.ipcMain.on('settings_get', async function(ev) {
|
ipcMain.on('settings_get', async function(ev) {
|
||||||
const data = {};
|
const data = {};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -153,15 +153,15 @@ electron.ipcMain.on('settings_get', async function(ev) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
electron.ipcMain.on('settings_set', function(ev, key, value) {
|
ipcMain.on('settings_set', function(ev, key, value) {
|
||||||
console.log(key, value);
|
console.log(key, value);
|
||||||
if (settings[key] && settings[key].set) {
|
if (settings[key] && settings[key].set) {
|
||||||
settings[key].set(value);
|
settings[key].set(value);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
electron.app.on('ready', () => {
|
app.on('ready', () => {
|
||||||
if (argv.devtools) {
|
if (argv['devtools']) {
|
||||||
try {
|
try {
|
||||||
const { default: installExt, REACT_DEVELOPER_TOOLS, REACT_PERF } = require('electron-devtools-installer');
|
const { default: installExt, REACT_DEVELOPER_TOOLS, REACT_PERF } = require('electron-devtools-installer');
|
||||||
installExt(REACT_DEVELOPER_TOOLS)
|
installExt(REACT_DEVELOPER_TOOLS)
|
||||||
|
@ -176,9 +176,9 @@ electron.app.on('ready', () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (vectorConfig.update_base_url) {
|
if (vectorConfig['update_base_url']) {
|
||||||
console.log(`Starting auto update with base URL: ${vectorConfig.update_base_url}`);
|
console.log(`Starting auto update with base URL: ${vectorConfig['update_base_url']}`);
|
||||||
updater.start(vectorConfig.update_base_url);
|
updater.start(vectorConfig['update_base_url']);
|
||||||
} else {
|
} else {
|
||||||
console.log('No update_base_url is defined: auto update is disabled');
|
console.log('No update_base_url is defined: auto update is disabled');
|
||||||
}
|
}
|
||||||
|
@ -191,7 +191,7 @@ electron.app.on('ready', () => {
|
||||||
defaultHeight: 768,
|
defaultHeight: 768,
|
||||||
});
|
});
|
||||||
|
|
||||||
mainWindow = global.mainWindow = new electron.BrowserWindow({
|
mainWindow = global.mainWindow = new BrowserWindow({
|
||||||
icon: iconPath,
|
icon: iconPath,
|
||||||
show: false,
|
show: false,
|
||||||
autoHideMenuBar: true,
|
autoHideMenuBar: true,
|
||||||
|
@ -202,7 +202,7 @@ electron.app.on('ready', () => {
|
||||||
height: mainWindowState.height,
|
height: mainWindowState.height,
|
||||||
});
|
});
|
||||||
mainWindow.loadURL(`file://${__dirname}/../../webapp/index.html`);
|
mainWindow.loadURL(`file://${__dirname}/../../webapp/index.html`);
|
||||||
electron.Menu.setApplicationMenu(vectorMenu);
|
Menu.setApplicationMenu(vectorMenu);
|
||||||
|
|
||||||
// explicitly hide because setApplicationMenu on Linux otherwise shows...
|
// explicitly hide because setApplicationMenu on Linux otherwise shows...
|
||||||
// https://github.com/electron/electron/issues/9621
|
// https://github.com/electron/electron/issues/9621
|
||||||
|
@ -217,7 +217,7 @@ electron.app.on('ready', () => {
|
||||||
mainWindow.once('ready-to-show', () => {
|
mainWindow.once('ready-to-show', () => {
|
||||||
mainWindowState.manage(mainWindow);
|
mainWindowState.manage(mainWindow);
|
||||||
|
|
||||||
if (!argv.hidden) {
|
if (!argv['hidden']) {
|
||||||
console.log("Showing window");
|
console.log("Showing window");
|
||||||
mainWindow.show();
|
mainWindow.show();
|
||||||
} else {
|
} else {
|
||||||
|
@ -254,15 +254,15 @@ electron.app.on('ready', () => {
|
||||||
webContentsHandler(mainWindow.webContents);
|
webContentsHandler(mainWindow.webContents);
|
||||||
});
|
});
|
||||||
|
|
||||||
electron.app.on('window-all-closed', () => {
|
app.on('window-all-closed', () => {
|
||||||
electron.app.quit();
|
app.quit();
|
||||||
});
|
});
|
||||||
|
|
||||||
electron.app.on('activate', () => {
|
app.on('activate', () => {
|
||||||
mainWindow.show();
|
mainWindow.show();
|
||||||
});
|
});
|
||||||
|
|
||||||
electron.app.on('before-quit', () => {
|
app.on('before-quit', () => {
|
||||||
global.appQuitting = true;
|
global.appQuitting = true;
|
||||||
if (mainWindow) {
|
if (mainWindow) {
|
||||||
mainWindow.webContents.send('before-quit');
|
mainWindow.webContents.send('before-quit');
|
||||||
|
@ -273,4 +273,4 @@ electron.app.on('before-quit', () => {
|
||||||
// installer uses for the shortcut icon.
|
// installer uses for the shortcut icon.
|
||||||
// This makes notifications work on windows 8.1 (and is
|
// This makes notifications work on windows 8.1 (and is
|
||||||
// a noop on other platforms).
|
// a noop on other platforms).
|
||||||
electron.app.setAppUserModelId('com.squirrel.riot-web.Riot');
|
app.setAppUserModelId('com.squirrel.riot-web.Riot');
|
||||||
|
|
Loading…
Reference in a new issue