insomnia/packages/insomnia-app/app/main/squirrel-startup.ts
Dimitri Mitropoulos 5f4c19da35
[TypeScript] Phase 1 & 2 (#3370)
Co-authored-by: Opender Singh <opender.singh@konghq.com>
2021-05-12 18:35:00 +12:00

38 lines
884 B
TypeScript

import path from 'path';
import { spawn } from 'child_process';
import { app } from 'electron';
function run(args, done) {
const updateExe = path.resolve(path.dirname(process.execPath), '..', 'Update.exe');
spawn(updateExe, args, {
detached: true,
}).on('close', done);
}
export function checkIfRestartNeeded() {
if (process.platform !== 'win32') {
return false;
}
const cmd = process.argv[1];
console.log('processing squirrel command `%s`', cmd);
const target = path.basename(process.execPath);
switch (cmd) {
case '--squirrel-install':
run(['--createShortcut=' + target + ''], app.quit);
return true;
case '--squirrel-uninstall':
run(['--removeShortcut=' + target + ''], app.quit);
return true;
case '--squirrel-updated':
case '--squirrel-obsolete':
app.quit();
return true;
}
return false;
}