2017-01-19 08:02:08 -05:00
|
|
|
/*
|
|
|
|
Copyright 2017 OpenMarket Ltd
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2016-11-08 06:20:47 -05:00
|
|
|
const path = require('path');
|
|
|
|
const spawn = require('child_process').spawn;
|
2017-05-22 14:21:52 -04:00
|
|
|
const {app} = require('electron');
|
2016-11-08 06:20:47 -05:00
|
|
|
|
2017-05-22 14:21:52 -04:00
|
|
|
function runUpdateExe(args, done) {
|
2017-01-11 11:27:40 -05:00
|
|
|
// Invokes Squirrel's Update.exe which will do things for us like create shortcuts
|
|
|
|
// Note that there's an Update.exe in the app-x.x.x directory and one in the parent
|
|
|
|
// directory: we need to run the one in the parent directory, because it discovers
|
|
|
|
// information about the app by inspecting the directory it's run from.
|
|
|
|
const updateExe = path.resolve(path.dirname(process.execPath), '..', 'Update.exe');
|
2017-05-22 14:21:52 -04:00
|
|
|
console.log(`Spawning '${updateExe}' with args '${args}'`);
|
2016-11-08 06:20:47 -05:00
|
|
|
spawn(updateExe, args, {
|
2017-05-22 14:21:52 -04:00
|
|
|
detached: true,
|
2016-11-08 06:20:47 -05:00
|
|
|
}).on('close', done);
|
2017-05-22 14:21:52 -04:00
|
|
|
}
|
2016-11-08 06:20:47 -05:00
|
|
|
|
2017-05-22 14:21:52 -04:00
|
|
|
function checkSquirrelHooks() {
|
|
|
|
if (process.platform !== 'win32') return false;
|
2016-11-08 06:20:47 -05:00
|
|
|
|
|
|
|
const cmd = process.argv[1];
|
|
|
|
const target = path.basename(process.execPath);
|
|
|
|
if (cmd === '--squirrel-install' || cmd === '--squirrel-updated') {
|
2017-05-22 14:21:52 -04:00
|
|
|
runUpdateExe(['--createShortcut=' + target + ''], app.quit);
|
2016-11-08 06:20:47 -05:00
|
|
|
return true;
|
|
|
|
} else if (cmd === '--squirrel-uninstall') {
|
2017-05-22 14:21:52 -04:00
|
|
|
runUpdateExe(['--removeShortcut=' + target + ''], app.quit);
|
2016-11-08 06:20:47 -05:00
|
|
|
return true;
|
|
|
|
} else if (cmd === '--squirrel-obsolete') {
|
|
|
|
app.quit();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-05-22 14:21:52 -04:00
|
|
|
module.exports = checkSquirrelHooks;
|