diff --git a/.eslintrc.json b/.eslintrc.json index b5743439..450c0767 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,7 +1,9 @@ { "extends": "./.eslintrc-platform.json", + "parserOptions": { + "ecmaVersion": 2017 + }, "rules": { - "global-require": 1, "indent": [2, 2, {"SwitchCase": 0}], "no-console": 0, "no-eval": 1, diff --git a/CHANGELOG.md b/CHANGELOG.md index 4832fda9..fa8aa666 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,8 @@ Release date: TBD #### Windows - Fixed desktop notifications not working when the window has been minimized from inactive state. [#522](https://github.com/mattermost/desktop/issues/522) + - Fixed the uninstaller not removing files correctly. + [#551](https://github.com/mattermost/desktop/issues/551) #### Mac - Fixed an issue where the text box didn't keep focus after uploading a file. diff --git a/src/main.js b/src/main.js index d1f81e9c..319e0059 100644 --- a/src/main.js +++ b/src/main.js @@ -12,8 +12,7 @@ const { } = require('electron'); const isDev = require('electron-is-dev'); const installExtension = require('electron-devtools-installer'); - -const AutoLaunch = require('auto-launch'); +const squirrelStartup = require('./main/squirrelStartup'); process.on('uncaughtException', (error) => { console.error(error); @@ -21,34 +20,8 @@ process.on('uncaughtException', (error) => { global.willAppQuit = false; -if (process.platform === 'win32') { - var cmd = process.argv[1]; - var appLauncher = new AutoLaunch({ - name: 'Mattermost', - isHidden: true - }); - if (cmd === '--squirrel-uninstall') { - // If we're uninstalling, make sure we also delete our auto launch registry key - appLauncher.isEnabled().then((enabled) => { - if (enabled) { - 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 - appLauncher.isEnabled().then((enabled) => { - if (enabled) { - return appLauncher.disable().then(() => { - return appLauncher.enable(); - }); - } - return true; - }); - } -} - app.setAppUserModelId('com.squirrel.mattermost.Mattermost'); // Use explicit AppUserModelID -if (require('electron-squirrel-startup')) { +if (squirrelStartup()) { global.willAppQuit = true; } diff --git a/src/main/squirrelStartup.js b/src/main/squirrelStartup.js new file mode 100644 index 00000000..43fb3a30 --- /dev/null +++ b/src/main/squirrelStartup.js @@ -0,0 +1,39 @@ +const AutoLaunch = require('auto-launch'); + +function shouldQuitApp(cmd) { + if (process.platform !== 'win32') { + return false; + } + return ['--squirrel-install', '--squirrel-updated', '--squirrel-uninstall', '--squirrel-obsolete'].includes(cmd); +} + +async function setupAutoLaunch(cmd) { + const appLauncher = new AutoLaunch({ + name: 'Mattermost', + isHidden: true + }); + if (cmd === '--squirrel-uninstall') { + // If we're uninstalling, make sure we also delete our auto launch registry key + return 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(); + } + } + return async () => true; +} + +function squirrelStartup() { + if (process.platform === 'win32') { + const cmd = process.argv[1]; + setupAutoLaunch(cmd).then(() => { + require('electron-squirrel-startup'); // eslint-disable-line global-require + }); + return shouldQuitApp(cmd); + } + return false; +} + +module.exports = squirrelStartup;