diff --git a/src-tauri/src/daemon/autostart.rs b/src-tauri/src/daemon/autostart.rs index 24f46f0..1e78aa4 100644 --- a/src-tauri/src/daemon/autostart.rs +++ b/src-tauri/src/daemon/autostart.rs @@ -1,4 +1,5 @@ use directories::ProjectDirs; +#[cfg(any(target_os = "macos", target_os = "linux"))] use std::fs; use std::io; use std::path::PathBuf; diff --git a/src-tauri/src/vpn/storage.rs b/src-tauri/src/vpn/storage.rs index 0ce6d14..ad66bba 100644 --- a/src-tauri/src/vpn/storage.rs +++ b/src-tauri/src/vpn/storage.rs @@ -58,6 +58,39 @@ impl VpnStorage { } } + /// Create a VPN storage manager with a custom storage directory + pub fn with_dir(dir: &std::path::Path) -> Self { + let storage_path = dir.join("vpn_configs.json"); + let key_path = dir.join(".vpn_key"); + + let encryption_key = if key_path.exists() { + if let Ok(key_data) = fs::read(&key_path) { + if key_data.len() == 32 { + let mut key = [0u8; 32]; + key.copy_from_slice(&key_data); + key + } else { + let key: [u8; 32] = rand::rng().random(); + let _ = fs::write(&key_path, key); + key + } + } else { + let key: [u8; 32] = rand::rng().random(); + let _ = fs::write(&key_path, key); + key + } + } else { + let key: [u8; 32] = rand::rng().random(); + let _ = fs::write(&key_path, key); + key + }; + + Self { + storage_path, + encryption_key, + } + } + /// Get the storage file path fn get_storage_path() -> PathBuf { let data_dir = directories::ProjectDirs::from("com", "donut", "donutbrowser") diff --git a/src-tauri/tests/vpn_integration.rs b/src-tauri/tests/vpn_integration.rs index fd394e5..b396e4c 100644 --- a/src-tauri/tests/vpn_integration.rs +++ b/src-tauri/tests/vpn_integration.rs @@ -286,10 +286,8 @@ fn test_vpn_storage_import() { // Helper Functions // ============================================================================ -fn create_test_storage(_temp_dir: &tempfile::TempDir) -> VpnStorage { - // VpnStorage::new() uses the default path - // TODO: Pass temp_dir path when VpnStorage supports custom paths - VpnStorage::new() +fn create_test_storage(temp_dir: &tempfile::TempDir) -> VpnStorage { + VpnStorage::with_dir(temp_dir.path()) } // ============================================================================