mirror of
https://github.com/YuJunZhiXue/dsh-purge.git
synced 2026-11-28 05:10:22 +08:00
44 lines
1.3 KiB
JavaScript
44 lines
1.3 KiB
JavaScript
/** 官方桌面启动时 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;
|
||
}
|