Files
clash-verge-rev/src-tauri/src/cmd/service.rs
T
Tunglies e8e16f7d57 refactor(logging): replace log_err! with structured logging_error! calls
refactor(cm-service): better error handling from Backend to Frontend
2025-03-28 03:39:34 +08:00

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(e) = service_op.await {
let emsg = format!("{} {} failed: {:?}", op_type, "service", e);
logging_error!(Type::Service, true, "{}", emsg);
return Err(emsg);
}
if let Err(e) = CoreManager::global().restart_core().await {
let emsg = format!("{} {} failed: {:?}", op_type, "core", e);
logging_error!(Type::Core, true, "{}", emsg);
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
}