mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-01-29 08:45:41 +08:00
refactor(logging): replace log_err! with structured logging_error! calls
refactor(cm-service): better error handling from Backend to Frontend
This commit is contained in:
@@ -5,34 +5,39 @@ use crate::{
|
||||
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 {
|
||||
logging_error!(Type::Service, true, service::install_service().await);
|
||||
logging_error!(Type::Core, true, CoreManager::global().restart_core().await);
|
||||
Ok(())
|
||||
execute_service_operation(service::install_service(), "Install").await
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn uninstall_service() -> CmdResult {
|
||||
logging_error!(Type::Service, true, service::uninstall_service().await);
|
||||
logging_error!(Type::Core, true, CoreManager::global().restart_core().await);
|
||||
Ok(())
|
||||
execute_service_operation(service::uninstall_service(), "Uninstall").await
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn reinstall_service() -> CmdResult {
|
||||
logging_error!(Type::Service, true, service::reinstall_service().await);
|
||||
logging_error!(Type::Core, true, CoreManager::global().restart_core().await);
|
||||
Ok(())
|
||||
execute_service_operation(service::reinstall_service(), "Reinstall").await
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn repair_service() -> CmdResult {
|
||||
logging_error!(
|
||||
Type::Service,
|
||||
true,
|
||||
service::force_reinstall_service().await
|
||||
);
|
||||
logging_error!(Type::Core, true, CoreManager::global().restart_core().await);
|
||||
Ok(())
|
||||
execute_service_operation(service::force_reinstall_service(), "Repair").await
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user