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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"@stablelib/base64": "^2.0.1",
"@stablelib/x25519": "^2.0.1",
"@tanstack/query-core": "^5.100.14",
"@tanstack/react-virtual": "^3.13.25",
"@tanstack/react-virtual": "^3.13.26",
"@tauri-apps/api": "^2.11.0",
"@tauri-apps/plugin-clipboard-manager": "^2.3.2",
"@tauri-apps/plugin-deep-link": "^2.4.9",
Expand Down
324 changes: 162 additions & 162 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 15 additions & 15 deletions src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

64 changes: 35 additions & 29 deletions src-tauri/src/bin/defguard-client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use defguard_client::{
LOG_FILENAME, VERSION,
};
use log::{Level, LevelFilter};
use tauri::{AppHandle, Builder, Manager, RunEvent, WindowEvent};
use tauri::{async_runtime, AppHandle, Builder, Manager, RunEvent, WindowEvent};
use tauri_plugin_deep_link::DeepLinkExt;
use tauri_plugin_log::{Target, TargetKind};

Expand Down Expand Up @@ -100,7 +100,7 @@ async fn startup(app_handle: &AppHandle) {
.lock()
.expect("failed to lock app state")
.mtu();
let handle = tauri::async_runtime::spawn(async move {
let handle = async_runtime::spawn(async move {
if let Err(err) = defguard_client::apple::sync_locations_and_tunnels(mtu).await {
error!("Failed to sync locations and tunnels: {err}");
}
Expand All @@ -122,7 +122,7 @@ async fn startup(app_handle: &AppHandle) {
});

let handle = app_handle.clone();
tauri::async_runtime::spawn(async move {
async_runtime::spawn(async move {
defguard_client::apple::connection_state_update_thread(&handle).await;
error!("Connection state update thread has exited unexpectedly, quitting the app.");
handle.exit(0);
Expand All @@ -131,7 +131,7 @@ async fn startup(app_handle: &AppHandle) {

// Run periodic tasks.
let periodic_tasks_handle = app_handle.clone();
tauri::async_runtime::spawn(async move {
async_runtime::spawn(async move {
run_periodic_tasks(&periodic_tasks_handle).await;
// One of the tasks exited, so something went wrong, quit the app
error!("One of the periodic tasks has stopped unexpectedly. Exiting the application.");
Expand All @@ -154,6 +154,17 @@ async fn startup(app_handle: &AppHandle) {
debug!("Tray menu has been re-generated successfully.");
}

/// Open the appropriate window, either the old or the new UI, depending if there are locations.
#[cfg(not(target_os = "linux"))]
fn open_appropriate_window(app_handle: &AppHandle) {
let has_locations = async_runtime::block_on(has_non_service_locations());
if has_locations {
let _ = WindowManager::open_tray(app_handle);
} else {
let _ = WindowManager::open_full_view(app_handle);
}
}

fn main() {
let app = Builder::default()
.invoke_handler(tauri::generate_handler![
Expand Down Expand Up @@ -220,14 +231,7 @@ fn main() {

#[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);
}
open_appropriate_window(app);
}
}
}))
Expand Down Expand Up @@ -370,12 +374,12 @@ fn main() {
)?;

// run DB migrations
tauri::async_runtime::block_on(handle_db_migrations());
async_runtime::block_on(handle_db_migrations());

// Check if client needs to be initialized
// and try to load provisioning config if necessary
let provisioning_config =
tauri::async_runtime::block_on(handle_client_initialization(app_handle));
async_runtime::block_on(handle_client_initialization(app_handle));

let state = AppState::new(config, provisioning_config);
app.manage(state);
Expand All @@ -395,7 +399,8 @@ fn main() {
}
#[cfg(not(target_os = "linux"))]
{
// If the app was cold-launched by a deep link the full view must open, not the tray.
// If the app was cold-launched by a deep-link, the full view must open, not the
// tray.
let launched_by_deep_link = app_handle
.deep_link()
.get_current()
Expand All @@ -406,15 +411,7 @@ fn main() {
info!("App launched via deep link, opening full view directly.");
let _ = WindowManager::open_full_view(app_handle);
} else {
let has_locations = tauri::async_runtime::block_on(
defguard_client::window_manager::has_non_service_locations()
);
if has_locations {
WindowManager::open_tray(app_handle)?;
} else {
info!("No locations found, showing full view on startup.");
let _ = WindowManager::open_full_view(app_handle);
}
open_appropriate_window(app_handle);
}
}

Expand Down Expand Up @@ -455,7 +452,7 @@ fn main() {
log_dir.display(),
service::config::DEFAULT_LOG_DIR
);
tauri::async_runtime::block_on(startup(app_handle));
async_runtime::block_on(startup(app_handle));

// Handle a deep link that launched the app (startup case).
if let Ok(Some(urls)) = app_handle.deep_link().get_current() {
Expand All @@ -465,7 +462,7 @@ fn main() {
// Handle Ctrl-C.
debug!("Setting up Ctrl-C handler.");
let app_handle_clone = app_handle.clone();
tauri::async_runtime::spawn(async move {
async_runtime::spawn(async move {
tokio::signal::ctrl_c()
.await
.expect("Signal handler failure");
Expand All @@ -490,7 +487,7 @@ fn main() {
let semaphore = Arc::new(AtomicBool::new(false));
let semaphore_clone = Arc::clone(&semaphore);

let handle = tauri::async_runtime::spawn(async move {
let handle = async_runtime::spawn(async move {
let _ = close_all_connections().await;
// This will clean the database file, pruning write-ahead log.
DB_POOL.close().await;
Expand All @@ -499,19 +496,28 @@ fn main() {
// Obj-C API needs a runtime, but at this point Tauri has closed its runtime, so
// create a temporary one.
defguard_client::apple::spawn_runloop_and_wait_for(&semaphore);
tauri::async_runtime::block_on(async move {
async_runtime::block_on(async move {
let _ = handle.await;
});
}
#[cfg(not(target_os = "macos"))]
{
tauri::async_runtime::block_on(async move {
async_runtime::block_on(async move {
let _ = close_all_connections().await;
// This will clean the database file, pruning write-ahead log.
DB_POOL.close().await;
});
}
}
#[cfg(target_os = "macos")]
RunEvent::Reopen {
has_visible_windows,
..
} => {
if !has_visible_windows {
open_appropriate_window(app_handle);
}
}
_ => {
trace!("Received event: {event:?}");
}
Expand Down
Loading
Loading