2019-12-06 18:17:34 +00:00
|
|
|
/*
|
2024-09-06 17:56:18 +01:00
|
|
|
Copyright 2024 New Vector Ltd.
|
2019-12-06 18:17:34 +00:00
|
|
|
Copyright 2017 OpenMarket Ltd
|
|
|
|
|
2024-09-06 17:56:18 +01:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
|
|
|
|
Please see LICENSE files in the repository root for full details.
|
2019-12-06 18:17:34 +00:00
|
|
|
*/
|
|
|
|
|
2021-06-25 14:35:58 +01:00
|
|
|
import path from "path";
|
|
|
|
import { spawn } from "child_process";
|
|
|
|
import { app } from "electron";
|
2019-12-06 18:17:34 +00:00
|
|
|
|
2024-04-15 17:33:30 +01:00
|
|
|
export function getSquirrelExecutable(): string {
|
|
|
|
return path.resolve(path.dirname(process.execPath), "..", "Update.exe");
|
|
|
|
}
|
|
|
|
|
2021-06-25 14:35:58 +01:00
|
|
|
function runUpdateExe(args: string[]): Promise<void> {
|
2019-12-06 18:17:34 +00: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.
|
2024-04-15 17:33:30 +01:00
|
|
|
const updateExe = getSquirrelExecutable();
|
2019-12-06 18:17:34 +00:00
|
|
|
console.log(`Spawning '${updateExe}' with args '${args}'`);
|
2022-12-15 11:00:58 +00:00
|
|
|
return new Promise((resolve) => {
|
2020-07-14 19:05:28 +01:00
|
|
|
spawn(updateExe, args, {
|
2021-08-03 17:12:28 +01:00
|
|
|
detached: true,
|
2022-12-15 11:00:58 +00:00
|
|
|
}).on("close", resolve);
|
2020-07-14 19:05:28 +01:00
|
|
|
});
|
2019-12-06 18:17:34 +00:00
|
|
|
}
|
|
|
|
|
2021-07-27 11:47:44 +01:00
|
|
|
function checkSquirrelHooks(): boolean {
|
2022-12-15 11:00:58 +00:00
|
|
|
if (process.platform !== "win32") return false;
|
2019-12-06 18:17:34 +00:00
|
|
|
const cmd = process.argv[1];
|
|
|
|
const target = path.basename(process.execPath);
|
2023-04-26 15:05:58 +01:00
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case "--squirrel-install":
|
2024-06-12 17:17:24 +01:00
|
|
|
void runUpdateExe(["--createShortcut=" + target]).then(() => app.quit());
|
2023-04-26 15:05:58 +01:00
|
|
|
return true;
|
|
|
|
|
|
|
|
case "--squirrel-updated":
|
|
|
|
case "--squirrel-obsolete":
|
|
|
|
app.quit();
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case "--squirrel-uninstall":
|
2024-06-12 17:17:24 +01:00
|
|
|
void runUpdateExe(["--removeShortcut=" + target]).then(() => app.quit());
|
2023-04-26 15:05:58 +01:00
|
|
|
return true;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return false;
|
2019-12-06 18:17:34 +00:00
|
|
|
}
|
|
|
|
}
|
2021-07-27 11:47:44 +01:00
|
|
|
|
|
|
|
if (checkSquirrelHooks()) {
|
|
|
|
process.exit(1);
|
|
|
|
}
|