示例工程 47-crash-recovery

47-crash-recovery/app/.tsc/shared/ipc.js

javascript · 1.5 KB

export const CH = {
    snapshot: "crash:snapshot",
    crash: "crash:renderer",
    reload: "crash:reload",
    reportError: "crash:report-error",
    ready: "crash:ready",
    refresh: "crash:refresh",
    clearHistory: "crash:clear-history",
};
export function assertNoArgs(value) {
    if (value !== undefined)
        throw new Error("BAD_ARGS");
}
export function assertErrorInfo(value) {
    if (typeof value !== "object" || value === null) {
        throw new Error("BAD_ERROR_REPORT");
    }
    const report = value;
    if (typeof report.message !== "string" ||
        report.message.length === 0 ||
        report.message.length > 2000 ||
        typeof report.source !== "string" ||
        typeof report.line !== "number") {
        throw new Error("BAD_ERROR_REPORT");
    }
}
export function decideRecovery(reason, attempts) {
    if (reason === "clean-exit" || reason === "killed") {
        return {
            action: "reload",
            delayMs: 300,
            detail: "进程被结束,直接重建渲染进程",
        };
    }
    if (attempts >= 3) {
        return {
            action: "safe-mode",
            delayMs: 1200,
            detail: "短时间内多次崩溃,进入安全模式并停止自动恢复",
        };
    }
    const delayMs = Math.min(300 * 2 ** attempts, 5000);
    return {
        action: "reload",
        delayMs,
        detail: `第 ${attempts + 1} 次恢复,退避 ${delayMs}ms`,
    };
}
//# sourceMappingURL=ipc.js.map