Skip to content

Commit ee14bae

Browse files
committed
fix: surface close preference save failures
1 parent ac4e7d1 commit ee14bae

4 files changed

Lines changed: 49 additions & 12 deletions

File tree

scripts/ui/close-confirm.test.mjs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,11 @@ test('close confirm dialog reads close action values from query params instead o
4040
assert.doesNotMatch(html, /submit\("tray"\)/);
4141
assert.doesNotMatch(html, /submit\("exit"\)/);
4242
});
43+
44+
test('close confirm dialog only schedules frontend close fallback for tray actions', async () => {
45+
const html = await readHtml();
46+
47+
assert.match(html, /if \(action === trayAction\) \{/);
48+
assert.match(html, /recoveryTimer = window\.setTimeout\(/);
49+
assert.match(html, /window\.close\(\);/);
50+
});

src-tauri/src/bridge/commands.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,8 +339,12 @@ pub(crate) fn desktop_bridge_submit_close_prompt(
339339
append_desktop_log,
340340
) {
341341
append_desktop_log(&format!(
342-
"failed to persist remembered close action; continuing with selected action: {error}"
342+
"failed to persist remembered close action; aborting selected action: {error}"
343343
));
344+
return BackendBridgeResult {
345+
ok: false,
346+
reason: Some(error),
347+
};
344348
}
345349
}
346350

@@ -362,6 +366,15 @@ pub(crate) fn desktop_bridge_submit_close_prompt(
362366
finish_tray_close_prompt_cleanup(cleanup_result, append_desktop_log)
363367
}
364368
CloseAction::Exit => {
369+
if let Some(prompt_window) =
370+
app_handle.get_webview_window(window::close_confirm::CLOSE_CONFIRM_WINDOW_LABEL)
371+
{
372+
if let Err(error) = prompt_window.close() {
373+
append_desktop_log(&format!(
374+
"Failed to close confirm prompt window before exit: {error}"
375+
));
376+
}
377+
}
365378
crate::lifecycle::events::request_immediate_exit(
366379
&app_handle,
367380
crate::lifecycle::events::ImmediateExitTrigger::ClosePromptExitAction,

src-tauri/src/close_behavior.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,9 @@ where
147147
{
148148
let Some(state_path) = crate::desktop_state::resolve_desktop_state_path(packaged_root_dir)
149149
else {
150-
log("close behavior state path is unavailable; skipping close action persistence");
151-
return Ok(());
150+
let message = "close behavior state path is unavailable; skipping close action persistence";
151+
log(message);
152+
return Err(message.to_string());
152153
};
153154

154155
write_cached_close_action_at_path(action, &state_path, &log)
@@ -379,4 +380,17 @@ mod tests {
379380
None
380381
);
381382
}
383+
384+
#[test]
385+
fn write_cached_close_action_errors_when_state_path_is_unavailable() {
386+
let result = super::write_cached_close_action(Some(CloseAction::Tray), None, &noop_log);
387+
388+
assert_eq!(
389+
result,
390+
Err(
391+
"close behavior state path is unavailable; skipping close action persistence"
392+
.to_string()
393+
)
394+
);
395+
}
382396
}

ui/close-confirm.html

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -243,16 +243,18 @@ <h1 id="title"></h1>
243243
return;
244244
}
245245

246-
recoveryTimer = window.setTimeout(() => {
247-
recoveryTimer = null;
248-
if (document.visibilityState !== "hidden") {
249-
error.textContent = copy.submitStalled;
250-
setPending(false);
246+
if (action === trayAction) {
247+
recoveryTimer = window.setTimeout(() => {
248+
recoveryTimer = null;
249+
if (document.visibilityState !== "hidden") {
250+
error.textContent = copy.submitStalled;
251+
setPending(false);
252+
}
253+
}, 1500);
254+
255+
if (typeof window.close === "function") {
256+
window.close();
251257
}
252-
}, 1500);
253-
254-
if (typeof window.close === "function") {
255-
window.close();
256258
}
257259
} catch (_invokeError) {
258260
error.textContent = copy.submitError;

0 commit comments

Comments
 (0)