Q183: unsaved input is kept across pages, and leaving or closing asks before losing it

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ZacharyZhang-NYandClaude Opus 5.5 committed 2026-10-09 07:30:13 -04:00
1 parent 3f8832702e
commit 2790d88186
27 files changed
+351 -41

No files matched your search

+1
View File
@@ -14,6 +14,7 @@ const noInput = z.undefined();
export const IPC_CONTRACTS: { [K in InvokedMethod]: z.ZodType<InputOf<K>> } = {
loadSnapshot: noInput,
relaunchApp: noInput,
reportUnsaved: z.strictObject({ unsaved: z.boolean() }),
runningSessionCount: noInput,
pickDirectory: noInput,
listConnectorCatalog: noInput,
+5
View File
@@ -42,6 +42,7 @@ import { runHistory } from "../services/run-history";
import { deleteWorkspace, setPrimaryWorkspace, updateWorkspace } from "../services/workspace-admin";
import { setProviderModel } from "../services/provider-default-model";
import { completeSetup, saveOnboardingDraft } from "../services/onboarding-progress";
import { setUnsavedInput } from "./unsaved-guard";
import { providerDisconnectImpact } from "../services/provider-disconnect-impact";
export interface IpcDeps {
@@ -151,6 +152,10 @@ export function registerIpcHandlers(deps: IpcDeps): void {
}
});
handle("completeSetup", (input) => mutate(() => completeSetup(deps.connection.db, input.orgId)));
handle("reportUnsaved", (input) => {
setUnsavedInput(input.unsaved);
return ok(null);
});
handle("runningSessionCount", () => ok((deps.connection.db.prepare("select count(*) as n from task_runs where state = 'running'").get() as { n: number }).n));
// Chromium's locale is fixed at launch; the reply goes out before the process exits.
handle("relaunchApp", () => {
+29
View File
@@ -0,0 +1,29 @@
import { dialog, type BrowserWindow } from "electron";
let unsaved = false;
/** The renderer reports whether any typed input would be lost; closing asks first while it is. */
export function setUnsavedInput(value: boolean): void {
unsaved = value;
}
/** True when closing may go ahead: nothing is unsaved, or the user chose to discard it. */
export function confirmDiscardOnClose(win: BrowserWindow, language: "en" | "zh"): boolean {
if (!unsaved) return true;
const zh = language === "zh";
const choice = dialog.showMessageBoxSync(win, {
type: "warning",
buttons: [zh ? "放弃并关闭" : "Discard and close", zh ? "留下" : "Stay"],
defaultId: 1,
cancelId: 1,
message: zh ? "有尚未保存或发送的内容。" : "Some of what you typed is not saved or sent.",
detail: zh ? "关闭应用会丢失这些内容。" : "Closing the app discards it.",
});
if (choice !== 0) {
console.info("[app] close cancelled: unsaved input kept");
return false;
}
unsaved = false;
console.info("[app] closing with unsaved input discarded");
return true;
}
+10
View File
@@ -11,6 +11,7 @@ import { SkillService } from "./services/skill-service";
import { startProviderBackgroundWorker } from "./app/provider-background-worker";
import { recoverInterruptedWork } from "./app/startup-recovery";
import { startTaskQueueWorker } from "./app/task-queue-worker";
import { confirmDiscardOnClose } from "./app/unsaved-guard";
import { stopAllRunsAndWait } from "./services/run-control";
const QUIT_GRACE_MS = 10_000;
@@ -66,8 +67,17 @@ if (!app.requestSingleInstanceLock()) {
});
let shutdown: "running" | "draining" | "drained" = "running";
const uiLanguage = language === "zh" ? "zh" : "en";
// Asked before anything shuts down, so choosing to stay leaves the app fully running.
win.on("close", (event) => {
if (shutdown === "running" && !confirmDiscardOnClose(win, uiLanguage)) event.preventDefault();
});
app.on("before-quit", (event) => {
if (shutdown === "drained") return;
if (shutdown === "running" && !confirmDiscardOnClose(win, uiLanguage)) {
event.preventDefault();
return;
}
// Hold every exit request until running sessions are stopped and have recorded how they ended.
event.preventDefault();
if (shutdown === "draining") return;