mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-11-09 03:42:06 +08:00
refactor(tray): change menu text storage to use Arc<str> for improved performance refactor(service): utilize SmartString for error messages to enhance memory management
46 lines
1.3 KiB
Rust
46 lines
1.3 KiB
Rust
use super::{CmdResult, StringifyErr};
|
|
use crate::{
|
|
core::service::{self, SERVICE_MANAGER, ServiceStatus},
|
|
utils::i18n::t,
|
|
};
|
|
use smartstring::SmartString;
|
|
|
|
async fn execute_service_operation_sync(status: ServiceStatus, op_type: &str) -> CmdResult {
|
|
if let Err(e) = SERVICE_MANAGER
|
|
.lock()
|
|
.await
|
|
.handle_service_status(&status)
|
|
.await
|
|
{
|
|
let emsg = format!("{} Service failed: {}", op_type, e);
|
|
return Err(SmartString::from(&*t(emsg.as_str()).await));
|
|
}
|
|
Ok(())
|
|
}
|
|
|
|
#[tauri::command]
|
|
pub async fn install_service() -> CmdResult {
|
|
execute_service_operation_sync(ServiceStatus::InstallRequired, "Install").await
|
|
}
|
|
|
|
#[tauri::command]
|
|
pub async fn uninstall_service() -> CmdResult {
|
|
execute_service_operation_sync(ServiceStatus::UninstallRequired, "Uninstall").await
|
|
}
|
|
|
|
#[tauri::command]
|
|
pub async fn reinstall_service() -> CmdResult {
|
|
execute_service_operation_sync(ServiceStatus::ReinstallRequired, "Reinstall").await
|
|
}
|
|
|
|
#[tauri::command]
|
|
pub async fn repair_service() -> CmdResult {
|
|
execute_service_operation_sync(ServiceStatus::ForceReinstallRequired, "Repair").await
|
|
}
|
|
|
|
#[tauri::command]
|
|
pub async fn is_service_available() -> CmdResult<bool> {
|
|
service::is_service_available().await.stringify_err()?;
|
|
Ok(true)
|
|
}
|