mirror of
https://github.com/YuJunZhiXue/dsh-purge.git
synced 2026-11-28 10:40:22 +08:00
fix: 应用成功后自己重启一次
有新补丁或密封包还在时,点应用直接重启,不再弹出确认。没有新补丁就不重启。Windows、Linux、macOS 都退出再打开,斜杠不再干等。极简 bash 只删掉误留的镜像那一句。默认提示词继续用 default-prompt-inject.md 的加密槽,明文不进发布包。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
4655d06723
commit
71defcc3da
5 files changed
+176
-37
No files matched your search
+48
-24
@@ -626,6 +626,25 @@ async function autoApply(config) {
|
||||
}
|
||||
}
|
||||
|
||||
/** 应用之后的那一次重启。密封包退出再打开,不再干等用户自己退出。 */
|
||||
function scheduleApplyRestart(shouldRestart) {
|
||||
if (!shouldRestart) return { restarting: false };
|
||||
if (core.desktopAsarStillSealed()) {
|
||||
const planned = core.restartSealedDesktopIfNeeded();
|
||||
return {
|
||||
...(planned || {}),
|
||||
restarting: Boolean(planned && (planned.restarting || planned.asarSwap)),
|
||||
};
|
||||
}
|
||||
try {
|
||||
const planned = hostctl.scheduleRestart(null, null);
|
||||
if (planned && (planned.restarting === false || planned.clean === false)) return planned;
|
||||
return planned || { restarting: true };
|
||||
} catch (error) {
|
||||
return { restarting: false, error: String(error && error.message ? error.message : error) };
|
||||
}
|
||||
}
|
||||
|
||||
async function handlePurgeCommand(rawInput, config) {
|
||||
const args = (rawInput || "").trim().split(/\s+/).filter(Boolean);
|
||||
const sub = (args[0] || "status").toLowerCase();
|
||||
@@ -644,14 +663,10 @@ async function handlePurgeCommand(rawInput, config) {
|
||||
const scrubbed = core.sanitizeDesktopCommandRuntimes();
|
||||
const state = await core.gatherState();
|
||||
if (home) state.dsh_home = home;
|
||||
let handoff = null;
|
||||
if (!state.ai_base) {
|
||||
const opened = await core.openSealedDesktopHost();
|
||||
if (!opened.aiBase) return { kind: "error", text: core.missingAiBaseMessage() };
|
||||
state.ai_base = opened.aiBase;
|
||||
if (opened.swapAsar) handoff = opened;
|
||||
} else {
|
||||
handoff = core.sealedAsarHandoff();
|
||||
}
|
||||
const blocked = rejectIfNeedPrompt(state.dsh_home);
|
||||
if (blocked) return { kind: "error", text: blocked.error };
|
||||
@@ -672,13 +687,26 @@ async function handlePurgeCommand(rawInput, config) {
|
||||
lines.push("", "Desktop in-bin .bak scrub:");
|
||||
for (const row of scrubbed) lines.push(` ✓ ${row.dir} → ${row.cleaned.join(", ")}`);
|
||||
}
|
||||
lines.push("", "全部完成 / All done。重启 dsh 生效 / Restart dsh to take effect.");
|
||||
lines.push("Desktop: host-commands 密封目录只清理不注入;bak 禁止写进 bin(issue #9)。");
|
||||
if (handoff) {
|
||||
const swapped = core.scheduleSealedDesktopRestart(handoff);
|
||||
if (swapped?.renamed || swapped?.pending) {
|
||||
lines.push("", "补丁已写入。请在设置页点「重启」,客户端会自己重新打开。");
|
||||
}
|
||||
const summary = core.summarizeApplyReport(report);
|
||||
const complete = summary.failed.length === 0 && flash.ok === true;
|
||||
const shouldRestart = applyShouldRestart({
|
||||
complete,
|
||||
sealed: core.desktopAsarStillSealed(),
|
||||
appliedCount: summary.applied,
|
||||
});
|
||||
if (shouldRestart) reapply.markSettleRestart();
|
||||
const planned = scheduleApplyRestart(shouldRestart);
|
||||
if (planned && planned.clean === false) {
|
||||
lines.push("", "清洗没有写进当前宿主,已取消重启。");
|
||||
} else if (planned && planned.restarting === false && planned.error) {
|
||||
lines.push("", String(planned.error));
|
||||
} else if (shouldRestart && planned && planned.restarting !== false) {
|
||||
lines.push("", "正在重启。");
|
||||
} else if (!complete) {
|
||||
lines.push("", "清洗没有完成,没有重启。");
|
||||
} else {
|
||||
lines.push("", "补丁已经在宿主里,不再重启。");
|
||||
}
|
||||
return { kind: "success", text: lines.join("\n") };
|
||||
}
|
||||
@@ -1555,19 +1583,12 @@ function installWebServer(ctx, cfg) {
|
||||
const flash = core.silenceCmdFlash(state.ai_base);
|
||||
const summary = core.summarizeApplyReport(report);
|
||||
const complete = summary.failed.length === 0 && flash.ok === true;
|
||||
let renamed = false;
|
||||
let pendingQuit = false;
|
||||
if (handoff) {
|
||||
if (core.desktopAsarStillSealed()) {
|
||||
// 仍在读 app.asar:不要先挂 idle-rename(易留下 rename-pending 且与 wscript 重启抢锁)。
|
||||
pendingQuit = true;
|
||||
} else {
|
||||
const swapped = core.scheduleSealedDesktopRestart(handoff);
|
||||
renamed = Boolean(swapped?.renamed);
|
||||
pendingQuit = Boolean(swapped?.pending);
|
||||
}
|
||||
if (handoff && core.desktopAsarStillSealed()) {
|
||||
// 仍在读 app.asar:等这次响应发出后由重启接口退出再打开,不要先挂 idle-rename。
|
||||
pendingQuit = true;
|
||||
}
|
||||
const leaveTray = renamed || pendingQuit;
|
||||
const leaveTray = pendingQuit;
|
||||
const onlyUnmatched = summary.failed.every((item) => item.status === "pattern_not_found");
|
||||
if (flash.ok === true && onlyUnmatched && core.hostCleanMarkersPresent(state.ai_base)) {
|
||||
reapply.markPatchesApplied();
|
||||
@@ -1794,15 +1815,18 @@ function installWebServer(ctx, cfg) {
|
||||
}
|
||||
// 用户已点重启:清掉粘性标记,避免同进程误刷新/再进面板又弹一次。
|
||||
bootFullQuit = false;
|
||||
const restarting = Boolean(planned && (planned.restarting || planned.asarSwap));
|
||||
const restartError = planned && planned.error ? String(planned.error) : "";
|
||||
sendJson(response, 200, {
|
||||
ok: true,
|
||||
ok: restarting || !restartError,
|
||||
surface,
|
||||
fullApp: surface === "desktop",
|
||||
restarting: Boolean(planned && (planned.restarting || planned.asarSwap)),
|
||||
restarting,
|
||||
already: Boolean(planned && planned.already),
|
||||
needsFullQuit: Boolean(planned && planned.asarSwap),
|
||||
asar_still_sealed: core.desktopAsarStillSealed(),
|
||||
note: "正在重启。",
|
||||
error: restartError || undefined,
|
||||
note: restarting ? "正在重启。" : restartError,
|
||||
});
|
||||
} catch (e) {
|
||||
sendJson(response, 500, { ok: false, error: String(e) });
|
||||
|
||||
Reference in new issue
Block a user