Add support for unix sockets

Signed-off-by: trivernis <trivernis@protonmail.com>
pull/4/head
trivernis 3 years ago
parent f397ad858f
commit 89bf781bd9

@ -140,16 +140,7 @@ pub async fn select_repository(
.path .path
.clone() .clone()
.ok_or_else(|| PluginError::from("Missing repo path or address in config."))?; .ok_or_else(|| PluginError::from("Missing repo path or address in config."))?;
let address_path = PathBuf::from(path).join(".tcp"); get_repo_address(path).await?
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
}; };
let client = ApiClient::connect(address).await?; let client = ApiClient::connect(address).await?;
api_state.set_api(client).await; api_state.set_api(client).await;
@ -168,6 +159,27 @@ pub async fn select_repository(
Ok(()) Ok(())
} }
async fn get_repo_address(path: String) -> PluginResult<String> {
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<()> { async fn close_selected_repository(app_state: &AppAccess<'_>) -> PluginResult<()> {
if let Some(path) = app_state if let Some(path) = app_state
.active_repo .active_repo

Loading…
Cancel
Save