fix(macos): keep project tab close confirmations visible (#7501)

Closing a macOS project tab group could cover the running-agent confirmation when a peer returned to Welcome and took focus. Confirmations and the Welcome transition now take turns, and background web views stay attached while their close checks are pending.
Цей коміт міститься в:
l0ng-ai authored and GitHub committed 2026-12-02 21:43:58 +08:00
1 джерело 24588b0975
коміт 1ba2ce55bb
6 files changed
+73 -17

No files matched your search

+3 -2
Переглянути файл
@@ -393,8 +393,9 @@ pub fn window_close_context(app: AppHandle, window: Window, windows: State<'_, W
};
let quitting = windows.quitting();
let has_document_windows = !windows::document_windows(&app, window.label()).is_empty();
let hidden_tab = windows.groups.lock().group(window.label()).is_some_and(|g| g.selected != window.label());
let batch = quitting || pending.len() > 1 || windows.in_tab_close_batch(window.label()) || hidden_tab;
// AppKit can deliver the selected tab's close before its siblings have registered theirs.
let grouped = windows.groups.lock().group(window.label()).is_some();
let batch = quitting || pending.len() > 1 || windows.in_tab_close_batch(window.label()) || grouped;
CloseContext { quitting, windows: count as u32, has_document_windows, batch }
}
+6
Переглянути файл
@@ -291,6 +291,12 @@ pub fn run() {
}
#[cfg(target_os = "linux")]
linux_window_state::save_before_close(window.app_handle());
// A background tab's detached page is suspended: it would never answer the close, and a
// prompt it shows would stay off screen while the rest of the group closes around it.
#[cfg(target_os = "macos")]
if let Some(webview) = window.app_handle().get_webview_window(window.label()) {
macos::attach(&webview);
}
if let Some(w) = window.try_state::<WindowsState>() {
w.close_requested(window.label());
}
+6
Переглянути файл
@@ -189,6 +189,12 @@ fn detach_if_background(window: &WebviewWindow, generation: u64) {
if !BACKGROUND.with_borrow(|tabs| tabs.due(window.label(), generation)) {
return;
}
// Selecting a peer for its close dialog can schedule another detach. Keep this
// page attached until its own close guard has answered.
if window.state::<WindowsState>().is_closing(window.label()) {
BACKGROUND.with_borrow_mut(|tabs| tabs.cancel(window.label()));
return;
}
let Some(native) = native(window) else { return };
// A visible window is never a background tab.
if native.occlusionState().contains(NSWindowOcclusionState::Visible) {
-7
Переглянути файл
@@ -365,13 +365,6 @@ pub fn cancel_close(app: &AppHandle, caller: &str) {
return;
}
state.close_settled(caller);
// For a red-button group close where this tab stayed open (e.g. returned to Welcome),
// select it so closing siblings disappear behind it without flashing.
if state.groups.lock().group(caller).is_some()
&& let Some(window) = app.get_webview_window(caller)
{
windows::focus(&window);
}
if !state.has_other_pending_closes(caller) && !state.quitting() {
let app = app.clone();
tauri::async_runtime::spawn(async move {
+44
Переглянути файл
@@ -125,6 +125,50 @@ describe("native window close", () => {
expect(forget).not.toHaveBeenCalled();
});
it("keeps a tab returning to Welcome from covering a peer's close dialog", async () => {
vi.mocked(ipc.commands.windowCloseContext).mockResolvedValue({
quitting: false,
windows: 1,
hasDocumentWindows: false,
batch: true,
});
let releasePeer!: (proceed: boolean) => void;
vi.mocked(ipc.commands.windowBeginPrompt).mockReturnValue(new Promise((resolve) => (releasePeer = resolve)));
const closing = close({});
await vi.waitFor(() => expect(ipc.commands.windowBeginPrompt).toHaveBeenCalledOnce());
expect(ipc.commands.closeProject).not.toHaveBeenCalled();
releasePeer(true);
expect(await closing).toHaveBeenCalledOnce();
expect(ipc.commands.closeProject).toHaveBeenCalledOnce();
expect(ipc.commands.closeProject).toHaveBeenCalledBefore(vi.mocked(ipc.commands.windowGroupCancelClose));
});
it("keeps the agent task's tab visible through confirmation and the transition to Welcome", async () => {
vi.mocked(ipc.commands.windowCloseContext).mockResolvedValue({
quitting: false,
windows: 1,
hasDocumentWindows: false,
batch: true,
});
deps.runningAgentTasks = async () => [{ id: "t1", title: "Refactor auth" }];
let answer!: (result: { button: string; checked: boolean }) => void;
deps.ask = vi.fn(() => new Promise<{ button: string; checked: boolean }>((resolve) => (answer = resolve)));
const closing = close({});
await vi.waitFor(() => expect(deps.ask).toHaveBeenCalledOnce());
expect(ipc.commands.windowBeginPrompt).toHaveBeenCalledBefore(vi.mocked(deps.ask));
expect(ipc.commands.closeProject).not.toHaveBeenCalled();
expect(ipc.commands.windowReadyToClose).not.toHaveBeenCalled();
expect(ipc.commands.windowEndPrompt).not.toHaveBeenCalled();
answer({ button: "pause", checked: false });
expect(await closing).toHaveBeenCalledOnce();
expect(ipc.commands.windowBeginPrompt).toHaveBeenCalledOnce();
expect(ipc.commands.closeProject).toHaveBeenCalledOnce();
});
it("closes the Welcome window without the exit prompt when confirm exit is on", async () => {
const prevented = await close({ confirmExit: true }, false, true);
expect(prevented).not.toHaveBeenCalled();
+14 -8
Переглянути файл
@@ -338,6 +338,13 @@ async function onCloseRequested(deps: CloseDeps): Promise<boolean> {
let promptHeld = false;
let batchAborted = false;
let frozen: (() => void) | undefined;
const acquirePromptTurn = async () => {
if (!promptHeld) {
promptHeld = await commands.windowBeginPrompt();
batchAborted = !promptHeld;
}
return promptHeld;
};
const cancel = async () => {
if (!batchAborted) {
await (quitting ? commands.appCancelQuit() : commands.windowGroupCancelClose());
@@ -359,14 +366,7 @@ async function onCloseRequested(deps: CloseDeps): Promise<boolean> {
deps = {
...deps,
ask: async (request) => {
if (!promptHeld) {
const proceed = await commands.windowBeginPrompt();
if (!proceed) {
batchAborted = true;
return { button: "cancel", checked: false };
}
promptHeld = true;
}
if (!(await acquirePromptTurn())) return { button: "cancel", checked: false };
await raiseWindowForPrompts();
return baseAsk(request);
},
@@ -422,6 +422,12 @@ async function onCloseRequested(deps: CloseDeps): Promise<boolean> {
return await cancel();
}
}
// Returning to Welcome detaches and focuses this window. Wait for any peer's dialog
// before doing that, and hold the turn until the native transition is complete.
if (welcome && ctx.batch && !(await acquirePromptTurn())) {
maybeEditorService()?.cancelClose?.();
return false;
}
forgot = forgetTabs();
if (!forgot && (!welcome || remote.session)) maybeEditorService()?.flushSession?.();
if (welcome) {