44 lines
1.3 KiB
Rust

use super::CmdResult;
use crate::{
core::{service, CoreManager},
logging_error,
utils::logging::Type,
};
async fn execute_service_operation(
service_op: impl std::future::Future<Output = Result<(), impl ToString + std::fmt::Debug>>,
op_type: &str,
) -> CmdResult {
if let Err(_) = service_op.await {
let emsg = format!("{} {} failed", op_type, "service");
// logging_error!(Type::Service, true, "{:?}", e);
return Err(emsg);
}
if let Err(_) = CoreManager::global().restart_core().await {
let emsg = format!("{} {} failed", op_type, "core");
// logging_error!(Type::Core, true, "{:?}", e);
return Err(emsg);
}
Ok(())
}
#[tauri::command]
pub async fn install_service() -> CmdResult {
execute_service_operation(service::install_service(), "Install").await
}
#[tauri::command]
pub async fn uninstall_service() -> CmdResult {
execute_service_operation(service::uninstall_service(), "Uninstall").await
}
#[tauri::command]
pub async fn reinstall_service() -> CmdResult {
execute_service_operation(service::reinstall_service(), "Reinstall").await
}
#[tauri::command]
pub async fn repair_service() -> CmdResult {
execute_service_operation(service::force_reinstall_service(), "Repair").await
}