insomnia/packages/insomnia-app/app/main/squirrel-startup.ts

39 lines
901 B
TypeScript
Raw Normal View History

import { spawn } from 'child_process';
import { app } from 'electron';
2021-07-22 23:04:56 +00:00
import path from 'path';
function run(args, done) {
const updateExe = path.resolve(path.dirname(process.execPath), '..', 'Update.exe');
spawn(updateExe, args, {
detached: true,
}).on('close', done);
}
2019-05-10 16:30:20 +00:00
export function checkIfRestartNeeded() {
2019-05-15 22:34:12 +00:00
if (process.platform !== 'win32') {
2019-05-10 19:20:07 +00:00
return false;
}
2019-05-10 19:20:07 +00:00
const cmd = process.argv[1];
console.log('processing squirrel command `%s`', cmd);
const target = path.basename(process.execPath);
2019-05-10 19:20:07 +00:00
switch (cmd) {
case '--squirrel-install':
run(['--createShortcut=' + target + ''], app.quit);
return true;
2019-05-10 19:20:07 +00:00
case '--squirrel-uninstall':
run(['--removeShortcut=' + target + ''], app.quit);
return true;
2019-05-10 19:20:07 +00:00
case '--squirrel-updated':
case '--squirrel-obsolete':
app.quit();
return true;
2019-05-10 19:20:07 +00:00
default:
return false;
}
}