Skip to content

Commit fc4ea04

Browse files
fix deep link handling rust side (#904)
1 parent fea1f86 commit fc4ea04

4 files changed

Lines changed: 54 additions & 26 deletions

File tree

new-ui/src/pages/compact/CompactLocationsPage/style.scss

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,7 @@
2424
&.windows {
2525
scrollbar-gutter: stable;
2626
overflow-y: scroll;
27-
28-
> .locations {
29-
padding-right: 6px;
30-
}
27+
padding-right: 6px;
3128
}
3229

3330
> .locations {
@@ -36,7 +33,6 @@
3633
row-gap: var(--spacing-sm);
3734
width: 100%;
3835
box-sizing: border-box;
39-
padding-right: 6px;
4036
}
4137
}
4238
}

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

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use defguard_client::{
2828
events::handle_deep_link,
2929
periodic::run_periodic_tasks,
3030
service,
31-
tray::{configure_tray_icon, setup_tray, show_main_window},
31+
tray::{configure_tray_icon, setup_tray},
3232
utils::load_log_targets,
3333
window_manager::*,
3434
LOG_FILENAME, VERSION,
@@ -211,9 +211,25 @@ fn main() {
211211
})
212212
// Initialize plugins here, except for `tauri_plugin_log` which is handled in `setup()`.
213213
// Single instance plugin should always be the first to register.
214-
.plugin(tauri_plugin_single_instance::init(|app, _argv, _cwd| {
215-
// Running instance might be hidden, so show it.
216-
show_main_window(app);
214+
.plugin(tauri_plugin_single_instance::init(|app, argv, _cwd| {
215+
let is_deep_link = argv.iter().any(|a| a.starts_with("defguard://"));
216+
// User tried to spawn second instance, mirror tray left click path.
217+
if !is_deep_link {
218+
#[cfg(target_os = "linux")]
219+
let _ = WindowManager::open_full_view(app);
220+
221+
#[cfg(not(target_os = "linux"))]
222+
{
223+
let has_locations = tauri::async_runtime::block_on(
224+
defguard_client::window_manager::has_non_service_locations(),
225+
);
226+
if has_locations {
227+
let _ = WindowManager::open_tray(app);
228+
} else {
229+
let _ = WindowManager::open_full_view(app);
230+
}
231+
}
232+
}
217233
}))
218234
.plugin(tauri_plugin_deep_link::init())
219235
.plugin(tauri_plugin_dialog::init())

src-tauri/src/events.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,9 @@ pub struct AddInstancePayload<'a> {
105105

106106
/// Handle deep-link URLs.
107107
pub fn handle_deep_link(app_handle: &AppHandle, urls: &[Url]) {
108+
debug!("Deep link received.");
108109
for link in urls {
109-
if link.path() == "/addinstance" {
110+
if link.host_str() == Some("addinstance") {
110111
let mut token = None;
111112
let mut url = None;
112113
for (key, value) in link.query_pairs() {
@@ -118,12 +119,9 @@ pub fn handle_deep_link(app_handle: &AppHandle, urls: &[Url]) {
118119
}
119120
}
120121
if let (Some(token), Some(url)) = (token, url) {
121-
info!("Deep link received: token={token}, url={url}");
122-
// If the compact tray window is visible, hide it before opening main view.
122+
info!("Valid Deep link received.");
123123
if let Some(tray_win) = app_handle.get_webview_window(NEW_UI_WINDOW_ID) {
124-
if tray_win.is_visible().unwrap_or(false) {
125-
let _ = tray_win.hide();
126-
}
124+
let _ = tray_win.hide();
127125
}
128126
if let Err(e) = WindowManager::open_full_view(app_handle) {
129127
warn!("Deep link: failed to open main window: {e}");

src-tauri/src/tray.rs

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -154,27 +154,45 @@ pub async fn setup_tray(app: &AppHandle) -> Result<(), Error> {
154154
} = event
155155
{
156156
let app = icon.app_handle();
157-
let any_visible = [NEW_UI_WINDOW_ID, OLD_UI_WINDOW_ID].iter().any(|id| {
158-
app.get_webview_window(id)
157+
158+
#[cfg(target_os = "linux")]
159+
show_main_window(app);
160+
161+
#[cfg(not(target_os = "linux"))]
162+
{
163+
let main_visible = app
164+
.get_webview_window(OLD_UI_WINDOW_ID)
165+
.and_then(|w| w.is_visible().ok())
166+
.unwrap_or(false);
167+
168+
if main_visible {
169+
if let Some(w) = app.get_webview_window(OLD_UI_WINDOW_ID) {
170+
let _ = w.hide();
171+
}
172+
}
173+
174+
let tray_visible = app
175+
.get_webview_window(NEW_UI_WINDOW_ID)
159176
.and_then(|w| w.is_visible().ok())
160-
.unwrap_or(false)
161-
});
162-
if any_visible {
163-
hide_visible_windows(app);
164-
} else {
165-
#[cfg(not(target_os = "linux"))]
166-
{
177+
.unwrap_or(false);
178+
179+
if tray_visible {
180+
if let Some(w) = app.get_webview_window(NEW_UI_WINDOW_ID) {
181+
let _ = w.hide();
182+
}
183+
} else {
167184
let has_locations = tauri::async_runtime::block_on(
168185
crate::window_manager::has_non_service_locations(),
169186
);
170187
if has_locations {
188+
if let Some(old_ui) = app.get_webview_window(OLD_UI_WINDOW_ID) {
189+
let _ = old_ui.hide();
190+
}
171191
show_new_ui_window_near_tray(app);
172192
} else {
173193
let _ = WindowManager::open_full_view(app);
174194
}
175195
}
176-
#[cfg(target_os = "linux")]
177-
show_main_window(app);
178196
}
179197
}
180198
})

0 commit comments

Comments
 (0)