From b4a528e2bb33da2a3ef2e76fc254f1f127d02638 Mon Sep 17 00:00:00 2001 From: trivernis Date: Tue, 2 Nov 2021 20:37:37 +0100 Subject: [PATCH] Change client online checking to use a non-pooled approach Signed-off-by: trivernis --- .../src/tauri_plugin/commands/daemon.rs | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/mediarepo-api/src/tauri_plugin/commands/daemon.rs b/mediarepo-api/src/tauri_plugin/commands/daemon.rs index 9a6d658..bf96dd7 100644 --- a/mediarepo-api/src/tauri_plugin/commands/daemon.rs +++ b/mediarepo-api/src/tauri_plugin/commands/daemon.rs @@ -1,6 +1,7 @@ -use crate::client_api::ApiClient; use crate::tauri_plugin::commands::AppAccess; use crate::tauri_plugin::error::PluginResult; +use rmp_ipc::prelude::IPCResult; +use rmp_ipc::IPCBuilder; #[tauri::command] pub async fn init_repository(app_state: AppAccess<'_>, repo_path: String) -> PluginResult<()> { @@ -28,9 +29,18 @@ pub async fn stop_daemon(app_state: AppAccess<'_>, repo_path: String) -> PluginR #[tauri::command] pub async fn check_daemon_running(address: String) -> PluginResult { - if let Ok(api_client) = ApiClient::connect(&address).await { - Ok(api_client.info().await.is_ok()) - } else { - Ok(false) - } + let connect_result = try_connect_daemon(address).await; + + Ok(connect_result.is_ok()) +} + +async fn try_connect_daemon(address: String) -> IPCResult<()> { + let ctx = IPCBuilder::new().address(address).build_client().await?; + ctx.emitter + .emit("info", ()) + .await? + .await_reply(&ctx) + .await?; + ctx.stop().await?; + Ok(()) }