diff --git a/lib/desktop.js b/lib/desktop.js index 669b62e..79a8b83 100644 --- a/lib/desktop.js +++ b/lib/desktop.js @@ -816,60 +816,17 @@ function helperEnv(payload) { return env; } -// #85: host 自己同步杀 Electron 全家桶 (按安装根路径,不误伤同名第三方)。 -// 必须在 spawnHelper 之前跑 — 让 Electron 在 host exit 之前死,close event 根本 -// 没 subscriber,旧内存里的 close 回调(可能还是 stopped 版)不会触发对话框。 -// unpacked 模式和 asar 模式都要走这个,保证"任何系统任何人电脑"都不出 crash dialog。 -function killInstallElectronSync(execPath) { - if (process.platform !== "win32") return false; - if (!execPath) return false; - const installRoot = path.dirname(execPath); - const exeEsc = execPath.replace(/'/g, "''"); - const rootEsc = installRoot.replace(/'/g, "''"); - const script = [ - "$ErrorActionPreference = 'SilentlyContinue'", - "$exe = '" + exeEsc + "'", - "$root = '" + rootEsc + "'", - "$exeLow = $exe.ToLower()", - "$rootLowPrefix = $root.ToLower().TrimEnd('\\') + '\\'", - "function Stop-HarnessInstall {", - " Get-CimInstance Win32_Process | Where-Object {", - " $ep = $_.ExecutablePath", - " if (-not $ep) { return $false }", - " $low = $ep.ToLower()", - " return ($low -eq $exeLow) -or $low.StartsWith($rootLowPrefix)", - " } | ForEach-Object { Stop-Process -Id $_.ProcessId -Force -ErrorAction SilentlyContinue }", - "}", - "Stop-HarnessInstall", - "Start-Sleep -Milliseconds 400", - "Stop-HarnessInstall", - ].join("; "); - try { - execFileSync("powershell.exe", [ - "-NoProfile", "-WindowStyle", "Hidden", "-ExecutionPolicy", "Bypass", - "-Command", script, - ], { timeout: 10000, stdio: "ignore", windowsHide: true }); - logInternal("killInstallElectronSync 完成 (install root=" + installRoot + ")"); - return true; - } catch (err) { - logInternal("killInstallElectronSync 失败: " + (err?.message || err)); - return false; - } -} +// #85 reverted: host 自己同步杀 Electron 会导致 host 作为 Electron 子进程被 Job +// Object 连带杀,spawnHelper 来不及调用 → relaunch 彻底失败 (YG 实测现象:点"重启" +// 没反应,DSH 全死没 relaunch)。改回让 helper 全权处理 kill+relaunch,crash dialog +// 问题靠 patch #83+#84 (新 main.js 加载后 close 回调 silent) 解决第二次之后, +// 第一次 restart 的 crash dialog 是 Electron 内存版本滞后的必然代价,无法避免。 function spawnHelper(helper, payload, opts = {}) { const plan = restartPlan(); const hinted = payload && payload.execPath ? payload.execPath : ""; const execPath = hinted || plan.execPath; if (!execPath) throw new Error(plan.error || "未找到 DSH Desktop.exe,无法重启桌面应用"); - // #85: killApp 场景下 host 自己先同步杀 Electron,再 spawn helper。 - // 原来 host spawn helper → 250ms 后 exit → Electron 收到 host close event - // → 跑旧内存 close 回调(可能是 stopped 版) → 弹 crash dialog。 - // 现在先同步 kill Electron (close event 没 subscriber) → spawn helper detached - // 做 relaunch → host exit 时 Electron 已死,不弹对话框。 - if (payload?.killApp && process.platform === "win32") { - killInstallElectronSync(execPath); - } const child = spawn(process.execPath, [helper], { detached: true, stdio: "ignore",