Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions new-ui/src/pages/compact/CompactLocationsPage/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@
&.windows {
scrollbar-gutter: stable;
overflow-y: scroll;

> .locations {
padding-right: 6px;
}
padding-right: 6px;
}

> .locations {
Expand All @@ -36,7 +33,6 @@
row-gap: var(--spacing-sm);
width: 100%;
box-sizing: border-box;
padding-right: 6px;
}
}
}
24 changes: 20 additions & 4 deletions src-tauri/src/bin/defguard-client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use defguard_client::{
events::handle_deep_link,
periodic::run_periodic_tasks,
service,
tray::{configure_tray_icon, setup_tray, show_main_window},
tray::{configure_tray_icon, setup_tray},
utils::load_log_targets,
window_manager::*,
LOG_FILENAME, VERSION,
Expand Down Expand Up @@ -211,9 +211,25 @@ fn main() {
})
// Initialize plugins here, except for `tauri_plugin_log` which is handled in `setup()`.
// Single instance plugin should always be the first to register.
.plugin(tauri_plugin_single_instance::init(|app, _argv, _cwd| {
// Running instance might be hidden, so show it.
show_main_window(app);
.plugin(tauri_plugin_single_instance::init(|app, argv, _cwd| {
let is_deep_link = argv.iter().any(|a| a.starts_with("defguard://"));
// User tried to spawn second instance, mirror tray left click path.
if !is_deep_link {
#[cfg(target_os = "linux")]
let _ = WindowManager::open_full_view(app);

#[cfg(not(target_os = "linux"))]
{
let has_locations = tauri::async_runtime::block_on(
defguard_client::window_manager::has_non_service_locations(),
);
if has_locations {
let _ = WindowManager::open_tray(app);
} else {
let _ = WindowManager::open_full_view(app);
}
}
}
}))
.plugin(tauri_plugin_deep_link::init())
.plugin(tauri_plugin_dialog::init())
Expand Down
10 changes: 4 additions & 6 deletions src-tauri/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,9 @@ pub struct AddInstancePayload<'a> {

/// Handle deep-link URLs.
pub fn handle_deep_link(app_handle: &AppHandle, urls: &[Url]) {
debug!("Deep link received.");
for link in urls {
if link.path() == "/addinstance" {
if link.host_str() == Some("addinstance") {
let mut token = None;
let mut url = None;
for (key, value) in link.query_pairs() {
Expand All @@ -118,12 +119,9 @@ pub fn handle_deep_link(app_handle: &AppHandle, urls: &[Url]) {
}
}
if let (Some(token), Some(url)) = (token, url) {
info!("Deep link received: token={token}, url={url}");
// If the compact tray window is visible, hide it before opening main view.
info!("Valid Deep link received.");
if let Some(tray_win) = app_handle.get_webview_window(NEW_UI_WINDOW_ID) {
if tray_win.is_visible().unwrap_or(false) {
let _ = tray_win.hide();
}
let _ = tray_win.hide();
}
if let Err(e) = WindowManager::open_full_view(app_handle) {
warn!("Deep link: failed to open main window: {e}");
Expand Down
40 changes: 29 additions & 11 deletions src-tauri/src/tray.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,27 +154,45 @@ pub async fn setup_tray(app: &AppHandle) -> Result<(), Error> {
} = event
{
let app = icon.app_handle();
let any_visible = [NEW_UI_WINDOW_ID, OLD_UI_WINDOW_ID].iter().any(|id| {
app.get_webview_window(id)

#[cfg(target_os = "linux")]
show_main_window(app);

#[cfg(not(target_os = "linux"))]
{
let main_visible = app
.get_webview_window(OLD_UI_WINDOW_ID)
.and_then(|w| w.is_visible().ok())
.unwrap_or(false);

if main_visible {
if let Some(w) = app.get_webview_window(OLD_UI_WINDOW_ID) {
let _ = w.hide();
}
}

let tray_visible = app
.get_webview_window(NEW_UI_WINDOW_ID)
.and_then(|w| w.is_visible().ok())
.unwrap_or(false)
});
if any_visible {
hide_visible_windows(app);
} else {
#[cfg(not(target_os = "linux"))]
{
.unwrap_or(false);

if tray_visible {
if let Some(w) = app.get_webview_window(NEW_UI_WINDOW_ID) {
let _ = w.hide();
}
} else {
let has_locations = tauri::async_runtime::block_on(
crate::window_manager::has_non_service_locations(),
);
if has_locations {
if let Some(old_ui) = app.get_webview_window(OLD_UI_WINDOW_ID) {
let _ = old_ui.hide();
}
show_new_ui_window_near_tray(app);
} else {
let _ = WindowManager::open_full_view(app);
}
}
#[cfg(target_os = "linux")]
show_main_window(app);
}
}
})
Expand Down
Loading