Skip to content

Commit 4c5cc17

Browse files
committed
macOS: handle app re-open
1 parent fc4ea04 commit 4c5cc17

5 files changed

Lines changed: 29 additions & 26 deletions

File tree

src-tauri/Cargo.lock

Lines changed: 13 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src-tauri/src/bin/defguard-client.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,15 @@ fn main() {
512512
});
513513
}
514514
}
515+
#[cfg(target_os = "macos")]
516+
RunEvent::Reopen {
517+
has_visible_windows,
518+
..
519+
} => {
520+
if !has_visible_windows {
521+
let _ = WindowManager::open_tray(app_handle);
522+
}
523+
}
515524
_ => {
516525
trace!("Received event: {event:?}");
517526
}

src-tauri/src/tray.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use crate::{
1717
database::{models::location::Location, DB_POOL},
1818
error::Error,
1919
events::EventKey,
20-
window_manager::{show_new_ui_window_near_tray, NEW_UI_WINDOW_ID, OLD_UI_WINDOW_ID},
20+
window_manager::{show_new_ui_window, NEW_UI_WINDOW_ID, OLD_UI_WINDOW_ID},
2121
ConnectionType,
2222
};
2323

@@ -188,7 +188,7 @@ pub async fn setup_tray(app: &AppHandle) -> Result<(), Error> {
188188
if let Some(old_ui) = app.get_webview_window(OLD_UI_WINDOW_ID) {
189189
let _ = old_ui.hide();
190190
}
191-
show_new_ui_window_near_tray(app);
191+
show_new_ui_window(app);
192192
} else {
193193
let _ = WindowManager::open_full_view(app);
194194
}
@@ -258,7 +258,7 @@ pub fn handle_tray_menu_event(app: &AppHandle, event: MenuEvent) {
258258
info!("Received QUIT request. Initiating shutdown...");
259259
handle.exit(0);
260260
}
261-
TRAY_EVENT_SHOW => show_new_ui_window_near_tray(app),
261+
TRAY_EVENT_SHOW => show_new_ui_window(app),
262262
TRAY_EVENT_HIDE => hide_visible_windows(app),
263263
TRAY_EVENT_UPDATES => {
264264
let _ = webbrowser::open(SUBSCRIBE_UPDATES_LINK);

src-tauri/src/window_manager/mod.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ impl WindowManager {
8989
#[cfg(target_os = "macos")]
9090
macos::position_window_near_tray(app, &window);
9191
#[cfg(target_os = "macos")]
92+
let _ = app.set_dock_visibility(false);
93+
#[cfg(target_os = "macos")]
9294
let _ = app.show();
9395
let _ = window.show();
9496
let _ = window.set_focus();
@@ -103,6 +105,8 @@ impl WindowManager {
103105
Self::build_full_window(app)?
104106
};
105107
#[cfg(target_os = "macos")]
108+
let _ = app.set_dock_visibility(true);
109+
#[cfg(target_os = "macos")]
106110
let _ = app.show();
107111
let _ = window.show();
108112
let _ = window.set_focus();
@@ -123,10 +127,6 @@ pub(crate) fn show_new_ui_window(app: &AppHandle) {
123127
let _ = WindowManager::open_tray(app);
124128
}
125129

126-
pub(crate) fn show_new_ui_window_near_tray(app: &AppHandle) {
127-
show_new_ui_window(app);
128-
}
129-
130130
#[tauri::command]
131131
pub fn open_new_ui_window(app: AppHandle) {
132132
show_new_ui_window(&app);
@@ -142,9 +142,6 @@ pub fn open_old_ui_window(app: AppHandle) {
142142
#[tauri::command]
143143
pub fn swap_to_old_ui(app: AppHandle) {
144144
tracing::info!("swap_to_old_ui called");
145-
#[cfg(target_os = "macos")]
146-
let _ = app.set_dock_visibility(true);
147-
148145
if let Some(window) = tauri::Manager::get_webview_window(&app, NEW_UI_WINDOW_ID) {
149146
if let Err(err) = window.hide() {
150147
tracing::error!("swap_to_old_ui task: Failed to hide new-ui window: {err:?}");
@@ -175,9 +172,6 @@ pub fn close_tray_window(app: AppHandle) {
175172
#[tauri::command]
176173
pub fn swap_to_new_ui(app: AppHandle) {
177174
tracing::info!("swap_to_new_ui called");
178-
#[cfg(target_os = "macos")]
179-
let _ = app.set_dock_visibility(false);
180-
181175
show_new_ui_window(&app);
182176
if let Some(window) = tauri::Manager::get_webview_window(&app, OLD_UI_WINDOW_ID) {
183177
if let Err(err) = window.hide() {
-6.9 KB
Loading

0 commit comments

Comments
 (0)