From 164e15106d8e243eb0111e04181aeca2b6020130 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=AB=E6=88=91=E5=B0=8F=E6=9D=A8=E5=90=8C=E5=AD=A6?= Date: Sat, 10 Oct 2026 00:15:42 +0800 Subject: [PATCH] =?UTF-8?q?revert(#85):=20=E6=92=A4=E9=94=80=20host=20?= =?UTF-8?q?=E8=87=AA=E6=9D=80=20Electron=20=E2=80=94=20=E4=BC=9A=E8=A2=AB?= =?UTF-8?q?=20Job=20Object=20=E8=BF=9E=E5=B8=A6=E6=9D=80=20=E2=86=92=20hel?= =?UTF-8?q?per=20=E6=9D=A5=E4=B8=8D=E5=8F=8A=20spawn?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit YG 实测现象:点'应用重启'没反应,DSH 全死不 relaunch。 根因:host 作为 Electron 子进程,在 Chromium Job Object 里。host sync 调 PowerShell 杀 Electron → Electron 死 → Job 连带杀 host → execFileSync 没返 → spawnHelper 没执行 → helper 没 spawn → 没 relaunch → 用户点了没反应。 保留 restart-desktop.js 的时序优化 (先 kill 再 cleanup,双保险)。 patch #83+#84 已经处理第二次之后的 close dialog (新 main.js 加载后 silent)。 第一次 restart 的 crash dialog 是 Electron 内存滞后的必然代价,YG 必须 fresh open DSH 一次让新 main.js 加载到内存,之后永远不再弹。 --- lib/desktop.js | 53 +++++--------------------------------------------- 1 file changed, 5 insertions(+), 48 deletions(-) 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",