Merge pull request #762 from yuya-oc/fix-windows-installer-crash

Fix an issue where Windows installer crashed in some cases
This commit is contained in:
Yuya Ochiai 2018-04-17 20:09:45 +09:00 committed by GitHub
commit dd3e74c865
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 8 deletions

View file

@ -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;

View file

@ -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);
}