Repository navigation
Conversation
Windows does not emit before-quit for a restart, shutdown or sign-out, so unsaved edits were lost without a prompt. The main window's query-session-end now holds the session end (preventDefault) only when the renderer has reported unsaved changes, and opens the existing quit prompt. The renderer reports the flag from OpenFileStore.dirtyEntries(), whose entry map is now observable so the report follows files opened later. Fixes #3590
|
Tested on a real Windows machine (Windows Server 2022, PR build at What works
What does not
Why When the session end begins, Windows ends all of the app's worker processes at once (exit code Next Holding the session end cannot protect the edit in the cases above, and never in the forced ones. The replacement keeps a backup of unsaved editor buffers while the user types and restores them at the next start, which does not depend on what Windows allows during a restart. |
Description
What users saw: on Windows, restart, shutdown or sign-out with unsaved editor changes ended
Emdash with no "Save changes before quitting?" prompt, and the edit was lost. Windows does not
emit
before-quitfor a session end, so the quit coordinator was never asked.Now: the main window listens for Electron's
query-session-end(Windows only; Electron45.4.1 documents that
event.preventDefault()there can delay the system shutdown). When therenderer has reported unsaved changes, the coordinator calls
preventDefault()and starts theexisting quit flow (
handleQuitRequested()), so the same prompts appear: "Save changes beforequitting?", then "Quit Emdash?".
reasonsincludescritical), an updater install pending, or arenderer that cannot answer: nothing is held.
"Has unsaved changes" source:
query-session-endis answered synchronously, so main keeps acopy of the flag. The renderer reports
openFileStore.dirtyEntries().length > 0(the source thequit prompt already uses) through a new
host.setHasUnsavedChangesWire procedure, via a MobXreactionaftershutdownReady().OpenFileStore's entry map is nowobservable.map(non-deep, mutations in
runInAction), so the reaction also follows files opened later. Mainresets the flag whenever the renderer is invalidated.
What Windows allows (what the user will see): returning "do not end" from
WM_QUERYENDSESSIONmakes Windows show its own full-screen "Emdash is preventing you fromrestarting / shutting down / signing out" screen with "… anyway" and "Cancel". The Emdash prompt
is open behind it.
Discard then quits Emdash (the restart is not resumed; the user starts it again); Cancel keeps
Emdash open with the edit intact.
AutoEndTasks, a critical session end): Windows endsEmdash and the unsaved edit is lost, as today. The app cannot prevent this.
If the hold turns out to be unreliable on real Windows, the fallback would be to write dirty
buffers to a recovery location on
session-endand restore them on the next launch. Not builthere.
Unchanged: macOS and Linux (
query-session-endis emitted on Windows only), and normal quiton Windows (window close, Ctrl+Q, tray; all still go through
before-quit). The Ctrl+Q focusissue from the issue's notes is not addressed.
High-risk area: Electron shutdown coordination (
src/main/bootstrap/shutdown/), plus a newWire procedure on the host contract.
Related issues
Fixes #3590
Testing
From
apps/emdash-desktop(Linux):pnpm run format:check(root)pnpm run lint(root)nx run @emdash/emdash-desktop:typecheckvitest run --project nodexterm-tmux.test.tsalso fails onmainhere;host-supervisor.ssh.test.tspasses when run alone (2/2, twice)shutdown.test.ts+open-file-store.test.tsNew tests: session end not held without unsaved changes; held with them, and Cancel keeps the
app open; Save/confirm quits; a repeated query is held without a second prompt; not held after
the flag clears, for a critical session end, after a main-frame navigation, or with an updater
install pending; a MobX reaction on
dirtyEntries()sees edits in a file opened after itstarted.
Windows: not yet tested in the running app.
Checklist
messages and, when possible, the PR title
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.