|
|
@ -1,6 +1,7 @@
|
|
|
|
use crate::client_api::ApiClient;
|
|
|
|
|
|
|
|
use crate::tauri_plugin::commands::AppAccess;
|
|
|
|
use crate::tauri_plugin::commands::AppAccess;
|
|
|
|
use crate::tauri_plugin::error::PluginResult;
|
|
|
|
use crate::tauri_plugin::error::PluginResult;
|
|
|
|
|
|
|
|
use rmp_ipc::prelude::IPCResult;
|
|
|
|
|
|
|
|
use rmp_ipc::IPCBuilder;
|
|
|
|
|
|
|
|
|
|
|
|
#[tauri::command]
|
|
|
|
#[tauri::command]
|
|
|
|
pub async fn init_repository(app_state: AppAccess<'_>, repo_path: String) -> PluginResult<()> {
|
|
|
|
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]
|
|
|
|
#[tauri::command]
|
|
|
|
pub async fn check_daemon_running(address: String) -> PluginResult<bool> {
|
|
|
|
pub async fn check_daemon_running(address: String) -> PluginResult<bool> {
|
|
|
|
if let Ok(api_client) = ApiClient::connect(&address).await {
|
|
|
|
let connect_result = try_connect_daemon(address).await;
|
|
|
|
Ok(api_client.info().await.is_ok())
|
|
|
|
|
|
|
|
} else {
|
|
|
|
Ok(connect_result.is_ok())
|
|
|
|
Ok(false)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|