Skip to content

Commit a02016c

Browse files
committed
Share Workspace membership checks across teardown consent gates
1 parent d103f20 commit a02016c

2 files changed

Lines changed: 11 additions & 12 deletions

File tree

‎standalone/src/quit-confirm-store.ts‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,18 @@ function ownDialog(): void {
7575
function captureWorkspaces(): void {
7676
const workspaces = getWorkspacesSnapshot().workspaces;
7777
workspaceNames = workspaces.map((workspace) => workspace.name);
78-
const ids = new Set(workspaces.map((workspace) => workspace.id));
79-
unsubscribeWorkspaces = subscribeToWorkspaces(() => {
78+
unsubscribeWorkspaces = watchWorkspaceMembership(cancelQuit);
79+
}
80+
81+
/** Both teardown consent gates keep the Workspace membership they asked about. */
82+
export function watchWorkspaceMembership(onChange: () => void): () => void {
83+
const ids = new Set(getWorkspacesSnapshot().workspaces.map(workspace => workspace.id));
84+
return subscribeToWorkspaces(() => {
8085
const current = getWorkspacesSnapshot().workspaces;
8186
// A changed destination invalidates consent; focus, rename and order do not.
82-
// Every exit from 'open' stops this watch, so no phase check is needed.
87+
// Each gate releases its watch before settling or committing.
8388
if (current.length !== ids.size || current.some((workspace) => !ids.has(workspace.id))) {
84-
cancelQuit();
89+
onChange();
8590
}
8691
});
8792
}

‎standalone/src/teardown-flow.ts‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { invoke } from "@tauri-apps/api/core";
2-
import { getWorkspacesSnapshot, subscribeToWorkspaces } from "dormouse-lib/lib/workspace-store";
32
import { listWallHandles } from "dormouse-lib/components/wall/wall-handles";
43
import { cancelEditorClose, confirmToolEditorsClose } from "dormouse-lib/lib/tool-editor";
54
import {
65
beginQuitProgress,
76
dismissQuitConfirm,
7+
watchWorkspaceMembership,
88
type QuitConfirmIntent,
99
} from "./quit-confirm-store";
1010

@@ -164,13 +164,7 @@ export function createTeardownFlow(options: {
164164
const dirty = listWallHandles().flatMap((wall) => wall.dirtyToolIds());
165165
if (dirty.length) {
166166
enter("confirming");
167-
const ids = new Set(getWorkspacesSnapshot().workspaces.map(workspace => workspace.id));
168-
const mine = { stopWatching: subscribeToWorkspaces(() => {
169-
const current = getWorkspacesSnapshot().workspaces;
170-
// The unsaved-file question precedes the running-work dialog, but
171-
// its consent is already scoped to the Workspaces present now.
172-
if (current.length !== ids.size || current.some(workspace => !ids.has(workspace.id))) cancel();
173-
}) };
167+
const mine = { stopWatching: watchWorkspaceMembership(cancel) };
174168
editorWait = mine;
175169
void confirmToolEditorsClose(dirty).then((accepted) => {
176170
if (editorWait !== mine) return;

0 commit comments

Comments
 (0)