fix(update): launch installers after the current app exits
This commit is contained in:
+1
-1
@@ -403,7 +403,7 @@ function registerIpcHandlers(): void {
|
||||
if (result.started) {
|
||||
updateQuitTimer = setTimeout(() => {
|
||||
app.quit();
|
||||
}, 5000);
|
||||
}, 250);
|
||||
}
|
||||
return result;
|
||||
});
|
||||
|
||||
+40
-10
@@ -893,9 +893,38 @@ async function resolveDigestFromYml(repo: string, tag: string, setupName: string
|
||||
return "";
|
||||
}
|
||||
|
||||
export function buildInstallerLaunchArgs(): string[] {
|
||||
return ["/S", "--updated", "--force-run"];
|
||||
}
|
||||
export function buildInstallerLaunchArgs(): string[] {
|
||||
return ["/S", "--updated", "--force-run"];
|
||||
}
|
||||
|
||||
function quotePowerShellLiteral(value: string): string {
|
||||
return `'${value.replaceAll("'", "''")}'`;
|
||||
}
|
||||
|
||||
export function buildDeferredInstallerLaunch(
|
||||
targetPath: string,
|
||||
currentProcessId: number = process.pid,
|
||||
systemRoot: string = process.env.SystemRoot || "C:\\Windows"
|
||||
): { command: string; args: string[] } {
|
||||
const installerArgs = buildInstallerLaunchArgs().map(quotePowerShellLiteral).join(",");
|
||||
const script = [
|
||||
"$deadline=(Get-Date).AddMinutes(2)",
|
||||
`while ((Get-Process -Id ${Math.max(1, Math.floor(currentProcessId))} -ErrorAction SilentlyContinue) -and ((Get-Date) -lt $deadline)) { Start-Sleep -Milliseconds 200 }`,
|
||||
`Start-Process -FilePath ${quotePowerShellLiteral(targetPath)} -ArgumentList @(${installerArgs}) -WindowStyle Hidden`
|
||||
].join("; ");
|
||||
return {
|
||||
command: path.win32.join(systemRoot, "System32", "WindowsPowerShell", "v1.0", "powershell.exe"),
|
||||
args: [
|
||||
"-NoLogo",
|
||||
"-NoProfile",
|
||||
"-NonInteractive",
|
||||
"-WindowStyle",
|
||||
"Hidden",
|
||||
"-EncodedCommand",
|
||||
Buffer.from(script, "utf16le").toString("base64")
|
||||
]
|
||||
};
|
||||
}
|
||||
|
||||
export async function checkGitHubUpdate(repo: string): Promise<UpdateCheckResult> {
|
||||
const safeRepo = normalizeUpdateRepo(repo);
|
||||
@@ -1097,13 +1126,14 @@ export async function installLatestUpdate(
|
||||
message: "Starte stille Update-Installation",
|
||||
});
|
||||
|
||||
const child = childProcess.spawn(targetPath, buildInstallerLaunchArgs(), {
|
||||
detached: true,
|
||||
stdio: "ignore",
|
||||
windowsHide: true,
|
||||
});
|
||||
child.once("error", (spawnError) => {
|
||||
logger.error(`Update-Installer Start fehlgeschlagen: ${compactErrorText(spawnError)}`);
|
||||
const deferredLaunch = buildDeferredInstallerLaunch(targetPath);
|
||||
const child = childProcess.spawn(deferredLaunch.command, deferredLaunch.args, {
|
||||
detached: true,
|
||||
stdio: "ignore",
|
||||
windowsHide: true,
|
||||
});
|
||||
child.once("error", (spawnError) => {
|
||||
logger.error(`Update-Launcher Start fehlgeschlagen: ${compactErrorText(spawnError)}`);
|
||||
});
|
||||
child.unref();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user