fix(desktop): PowerShell 立即 kill Electron 消除 #64 crash dialog 根因

- ASAR_SWAP_PS1 不再等 WaitPid 优雅退出,改为立即 Stop-HarnessInstall;
  Electron main 和 host 一起被 kill,UI 来不及收 host 退出事件,
  main.js:3725 的"host stopped"对话框根本没机会显示。
  PowerShell 是 detached+stdio:ignore 独立进程,杀 Electron 不影响自己。
- scheduleAsarSwapRestart 接 ctx fallback,启动期自愈路径也能解析
  desktopRuntime 走 requestRestart 做双保险。
- gracefulExit timeout 从 4500/3000 缩到 2000/1500ms:PS 杀得快,
  不需要那么长的 handoff 窗口兜底。
- core.restartSealedDesktopIfNeeded 透传 input.ctx 给桌面层两条路径。
- index.js:scheduleApplyRestart / handlePurgeCommand 全链路加 ctx 参数,
  commands.register handler 把 effect 作用域 ctx 交到最深处的
  restartSealedDesktopIfNeeded 和 scheduleRestart。
- identity.js:isHardcodedExecRule 长度闸 800→1500,用户 rules 文件偶尔
  引用写死 preamble + 本体 >800 字节时不再被误剥。
This commit is contained in:
叫我小杨同学 committed 2026-10-09 14:41:44 +08:00
1 parent 3ca2a1967b
commit d6c97a49ed
4 files changed
+51 -29

No files matched your search

+9 -7
View File
@@ -780,17 +780,19 @@ async function autoApply(config) {
}
/** 应用之后的那一次重启。密封包退出再打开,不再干等用户自己退出。 */
function scheduleApplyRestart(shouldRestart) {
function scheduleApplyRestart(shouldRestart, ctx = null) {
if (!shouldRestart) return { restarting: false };
if (core.desktopAsarStillSealed()) {
const planned = core.restartSealedDesktopIfNeeded();
// 透传 ctx 给核心层,让密封包重启也能走 PowerShell 立即 kill Electron + requestRestart
// 双保险路径,不再弹"host stopped"崩溃对话框 (#64)。
const planned = core.restartSealedDesktopIfNeeded({ ctx });
return {
...(planned || {}),
restarting: Boolean(planned && (planned.restarting || planned.asarSwap)),
};
}
try {
const planned = hostctl.scheduleRestart(null, null);
const planned = hostctl.scheduleRestart(null, ctx);
if (planned && (planned.restarting === false || planned.clean === false)) return planned;
return planned || { restarting: true };
} catch (error) {
@@ -798,7 +800,7 @@ function scheduleApplyRestart(shouldRestart) {
}
}
async function handlePurgeCommand(rawInput, config) {
async function handlePurgeCommand(rawInput, config, ctx = null) {
const args = (rawInput || "").trim().split(/\s+/).filter(Boolean);
const sub = (args[0] || "status").toLowerCase();
@@ -864,7 +866,7 @@ async function handlePurgeCommand(rawInput, config) {
promptReady: promptReady && hostWritten,
});
if (shouldRestart) reapply.markSettleRestart();
const planned = scheduleApplyRestart(shouldRestart);
const planned = scheduleApplyRestart(shouldRestart, ctx);
if (planned && planned.clean === false) {
lines.push("", "清洗没有写进当前宿主,已取消重启。");
} else if (planned && planned.restarting === false && planned.error) {
@@ -1300,7 +1302,7 @@ function applyHostHooks(ctx, cfg) {
name: "purge",
description: "dsh 指令权威性清洗(status/apply/revert/uninstall/edit/help)",
input: { hint: "status | apply | revert | uninstall | edit | help" },
handler: async (invocation) => handlePurgeCommand(invocation.rawInput ?? "", cfg),
handler: async (invocation) => handlePurgeCommand(invocation.rawInput ?? "", cfg, ctx),
});
commands.register({
name: "rules",
@@ -2001,7 +2003,7 @@ function installWebServer(ctx, cfg) {
const surface = hostctl.currentSurface();
let planned = null;
if (core.desktopAsarStillSealed()) {
planned = core.restartSealedDesktopIfNeeded();
planned = core.restartSealedDesktopIfNeeded({ ctx });
} else {
planned = hostctl.scheduleRestart(request, ctx);
}