Make sure the app correctly quits in the initial set up

This commit is contained in:
Yuya Ochiai 2018-04-14 01:01:02 +09:00
parent faf0cade89
commit 738829dbb5
2 changed files with 12 additions and 8 deletions

View file

@ -30,7 +30,9 @@ process.on('uncaughtException', criticalErrorHandler.processUncaughtExceptionHan
global.willAppQuit = false; global.willAppQuit = false;
app.setAppUserModelId('com.squirrel.mattermost.Mattermost'); // Use explicit AppUserModelID app.setAppUserModelId('com.squirrel.mattermost.Mattermost'); // Use explicit AppUserModelID
if (squirrelStartup()) { if (squirrelStartup(() => {
app.quit();
})) {
global.willAppQuit = true; global.willAppQuit = true;
} }
import settings from './common/settings'; import settings from './common/settings';
@ -279,7 +281,7 @@ app.on('activate', () => {
app.on('before-quit', () => { app.on('before-quit', () => {
// Make sure tray icon gets removed if the user exits via CTRL-Q // Make sure tray icon gets removed if the user exits via CTRL-Q
if (process.platform === 'win32') { if (trayIcon && process.platform === 'win32') {
trayIcon.destroy(); trayIcon.destroy();
} }
global.willAppQuit = true; global.willAppQuit = true;

View file

@ -5,7 +5,8 @@ function shouldQuitApp(cmd) {
if (process.platform !== 'win32') { if (process.platform !== 'win32') {
return false; 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) { async function setupAutoLaunch(cmd) {
@ -15,22 +16,23 @@ async function setupAutoLaunch(cmd) {
}); });
if (cmd === '--squirrel-uninstall') { if (cmd === '--squirrel-uninstall') {
// If we're uninstalling, make sure we also delete our auto launch registry key // 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') { } 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 // If we're updating and already have an registry entry for auto launch, make sure to update the path
const enabled = await appLauncher.isEnabled(); const enabled = await appLauncher.isEnabled();
if (enabled) { if (enabled) {
return appLauncher.enable(); await appLauncher.enable();
} }
} }
return async () => true;
} }
export default function squirrelStartup() { export default function squirrelStartup(callback) {
if (process.platform === 'win32') { if (process.platform === 'win32') {
const cmd = process.argv[1]; const cmd = process.argv[1];
setupAutoLaunch(cmd).then(() => { 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); return shouldQuitApp(cmd);
} }