Skip to content

Commit e92d8b6

Browse files
rust side
1 parent a3a8333 commit e92d8b6

2 files changed

Lines changed: 50 additions & 10 deletions

File tree

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

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use defguard_client::{
2525
DB_POOL,
2626
},
2727
enterprise::provisioning::handle_client_initialization,
28+
events::handle_deep_link,
2829
periodic::run_periodic_tasks,
2930
service,
3031
tray::{configure_tray_icon, setup_tray, show_main_window},
@@ -34,6 +35,7 @@ use defguard_client::{
3435
};
3536
use log::{Level, LevelFilter};
3637
use tauri::{AppHandle, Builder, Manager, RunEvent, WindowEvent};
38+
use tauri_plugin_deep_link::DeepLinkExt;
3739
use tauri_plugin_log::{Target, TargetKind};
3840

3941
#[macro_use]
@@ -272,6 +274,14 @@ fn main() {
272274

273275
let app_handle = app.app_handle();
274276

277+
// Single Rust-side entry point for all deep link events (runtime).
278+
{
279+
let handle = app_handle.clone();
280+
app.deep_link().on_open_url(move |event| {
281+
handle_deep_link(&handle, &event.urls());
282+
});
283+
}
284+
275285
// Prepare `AppConfig`.
276286
let config = AppConfig::new(app_handle);
277287

@@ -360,21 +370,34 @@ fn main() {
360370
warn!("Failed to pre-build full window: {e}");
361371
}
362372

373+
// If the app was cold-launched by a deep link the full view must open, not the tray.
374+
let launched_by_deep_link = app_handle
375+
.deep_link()
376+
.get_current()
377+
.ok()
378+
.flatten()
379+
.is_some();
380+
363381
// Decide which window to show based on platform and available locations.
364382
#[cfg(target_os = "linux")]
365383
{
366384
let _ = WindowManager::open_full_view(app_handle);
367385
}
368386
#[cfg(not(target_os = "linux"))]
369387
{
370-
let has_locations = tauri::async_runtime::block_on(
371-
defguard_client::window_manager::has_non_service_locations()
372-
);
373-
if has_locations {
374-
WindowManager::open_tray(app_handle)?;
375-
} else {
376-
info!("No locations found, showing full view on startup.");
388+
if launched_by_deep_link {
389+
info!("App launched via deep link, opening full view directly.");
377390
let _ = WindowManager::open_full_view(app_handle);
391+
} else {
392+
let has_locations = tauri::async_runtime::block_on(
393+
defguard_client::window_manager::has_non_service_locations()
394+
);
395+
if has_locations {
396+
WindowManager::open_tray(app_handle)?;
397+
} else {
398+
info!("No locations found, showing full view on startup.");
399+
let _ = WindowManager::open_full_view(app_handle);
400+
}
378401
}
379402
}
380403

@@ -417,6 +440,11 @@ fn main() {
417440
);
418441
tauri::async_runtime::block_on(startup(app_handle));
419442

443+
// Handle a deep link that launched the app (startup case).
444+
if let Ok(Some(urls)) = app_handle.deep_link().get_current() {
445+
handle_deep_link(app_handle, &urls);
446+
}
447+
420448
// Handle Ctrl-C.
421449
debug!("Setting up Ctrl-C handler.");
422450
let app_handle_clone = app_handle.clone();

src-tauri/src/events.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
use serde::Serialize;
2-
use tauri::{AppHandle, Emitter, Url};
2+
use tauri::{AppHandle, Emitter, Manager, Url};
33
use tauri_plugin_notification::NotificationExt;
44

5-
use crate::{tray::show_main_window, ConnectionType};
5+
use crate::{
6+
window_manager::{WindowManager, NEW_UI_WINDOW_ID},
7+
ConnectionType,
8+
};
69

710
// Match src/pages/client/types.ts.
811
#[non_exhaustive]
@@ -115,7 +118,16 @@ pub fn handle_deep_link(app_handle: &AppHandle, urls: &[Url]) {
115118
}
116119
}
117120
if let (Some(token), Some(url)) = (token, url) {
118-
show_main_window(app_handle);
121+
info!("Deep link received: token={token}, url={url}");
122+
// If the compact tray window is visible, hide it before opening main view.
123+
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+
}
127+
}
128+
if let Err(e) = WindowManager::open_full_view(app_handle) {
129+
warn!("Deep link: failed to open main window: {e}");
130+
}
119131
let _ = app_handle.emit(
120132
EventKey::AddInstance.into(),
121133
AddInstancePayload {

0 commit comments

Comments
 (0)