-
Notifications
You must be signed in to change notification settings - Fork 20
fix: confirm desktop close behavior before hiding to tray #118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 5 commits
fd71afb
4b9e443
f3db42a
98c570f
7da9e76
dee9ab5
b74fcdf
b8873db
1e24289
dfc0ce2
8adb9ea
99a4845
ac4e7d1
ee14bae
0392943
45230cd
7acc59c
e5d7b14
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -13,9 +13,10 @@ use crate::bridge::updater_types::{ | |||||
| map_update_channel_ok, map_update_check_error, map_update_install_error, map_update_install_ok, | ||||||
| DesktopAppUpdateChannelResult, DesktopAppUpdateCheckResult, DesktopAppUpdateResult, | ||||||
| }; | ||||||
| use crate::close_behavior::{self, CloseAction}; | ||||||
| use crate::{ | ||||||
| append_desktop_log, restart_backend_flow, runtime_paths, shell_locale, tray, update_channel, | ||||||
| BackendBridgeResult, BackendBridgeState, BackendState, DEFAULT_SHELL_LOCALE, | ||||||
| window, BackendBridgeResult, BackendBridgeState, BackendState, DEFAULT_SHELL_LOCALE, | ||||||
| }; | ||||||
|
|
||||||
| fn resolve_update_channel(app_handle: &AppHandle) -> update_channel::UpdateChannel { | ||||||
|
|
@@ -160,6 +161,11 @@ fn parse_openable_url(raw_url: &str) -> Result<Url, String> { | |||||
| } | ||||||
| } | ||||||
|
|
||||||
| fn parse_close_prompt_action(raw_action: &str) -> Result<CloseAction, String> { | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue (complexity): Consider inlining the close-prompt cleanup and parsing logic into the command to avoid extra helper layers that add indirection without clear benefit. You can reduce indirection here without losing any functionality. 1. Remove
|
||||||
| close_behavior::parse_close_action(raw_action) | ||||||
| .ok_or_else(|| "Invalid close action. Expected 'tray' or 'exit'.".to_string()) | ||||||
| } | ||||||
|
sourcery-ai[bot] marked this conversation as resolved.
|
||||||
|
|
||||||
| #[cfg(target_os = "macos")] | ||||||
| fn open_url_with_system_browser(url: &str) -> Result<(), String> { | ||||||
| Command::new("open") | ||||||
|
|
@@ -287,6 +293,68 @@ pub(crate) fn desktop_bridge_open_external_url(url: String) -> BackendBridgeResu | |||||
| } | ||||||
| } | ||||||
|
|
||||||
| #[tauri::command] | ||||||
| pub(crate) fn desktop_bridge_submit_close_prompt( | ||||||
| app_handle: AppHandle, | ||||||
| action: String, | ||||||
| remember: bool, | ||||||
| ) -> BackendBridgeResult { | ||||||
| let action = match parse_close_prompt_action(&action) { | ||||||
| Ok(action) => action, | ||||||
| Err(error) => { | ||||||
| return BackendBridgeResult { | ||||||
| ok: false, | ||||||
| reason: Some(error), | ||||||
| }; | ||||||
| } | ||||||
| }; | ||||||
|
|
||||||
| if remember { | ||||||
| let packaged_root_dir = runtime_paths::default_packaged_root_dir(); | ||||||
| if let Err(error) = | ||||||
| close_behavior::write_cached_close_action(Some(action), packaged_root_dir.as_deref()) | ||||||
| { | ||||||
| append_desktop_log(&format!( | ||||||
| "failed to persist remembered close action; continuing with selected action: {error}" | ||||||
| )); | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| match action { | ||||||
| CloseAction::Tray => { | ||||||
| window::actions::hide_main_window( | ||||||
| &app_handle, | ||||||
| DEFAULT_SHELL_LOCALE, | ||||||
| append_desktop_log, | ||||||
| ); | ||||||
| if let Some(prompt_window) = app_handle.get_webview_window("close-confirm") { | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid using hardcoded strings for window labels. It is better to use the constant defined in the
Suggested change
|
||||||
| if let Err(error) = prompt_window.close() { | ||||||
| let reason = format!("Failed to close close confirm prompt window: {error}"); | ||||||
| append_desktop_log(&reason); | ||||||
| return BackendBridgeResult { | ||||||
| ok: false, | ||||||
| reason: Some(reason), | ||||||
| }; | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| BackendBridgeResult { | ||||||
|
sourcery-ai[bot] marked this conversation as resolved.
Outdated
|
||||||
| ok: true, | ||||||
| reason: None, | ||||||
| } | ||||||
| } | ||||||
| CloseAction::Exit => { | ||||||
| let state = app_handle.state::<BackendState>(); | ||||||
| state.mark_quitting(); | ||||||
| app_handle.exit(0); | ||||||
| BackendBridgeResult { | ||||||
| ok: true, | ||||||
| reason: None, | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| #[tauri::command] | ||||||
| pub(crate) fn desktop_bridge_set_shell_locale( | ||||||
| app_handle: AppHandle, | ||||||
|
|
@@ -470,6 +538,20 @@ mod tests { | |||||
| ); | ||||||
| } | ||||||
|
|
||||||
| #[test] | ||||||
| fn parse_close_prompt_action_accepts_supported_values() { | ||||||
| assert_eq!(parse_close_prompt_action("tray"), Ok(CloseAction::Tray)); | ||||||
| assert_eq!(parse_close_prompt_action("exit"), Ok(CloseAction::Exit)); | ||||||
| } | ||||||
|
|
||||||
| #[test] | ||||||
| fn parse_close_prompt_action_rejects_invalid_values() { | ||||||
| assert_eq!( | ||||||
| parse_close_prompt_action("minimize"), | ||||||
| Err("Invalid close action. Expected 'tray' or 'exit'.".to_string()) | ||||||
| ); | ||||||
| } | ||||||
|
|
||||||
| #[test] | ||||||
| fn updater_check_manual_download_mode_only_reports_reason_without_forced_update_flag() { | ||||||
| let result = crate::bridge::updater_types::map_manual_download_no_update_result( | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Performing synchronous file I/O and environment/home directory resolution within the window event loop can lead to UI unresponsiveness or stutters, as this closure runs on the main thread. Consider caching the
packaged_root_dirand thesaved_close_actionin theBackendStateduring application startup to avoid blocking the event loop on every close request.