fix: 发布 1.1.54,官方桌面启动不再 INACTIVE_EFFECT(#58–#61)

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
叫我小杨同学andCursor committed 2026-10-03 14:19:25 +08:00
1 parent c67b012bd7
commit 4da6d2eaf4
7 files changed
+197 -24

No files matched your search

+73 -9
View File
@@ -19,6 +19,13 @@ import * as continueRetry from "./continue-retry.js";
import * as uninstaller from "./uninstall.js";
import { installRegionGate, readAllowText, writeAllowText } from "./net-scope.js";
import * as refusalRecover from "./refusal-recover.js";
import {
isInactiveContextError,
settleDelayMs,
settleMayReapply,
settleMayRestart,
watchContextLife,
} from "./settle-policy.js";
export const name = "dsh-purge";
@@ -391,7 +398,14 @@ function shimNeedsPatch(state) {
);
}
async function settleInstalledPatches(config, ctx) {
function currentSettleScope() {
let sealed = false;
try { sealed = core.desktopAsarStillSealed(); } catch { /* 非桌面或还没定位安装目录 */ }
return { surface: hostctl.currentSurface(), sealed };
}
async function settleInstalledPatches(config, ctx, life) {
if (life && !life.alive) return "skip:inactive";
try { core.rememberUnpackedArchive(); } catch { /* 没有官方安装目录时不必记归档 */ }
try {
reapply.ensureInstalledRevSeed();
@@ -404,17 +418,24 @@ async function settleInstalledPatches(config, ctx) {
log(config, "heal applied stamp failed:", String(e && e.message ? e.message : e));
}
const scope = currentSettleScope();
if (!reapply.patchesMatchInstall()) {
if (!settleMayReapply(scope)) {
log(config, "sealed desktop: skip startup reapply (wait for Apply)");
return "skip:sealed-wait-apply";
}
if (officialUpdate.upgradeMarkerExists(process.execPath)) {
const upgraded = await reapply.reapplyInstalled({ scheduleSwap: false, upgrade: true });
if (life && !life.alive) return "skip:inactive";
if (!upgraded.ok) {
log(config, "official upgrade reapply failed:", upgraded.error || "");
return "reapply-failed";
}
officialUpdate.clearUpgradeMarker(process.execPath);
officialUpdate.clearStaleExtractedApps(process.execPath);
if (reapply.shouldSkipSettleRestart()) {
log(config, "official upgrade reapplied; skip settle restart (cooldown)");
if (!settleMayRestart(currentSettleScope()) || reapply.shouldSkipSettleRestart()) {
if (upgraded.needsFullQuit) bootFullQuit = true;
log(config, "official upgrade reapplied; skip settle restart");
return "reapplied-no-restart";
}
reapply.markSettleRestart();
@@ -428,7 +449,9 @@ async function settleInstalledPatches(config, ctx) {
return "restarting";
}
const result = await reapply.reapplyInstalled();
// 启动自愈只写盘,不 swap asar / 不杀进程,避免官方 Host Fiber._reload 撞 INACTIVE_EFFECT。
const result = await reapply.reapplyInstalled({ scheduleSwap: false });
if (life && !life.alive) return "skip:inactive";
if (!result.ok) {
log(config, "reapply failed:", result.error || "");
return "reapply-failed";
@@ -440,6 +463,10 @@ async function settleInstalledPatches(config, ctx) {
log(config, "reapply wrote patches; official host needs a full quit");
return "full-quit";
}
if (!settleMayRestart(currentSettleScope())) {
log(config, "reapply wrote patches; desktop settle does not restart");
return "reapplied-no-restart";
}
if (reapply.shouldSkipSettleRestart()) {
log(config, "reapply wrote patches; skip settle restart (cooldown)");
return "reapplied-no-restart";
@@ -467,7 +494,7 @@ async function settleInstalledPatches(config, ctx) {
.then((r) => {
log(config, "auto-update:", JSON.stringify(r));
if (r && r.needsFullQuit) bootFullQuit = true;
if (r && r.restartAfter) {
if (r && r.restartAfter && settleMayRestart(currentSettleScope())) {
try { hostctl.scheduleRestart(null, ctx, { openBrowser: false }); } catch (e) {
console.warn("[dsh-purge] auto-update restart failed:", e);
}
@@ -867,6 +894,11 @@ async function handleSkillsCommand(rawInput) {
export function apply(ctx, config) {
const cfg = { ...DEFAULTS, ...(config || {}) };
if (!cfg.enabled) return;
const life = watchContextLife(ctx);
if (!life.alive) {
console.warn("[dsh-purge] skip apply: inactive context");
return;
}
log(cfg, "plugin enabled");
try {
@@ -883,14 +915,34 @@ export function apply(ctx, config) {
console.warn("[dsh-purge] desktop runtime scrub error:", String(e));
}
setImmediate(() => {
settleInstalledPatches(cfg, ctx)
const settleTimer = setTimeout(() => {
if (!life.alive) {
log(cfg, "settle skipped: inactive context");
return;
}
settleInstalledPatches(cfg, ctx, life)
.then((r) => log(cfg, "settle:", r))
.catch((e) => console.warn("[dsh-purge] settle error:", String(e)));
.catch((e) => {
if (isInactiveContextError(e)) {
log(cfg, "settle skipped: inactive context");
return;
}
console.warn("[dsh-purge] settle error:", String(e));
});
rules.ensureInitialState(core.findDshHome())
.then((r) => log(cfg, "rules init:", JSON.stringify(r)))
.catch((e) => console.warn("[dsh-purge] rules init error:", String(e)));
});
}, settleDelayMs(hostctl.currentSurface()));
try {
ctx.effect(() => () => clearTimeout(settleTimer));
} catch (e) {
if (isInactiveContextError(e)) {
clearTimeout(settleTimer);
console.warn("[dsh-purge] skip apply: inactive context");
return;
}
throw e;
}
try {
core.seedOverrideSync(core.findDshHome());
@@ -901,6 +953,18 @@ export function apply(ctx, config) {
core.installOverride(core.findDshHome(), false).catch((e) => {
console.warn("[dsh-purge] install override error:", String(e));
});
try {
applyHostHooks(ctx, cfg);
} catch (e) {
if (isInactiveContextError(e)) {
console.warn("[dsh-purge] skip apply: inactive context");
return;
}
throw e;
}
}
function applyHostHooks(ctx, cfg) {
installIdentityOverride(ctx, cfg);
installRegionGate(ctx);
try {
+43
View File
@@ -0,0 +1,43 @@
/** 官方桌面启动时 Fiber._reload 还在挂 desktop-office,settle 不得解包/杀进程。 */
export const DESKTOP_SETTLE_DELAY_MS = 4000;
export function isInactiveContextError(error) {
if (!error) return false;
if (error.code === "INACTIVE_EFFECT") return true;
return /inactive context/i.test(String(error.message || error));
}
export function watchContextLife(ctx) {
const life = { alive: true };
if (!ctx || typeof ctx.effect !== "function") return life;
try {
ctx.effect(() => () => {
life.alive = false;
});
} catch (error) {
if (isInactiveContextError(error)) {
life.alive = false;
return life;
}
throw error;
}
return life;
}
export function settleDelayMs(surface) {
return surface === "desktop" ? DESKTOP_SETTLE_DELAY_MS : 0;
}
/** 桌面启动自愈不得 requestRestart / taskkill,否则 Cordis 会 INACTIVE_EFFECT。 */
export function settleMayRestart({ surface, sealed = false } = {}) {
if (surface === "desktop") return false;
if (sealed) return false;
return true;
}
/** 密封 asar 上就地 extract/swap 会和官方 Host 的 Fiber._reload 抢锁。 */
export function settleMayReapply({ surface, sealed = false } = {}) {
if (surface === "desktop" && sealed) return false;
return true;
}