|
5 | 5 |
|
6 | 6 | use std::{env, str::FromStr}; |
7 | 7 |
|
| 8 | +#[cfg(target_os = "windows")] |
| 9 | +use defguard_client::utils::sync_connections; |
8 | 10 | use defguard_client::{ |
9 | 11 | __cmd__active_connection, __cmd__all_connections, __cmd__all_instances, __cmd__all_locations, |
10 | 12 | __cmd__all_tunnels, __cmd__connect, __cmd__delete_instance, __cmd__delete_tunnel, |
@@ -219,6 +221,27 @@ async fn main() { |
219 | 221 | *app_state.db.lock().unwrap() = Some(db); |
220 | 222 | debug!("Database setup has been completed successfully."); |
221 | 223 |
|
| 224 | + // Sync already active connections on windows. |
| 225 | + // When windows is restarted, the app doesn't close the active connections |
| 226 | + // and they are still running after the restart. We sync them here to |
| 227 | + // reflect the real system's state. |
| 228 | + // TODO: Find a way to intercept the shutdown event and close all connections |
| 229 | + #[cfg(target_os = "windows")] |
| 230 | + { |
| 231 | + match sync_connections(&app_handle).await { |
| 232 | + Ok(_) => { |
| 233 | + info!("Synchronized application's active connections with the connections already open on the system, if there were any.") |
| 234 | + } |
| 235 | + Err(e) => { |
| 236 | + warn!( |
| 237 | + "Failed to synchronize application's active connections with the connections already open on the system. \ |
| 238 | + The connections' state in the application may not reflect system's state. Reconnect manually to reset them. Error details: {}", |
| 239 | + e |
| 240 | + ) |
| 241 | + } |
| 242 | + }; |
| 243 | + } |
| 244 | + |
222 | 245 | // configure tray |
223 | 246 | debug!("Configuring tray icon..."); |
224 | 247 | if let Ok(settings) = Settings::get(&app_state.get_pool()).await { |
|
0 commit comments