diff --git a/mediarepo-api/src/tauri_plugin/commands/repo.rs b/mediarepo-api/src/tauri_plugin/commands/repo.rs index 86fbb6c..cea86b0 100644 --- a/mediarepo-api/src/tauri_plugin/commands/repo.rs +++ b/mediarepo-api/src/tauri_plugin/commands/repo.rs @@ -140,16 +140,7 @@ pub async fn select_repository( .path .clone() .ok_or_else(|| PluginError::from("Missing repo path or address in config."))?; - let address_path = PathBuf::from(path).join(".tcp"); - let mut address = String::from("127.0.0.1:2400"); - for _ in 0..10 { - if address_path.exists() { - address = fs::read_to_string(address_path).await?; - break; - } - tokio::time::sleep(Duration::from_millis(250)).await; - } - address + get_repo_address(path).await? }; let client = ApiClient::connect(address).await?; api_state.set_api(client).await; @@ -168,6 +159,27 @@ pub async fn select_repository( Ok(()) } +async fn get_repo_address(path: String) -> PluginResult { + let tcp_path = PathBuf::from(&path).join("repo.tcp"); + let socket_path = PathBuf::from(&path).join("repo.socket"); + + let mut address = String::from("127.0.0.1:2400"); + for _ in 0..10 { + #[cfg(unix)] + if socket_path.exists() { + address = socket_path.to_str().unwrap().to_string(); + break; + } + if tcp_path.exists() { + address = fs::read_to_string(tcp_path).await?; + break; + } + tokio::time::sleep(Duration::from_millis(250)).await; + } + + Ok(address) +} + async fn close_selected_repository(app_state: &AppAccess<'_>) -> PluginResult<()> { if let Some(path) = app_state .active_repo