Fix Windows uninstaller not removing files correctly

Multiple async tasks were not performed completely when running uninstaller.
So rearranged tasks with sequential order.
i.e. take care startup registry, finally call electron-squirrel-startup.
This commit is contained in:
Yuya Ochiai 2017-07-11 00:19:28 +09:00
parent 9f826cad93
commit ab5e5590a4
4 changed files with 46 additions and 30 deletions

View file

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

View file

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

View file

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

View file

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