feat: reorganize service commands and implement logging for service management

This commit is contained in:
Tunglies 2025-03-26 15:02:08 +08:00
parent 5a0eb56f70
commit 81968a579d
6 changed files with 48 additions and 29 deletions

View File

@ -1,8 +0,0 @@
use super::CmdResult;
use crate::{core::CoreManager, wrap_err};
/// 修复系统服务
#[tauri::command]
pub async fn repair_service() -> CmdResult {
wrap_err!(CoreManager::global().repair_service().await)
}

View File

@ -6,33 +6,33 @@ pub type CmdResult<T = ()> = Result<T, String>;
// Command modules
pub mod app;
pub mod clash;
pub mod core;
pub mod lighteweight;
pub mod media_unlock_checker;
pub mod network;
pub mod profile;
pub mod proxy;
pub mod runtime;
pub mod save_profile;
pub mod service;
pub mod system;
pub mod uwp;
pub mod validate;
pub mod verge;
pub mod webdav;
pub mod lighteweight;
// Re-export all command functions for backwards compatibility
pub use app::*;
pub use clash::*;
pub use core::*;
pub use lighteweight::*;
pub use media_unlock_checker::*;
pub use network::*;
pub use profile::*;
pub use proxy::*;
pub use runtime::*;
pub use save_profile::*;
pub use service::*;
pub use system::*;
pub use uwp::*;
pub use validate::*;
pub use verge::*;
pub use webdav::*;
pub use lighteweight::*;

View File

@ -0,0 +1,38 @@
use super::CmdResult;
use crate::{
core::{service, CoreManager},
logging_error,
utils::logging::Type,
};
#[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(())
}
#[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(())
}
#[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(())
}
#[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(())
}

View File

@ -1,8 +1,7 @@
use super::CmdResult;
use crate::{
core::{self, handle, service, CoreManager},
core::{self, handle, CoreManager},
module::sysinfo::PlatformSpecification,
wrap_err,
};
use once_cell::sync::Lazy;
use std::{
@ -52,12 +51,6 @@ pub async fn get_running_mode() -> Result<String, String> {
}
}
/// 安装/重装系统服务
#[tauri::command]
pub async fn install_service() -> CmdResult {
wrap_err!(service::reinstall_service().await)
}
/// 获取应用的运行时间(毫秒)
#[tauri::command]
pub fn get_app_uptime() -> CmdResult<i64> {

View File

@ -511,13 +511,6 @@ impl CoreManager {
Ok(())
}
/// 强制重新安装服务供UI调用用户主动修复服务
pub async fn repair_service(&self) -> Result<()> {
service::force_reinstall_service().await?;
self.restart_core().await?;
Ok(())
}
/// 切换核心
pub async fn change_core(&self, clash_core: Option<String>) -> Result<(), String> {
if clash_core.is_none() {

View File

@ -151,10 +151,13 @@ pub fn run() {
cmd::restart_app,
// 添加新的命令
cmd::get_running_mode,
cmd::install_service,
cmd::repair_service,
cmd::get_app_uptime,
cmd::get_auto_launch_status,
// service 管理
cmd::install_service,
cmd::uninstall_service,
cmd::reinstall_service,
cmd::repair_service,
// clash
cmd::get_clash_info,
cmd::patch_clash_config,