diff --git a/src-tauri/src/browser_runner.rs b/src-tauri/src/browser_runner.rs index f94c00f..9e08527 100644 --- a/src-tauri/src/browser_runner.rs +++ b/src-tauri/src/browser_runner.rs @@ -38,12 +38,6 @@ impl BrowserRunner { &BROWSER_RUNNER } - /// Migrate old profile structure to new UUID-based structure - pub async fn migrate_profiles_to_uuid(&self) -> Result, Box> { - let profile_manager = ProfileManager::instance(); - profile_manager.migrate_profiles_to_uuid().await - } - // Helper function to check if a process matches TOR/Mullvad browser fn is_tor_or_mullvad_browser( &self, diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index c2b1a5c..c367522 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -220,26 +220,6 @@ pub fn run() { } } - // Migrate profiles to UUID format if needed (async) - println!("Checking for profile migration..."); - let browser_runner = browser_runner::BrowserRunner::instance(); - tauri::async_runtime::spawn(async move { - match browser_runner.migrate_profiles_to_uuid().await { - Ok(migrated) => { - if !migrated.is_empty() { - println!( - "Successfully migrated {} profiles: {:?}", - migrated.len(), - migrated - ); - } - } - Err(e) => { - eprintln!("Warning: Failed to migrate profiles: {e}"); - } - } - }); - // Set up deep link handler let handle = app.handle().clone(); diff --git a/src-tauri/src/profile/manager.rs b/src-tauri/src/profile/manager.rs index 1bf6a2a..e117b32 100644 --- a/src-tauri/src/profile/manager.rs +++ b/src-tauri/src/profile/manager.rs @@ -908,243 +908,6 @@ impl ProfileManager { Ok(()) } - - // Migrate old profile structure to new UUID-based structure - pub async fn migrate_profiles_to_uuid(&self) -> Result, Box> { - let profiles_dir = self.get_profiles_dir(); - if !profiles_dir.exists() { - return Ok(vec![]); - } - - let mut migrated_profiles = Vec::new(); - - // Scan for old-format profile files (*.json files directly in profiles directory) - for entry in fs::read_dir(&profiles_dir)? { - let entry = entry?; - let path = entry.path(); - - // Look for .json files that are NOT in UUID directories - if path.is_file() && path.extension().is_some_and(|ext| ext == "json") { - let content = fs::read_to_string(&path)?; - - // Try to parse as old profile format (without UUID) - let mut old_profile: serde_json::Value = serde_json::from_str(&content)?; - - // Skip if it already has an id field (already migrated) - if old_profile.get("id").is_some() { - continue; - } - - // Generate new UUID for this profile - let profile_id = uuid::Uuid::new_v4(); - - // Extract profile name before mutating - let profile_name = old_profile["name"] - .as_str() - .unwrap_or("unknown") - .to_string(); - - // Check if there's a running browser process for this profile and kill it - if let Some(process_id_value) = old_profile.get("process_id") { - if let Some(pid) = process_id_value.as_u64() { - let pid = pid as u32; - println!("Found running browser process (PID: {pid}) for profile '{profile_name}' during migration"); - - // Kill the process before migration - if let Err(e) = Self::kill_browser_process_by_pid(pid).await { - println!( - "Warning: Failed to kill browser process (PID: {pid}) during migration: {e}" - ); - // Continue with migration even if kill fails - the process might already be dead - } else { - println!( - "Successfully killed browser process (PID: {pid}) for profile '{profile_name}'" - ); - } - - // Clear the process_id since we killed it - old_profile["process_id"] = serde_json::Value::Null; - } - } - - let snake_case_name = profile_name.to_lowercase().replace(" ", "_"); - let old_profile_dir = profiles_dir.join(&snake_case_name); - - // Create new UUID directory and profile subdirectory - let new_profile_dir = profiles_dir.join(profile_id.to_string()); - let new_profile_data_dir = new_profile_dir.join("profile"); - create_dir_all(&new_profile_dir)?; - create_dir_all(&new_profile_data_dir)?; - - // Now update the profile with UUID (no need to store profile_path anymore) - old_profile["id"] = serde_json::Value::String(profile_id.to_string()); - - // Handle proxy migration - extract proxy to separate storage if it exists - if let Some(proxy_value) = old_profile.get("proxy").cloned() { - if !proxy_value.is_null() { - // Try to deserialize the proxy settings - if let Ok(proxy_settings) = serde_json::from_value::(proxy_value) { - // Create a stored proxy with the profile name (all proxies are now enabled by default) - let proxy_name = format!("{profile_name} Proxy"); - match PROXY_MANAGER.create_stored_proxy(proxy_name.clone(), proxy_settings.clone()) { - Ok(stored_proxy) => { - // Update profile to reference the stored proxy - old_profile["proxy_id"] = serde_json::Value::String(stored_proxy.id); - println!( - "Migrated proxy for profile '{}' to stored proxy '{}'", - profile_name, stored_proxy.name - ); - } - Err(e) => { - println!("Warning: Failed to migrate proxy for profile '{profile_name}': {e}"); - // If creation fails (e.g., name collision), try to find existing proxy with same settings - let existing_proxies = PROXY_MANAGER.get_stored_proxies(); - if let Some(existing_proxy) = existing_proxies.iter().find(|p| { - p.proxy_settings.proxy_type == proxy_settings.proxy_type - && p.proxy_settings.host == proxy_settings.host - && p.proxy_settings.port == proxy_settings.port - && p.proxy_settings.username == proxy_settings.username - && p.proxy_settings.password == proxy_settings.password - }) { - old_profile["proxy_id"] = serde_json::Value::String(existing_proxy.id.clone()); - println!( - "Reused existing proxy '{}' for profile '{}'", - existing_proxy.name, profile_name - ); - } else { - // Try with a different name if the original failed due to name collision - let alt_proxy_name = format!( - "{profile_name} Proxy {}", - &uuid::Uuid::new_v4().to_string()[..8] - ); - match PROXY_MANAGER - .create_stored_proxy(alt_proxy_name.clone(), proxy_settings.clone()) - { - Ok(stored_proxy) => { - old_profile["proxy_id"] = serde_json::Value::String(stored_proxy.id); - println!( - "Migrated proxy for profile '{}' to stored proxy '{}' with fallback name", - profile_name, stored_proxy.name - ); - } - Err(e2) => { - println!("Error: Could not migrate proxy for profile '{profile_name}' even with fallback name: {e2}"); - } - } - } - } - } - } else { - println!( - "Warning: Could not deserialize proxy settings for profile '{profile_name}'" - ); - } - } - } - - // Always remove the old proxy field after migration attempt, whether successful or not - if old_profile - .as_object_mut() - .unwrap() - .remove("proxy") - .is_some() - { - println!("Removed legacy proxy field from profile '{profile_name}'"); - } - - // Move old profile directory contents to new UUID/profile directory if it exists - if old_profile_dir.exists() && old_profile_dir.is_dir() { - // Copy all contents from old directory to new profile subdirectory - for entry in fs::read_dir(&old_profile_dir)? { - let entry = entry?; - let source_path = entry.path(); - let dest_path = new_profile_data_dir.join(entry.file_name()); - - if source_path.is_dir() { - Self::copy_directory_recursive(&source_path, &dest_path)?; - } else { - fs::copy(&source_path, &dest_path)?; - } - } - - // Remove old profile directory - fs::remove_dir_all(&old_profile_dir)?; - println!( - "Migrated profile directory: {} -> {}", - old_profile_dir.display(), - new_profile_data_dir.display() - ); - } - - // Save migrated profile as metadata.json in UUID directory - let metadata_file = new_profile_dir.join("metadata.json"); - let json = serde_json::to_string_pretty(&old_profile)?; - fs::write(&metadata_file, json)?; - - // Remove old profile JSON file - fs::remove_file(&path)?; - - migrated_profiles.push(profile_name.clone()); - println!("Migrated profile '{profile_name}' to UUID: {profile_id}"); - } - } - - if !migrated_profiles.is_empty() { - println!( - "Successfully migrated {} profiles to UUID format", - migrated_profiles.len() - ); - } - - Ok(migrated_profiles) - } - - /// Helper function to kill a browser process by PID only (used during migration) - async fn kill_browser_process_by_pid( - pid: u32, - ) -> Result<(), Box> { - println!("Attempting to kill browser process with PID: {pid} during migration"); - - // Kill the process using platform-specific implementation - #[cfg(target_os = "macos")] - crate::platform_browser::macos::kill_browser_process_impl(pid).await?; - - #[cfg(target_os = "windows")] - crate::platform_browser::windows::kill_browser_process_impl(pid).await?; - - #[cfg(target_os = "linux")] - crate::platform_browser::linux::kill_browser_process_impl(pid).await?; - - #[cfg(not(any(target_os = "macos", target_os = "windows", target_os = "linux")))] - return Err("Unsupported platform".into()); - - println!("Successfully killed browser process with PID: {pid} during migration"); - Ok(()) - } - - /// Recursively copy directory contents - fn copy_directory_recursive( - source: &Path, - destination: &Path, - ) -> Result<(), Box> { - if !destination.exists() { - create_dir_all(destination)?; - } - - for entry in fs::read_dir(source)? { - let entry = entry?; - let source_path = entry.path(); - let dest_path = destination.join(entry.file_name()); - - if source_path.is_dir() { - Self::copy_directory_recursive(&source_path, &dest_path)?; - } else { - fs::copy(&source_path, &dest_path)?; - } - } - - Ok(()) - } } #[cfg(test)] diff --git a/src/app/page.tsx b/src/app/page.tsx index 26248ab..86694b3 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -202,17 +202,6 @@ export default function Home() { ); setProfiles(profileList); - // TODO: remove after a few version bumps, needed to properly display migrated profiles - setTimeout(async () => { - for (let i = 0; i < 10; i++) { - const profiles = await invoke( - "list_browser_profiles", - ); - setProfiles(profiles); - } - await sleep(500); - }, 0); - // Check for updates after loading profiles await checkForUpdates(); await checkMissingBinaries();