mirror of
https://github.com/YuJunZhiXue/dsh-purge.git
synced 2026-11-28 03:20:22 +08:00
revert(#85): 撤销 host 自杀 Electron — 会被 Job Object 连带杀 → helper 来不及 spawn
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 加载到内存,之后永远不再弹。
This commit is contained in:
1 parent
9d384d0723
commit
554277fcfb
1 file changed
+5
-48
+5
-48
@@ -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",
|
||||
|
||||
Reference in new issue
Block a user