diff --git a/src/main.js b/src/main.js index 1502eb9d..3e4618e3 100644 --- a/src/main.js +++ b/src/main.js @@ -30,7 +30,9 @@ process.on('uncaughtException', criticalErrorHandler.processUncaughtExceptionHan global.willAppQuit = false; app.setAppUserModelId('com.squirrel.mattermost.Mattermost'); // Use explicit AppUserModelID -if (squirrelStartup()) { +if (squirrelStartup(() => { + app.quit(); +})) { global.willAppQuit = true; } import settings from './common/settings'; @@ -279,7 +281,7 @@ app.on('activate', () => { app.on('before-quit', () => { // Make sure tray icon gets removed if the user exits via CTRL-Q - if (process.platform === 'win32') { + if (trayIcon && process.platform === 'win32') { trayIcon.destroy(); } global.willAppQuit = true; diff --git a/src/main/squirrelStartup.js b/src/main/squirrelStartup.js index d6736584..7ee7fe76 100644 --- a/src/main/squirrelStartup.js +++ b/src/main/squirrelStartup.js @@ -5,7 +5,8 @@ function shouldQuitApp(cmd) { if (process.platform !== 'win32') { return false; } - return ['--squirrel-install', '--squirrel-updated', '--squirrel-uninstall', '--squirrel-obsolete'].includes(cmd); + const squirrelCommands = ['--squirrel-install', '--squirrel-updated', '--squirrel-uninstall', '--squirrel-obsolete']; + return squirrelCommands.includes(cmd); } async function setupAutoLaunch(cmd) { @@ -15,22 +16,23 @@ async function setupAutoLaunch(cmd) { }); if (cmd === '--squirrel-uninstall') { // If we're uninstalling, make sure we also delete our auto launch registry key - return appLauncher.disable(); + await appLauncher.disable(); } else if (cmd === '--squirrel-install' || cmd === '--squirrel-updated') { // If we're updating and already have an registry entry for auto launch, make sure to update the path const enabled = await appLauncher.isEnabled(); if (enabled) { - return appLauncher.enable(); + await appLauncher.enable(); } } - return async () => true; } -export default function squirrelStartup() { +export default function squirrelStartup(callback) { if (process.platform === 'win32') { const cmd = process.argv[1]; setupAutoLaunch(cmd).then(() => { - require('electron-squirrel-startup'); // eslint-disable-line global-require + if (require('electron-squirrel-startup') && callback) { // eslint-disable-line global-require + callback(); + } }); return shouldQuitApp(cmd); }