refactor: split window restoration into type-specific helpers and add focus event handler
Rename restore_main_window to restore_webview_window for WebviewWindow type. Add new restore_window helper for generic Window type. Update tray menu and click handlers to use restore_webview_window. Add WindowEvent::Focused handler to restore window state when focused.
This commit is contained in:
@@ -341,7 +341,13 @@ fn ensure_app_dir(app: &AppHandle) -> Result<PathBuf, String> {
|
||||
Ok(dir)
|
||||
}
|
||||
|
||||
fn restore_main_window(window: &Window) {
|
||||
fn restore_window(window: &Window) {
|
||||
let _ = window.show();
|
||||
let _ = window.unminimize();
|
||||
let _ = window.set_focus();
|
||||
}
|
||||
|
||||
fn restore_webview_window(window: &WebviewWindow) {
|
||||
let _ = window.show();
|
||||
let _ = window.unminimize();
|
||||
let _ = window.set_focus();
|
||||
@@ -368,7 +374,7 @@ pub fn run() {
|
||||
.on_menu_event(|app, event| match event.id().as_ref() {
|
||||
"open" => {
|
||||
if let Some(window) = app.get_webview_window(MAIN_WINDOW_LABEL) {
|
||||
restore_main_window(&window);
|
||||
restore_webview_window(&window);
|
||||
}
|
||||
}
|
||||
"quit" => {
|
||||
@@ -385,7 +391,7 @@ pub fn run() {
|
||||
{
|
||||
let app = tray.app_handle();
|
||||
if let Some(window) = app.get_webview_window(MAIN_WINDOW_LABEL) {
|
||||
restore_main_window(&window);
|
||||
restore_webview_window(&window);
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -406,6 +412,9 @@ pub fn run() {
|
||||
hide_main_window(window);
|
||||
}
|
||||
}
|
||||
WindowEvent::Focused(true) => {
|
||||
restore_window(window);
|
||||
}
|
||||
_ => {}
|
||||
})
|
||||
.invoke_handler(tauri::generate_handler![load_state, enroll_device, sync_profile, connect_tunnel, disconnect_tunnel])
|
||||
|
||||
Reference in New Issue
Block a user