From 0f30e9a1b38348213e301c06ff2ef2998ce51d8e Mon Sep 17 00:00:00 2001 From: Adam Date: Wed, 8 Jan 2025 13:44:28 +0100 Subject: [PATCH] Fix Windows build (#372) --- ...e0cebf2afc3ad798638db9ea0aabcd506192b.json | 86 +++++++++++++++++++ src-tauri/Cargo.lock | 10 +-- src-tauri/Cargo.toml | 36 ++++---- src-tauri/src/bin/defguard-service.rs | 6 +- src-tauri/src/database/models/location.rs | 15 ++++ src-tauri/src/utils.rs | 8 +- 6 files changed, 129 insertions(+), 32 deletions(-) create mode 100644 src-tauri/.sqlx/query-5953a81f34f906e34aabec089dfe0cebf2afc3ad798638db9ea0aabcd506192b.json diff --git a/src-tauri/.sqlx/query-5953a81f34f906e34aabec089dfe0cebf2afc3ad798638db9ea0aabcd506192b.json b/src-tauri/.sqlx/query-5953a81f34f906e34aabec089dfe0cebf2afc3ad798638db9ea0aabcd506192b.json new file mode 100644 index 00000000..ab312bb2 --- /dev/null +++ b/src-tauri/.sqlx/query-5953a81f34f906e34aabec089dfe0cebf2afc3ad798638db9ea0aabcd506192b.json @@ -0,0 +1,86 @@ +{ + "db_name": "SQLite", + "query": "SELECT id, instance_id, name, address, pubkey, endpoint, allowed_ips, dns, network_id,route_all_traffic, mfa_enabled, keepalive_interval FROM location;", + "describe": { + "columns": [ + { + "name": "id", + "ordinal": 0, + "type_info": "Integer" + }, + { + "name": "instance_id", + "ordinal": 1, + "type_info": "Integer" + }, + { + "name": "name", + "ordinal": 2, + "type_info": "Text" + }, + { + "name": "address", + "ordinal": 3, + "type_info": "Text" + }, + { + "name": "pubkey", + "ordinal": 4, + "type_info": "Text" + }, + { + "name": "endpoint", + "ordinal": 5, + "type_info": "Text" + }, + { + "name": "allowed_ips", + "ordinal": 6, + "type_info": "Text" + }, + { + "name": "dns", + "ordinal": 7, + "type_info": "Text" + }, + { + "name": "network_id", + "ordinal": 8, + "type_info": "Integer" + }, + { + "name": "route_all_traffic", + "ordinal": 9, + "type_info": "Bool" + }, + { + "name": "mfa_enabled", + "ordinal": 10, + "type_info": "Bool" + }, + { + "name": "keepalive_interval", + "ordinal": 11, + "type_info": "Integer" + } + ], + "parameters": { + "Right": 0 + }, + "nullable": [ + false, + false, + false, + false, + false, + false, + false, + true, + false, + false, + false, + false + ] + }, + "hash": "5953a81f34f906e34aabec089dfe0cebf2afc3ad798638db9ea0aabcd506192b" +} diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 2197542e..62031d5f 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -1320,7 +1320,7 @@ dependencies = [ "tracing-subscriber", "vergen-git2", "webbrowser", - "widestring 0.4.3", + "widestring", "winapi", "windows-service", "x25519-dalek", @@ -7169,12 +7169,6 @@ dependencies = [ "wasite", ] -[[package]] -name = "widestring" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c168940144dd21fd8046987c16a46a33d5fc84eec29ef9dcddc2ac9e31526b7c" - [[package]] name = "widestring" version = "1.1.0" @@ -7363,7 +7357,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d24d6bcc7f734a4091ecf8d7a64c5f7d7066f45585c1861eba06449909609c8a" dependencies = [ "bitflags 2.6.0", - "widestring 1.1.0", + "widestring", "windows-sys 0.52.0", ] diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 08cb9d1a..9e2df29c 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -50,24 +50,24 @@ serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" serde_with = "3.11" sqlx = { version = "0.8", features = [ - "chrono", - "sqlite", - "runtime-tokio", - "uuid", - "macros", + "chrono", + "sqlite", + "runtime-tokio", + "uuid", + "macros", ] } struct-patch = "0.8" strum = { version = "0.26", features = ["derive"] } tauri = { version = "1.8", features = [ - "notification-all", - "dialog-all", - "clipboard-all", - "http-all", - "window-all", - "system-tray", - "native-tls-vendored", - "icon-png", - "fs-all", + "notification-all", + "dialog-all", + "clipboard-all", + "http-all", + "window-all", + "system-tray", + "native-tls-vendored", + "icon-png", + "fs-all", ] } tauri-plugin-single-instance = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v1" } tauri-plugin-log = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v1" } @@ -82,15 +82,15 @@ tracing-appender = "0.2" tracing-subscriber = { version = "0.3", features = ["env-filter", "json"] } webbrowser = "1.0" x25519-dalek = { version = "2", features = [ - "getrandom", - "serde", - "static_secrets", + "getrandom", + "serde", + "static_secrets", ] } [target.'cfg(target_os = "windows")'.dependencies] windows-service = "0.7" winapi = { version = "0.3", features = ["winsvc", "winerror"] } -widestring = "0.4" +widestring = "1.1" [target.'cfg(target_os = "macos")'.dependencies] nix = { version = "0.29", features = ["net"] } diff --git a/src-tauri/src/bin/defguard-service.rs b/src-tauri/src/bin/defguard-service.rs index 08b4cff5..b7083e53 100644 --- a/src-tauri/src/bin/defguard-service.rs +++ b/src-tauri/src/bin/defguard-service.rs @@ -3,13 +3,11 @@ //! This binary is meant to run as a daemon with root privileges //! and communicate with the desktop client over HTTP. -use clap::Parser; -use defguard_client::service::{config::Config, run_server}; - #[cfg(not(windows))] #[tokio::main] async fn main() -> anyhow::Result<()> { - use defguard_client::service::utils::logging_setup; + use clap::Parser; + use defguard_client::service::{config::Config, run_server, utils::logging_setup}; // parse config let config: Config = Config::parse(); diff --git a/src-tauri/src/database/models/location.rs b/src-tauri/src/database/models/location.rs index c866d848..3bd1b5f3 100644 --- a/src-tauri/src/database/models/location.rs +++ b/src-tauri/src/database/models/location.rs @@ -36,6 +36,21 @@ impl fmt::Display for Location { } impl Location { + #[cfg(windows)] + pub(crate) async fn all<'e, E>(executor: E) -> Result, SqlxError> + where + E: SqliteExecutor<'e>, + { + query_as!( + Self, + "SELECT id, instance_id, name, address, pubkey, endpoint, allowed_ips, dns, network_id,\ + route_all_traffic, mfa_enabled, keepalive_interval \ + FROM location;" + ) + .fetch_all(executor) + .await + } + pub(crate) async fn save<'e, E>(&mut self, executor: E) -> Result<(), SqlxError> where E: SqliteExecutor<'e>, diff --git a/src-tauri/src/utils.rs b/src-tauri/src/utils.rs index dce403b5..f569e616 100644 --- a/src-tauri/src/utils.rs +++ b/src-tauri/src/utils.rs @@ -996,7 +996,9 @@ pub async fn sync_connections(app_handle: &AppHandle) -> Result<(), Error> { continue; } - appstate.add_connection(location.id, &interface_name, ConnectionType::Location); + appstate + .add_connection(location.id, &interface_name, ConnectionType::Location) + .await; debug!("Sending event informing the frontend that a new connection has been created."); app_handle.emit_all( @@ -1084,7 +1086,9 @@ pub async fn sync_connections(app_handle: &AppHandle) -> Result<(), Error> { continue; } - appstate.add_connection(tunnel.id, &interface_name, ConnectionType::Tunnel); + appstate + .add_connection(tunnel.id, &interface_name, ConnectionType::Tunnel) + .await; debug!("Sending event informing the frontend that a new connection has been created."); app_handle.emit_all(