mirror of
https://github.com/clash-verge-rev/clash-verge-rev
synced 2025-05-05 03:03:46 +08:00
feat: reorganize service commands and implement logging for service management
This commit is contained in:
parent
5a0eb56f70
commit
81968a579d
@ -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)
|
|
||||||
}
|
|
@ -6,33 +6,33 @@ pub type CmdResult<T = ()> = Result<T, String>;
|
|||||||
// Command modules
|
// Command modules
|
||||||
pub mod app;
|
pub mod app;
|
||||||
pub mod clash;
|
pub mod clash;
|
||||||
pub mod core;
|
pub mod lighteweight;
|
||||||
pub mod media_unlock_checker;
|
pub mod media_unlock_checker;
|
||||||
pub mod network;
|
pub mod network;
|
||||||
pub mod profile;
|
pub mod profile;
|
||||||
pub mod proxy;
|
pub mod proxy;
|
||||||
pub mod runtime;
|
pub mod runtime;
|
||||||
pub mod save_profile;
|
pub mod save_profile;
|
||||||
|
pub mod service;
|
||||||
pub mod system;
|
pub mod system;
|
||||||
pub mod uwp;
|
pub mod uwp;
|
||||||
pub mod validate;
|
pub mod validate;
|
||||||
pub mod verge;
|
pub mod verge;
|
||||||
pub mod webdav;
|
pub mod webdav;
|
||||||
pub mod lighteweight;
|
|
||||||
|
|
||||||
// Re-export all command functions for backwards compatibility
|
// Re-export all command functions for backwards compatibility
|
||||||
pub use app::*;
|
pub use app::*;
|
||||||
pub use clash::*;
|
pub use clash::*;
|
||||||
pub use core::*;
|
pub use lighteweight::*;
|
||||||
pub use media_unlock_checker::*;
|
pub use media_unlock_checker::*;
|
||||||
pub use network::*;
|
pub use network::*;
|
||||||
pub use profile::*;
|
pub use profile::*;
|
||||||
pub use proxy::*;
|
pub use proxy::*;
|
||||||
pub use runtime::*;
|
pub use runtime::*;
|
||||||
pub use save_profile::*;
|
pub use save_profile::*;
|
||||||
|
pub use service::*;
|
||||||
pub use system::*;
|
pub use system::*;
|
||||||
pub use uwp::*;
|
pub use uwp::*;
|
||||||
pub use validate::*;
|
pub use validate::*;
|
||||||
pub use verge::*;
|
pub use verge::*;
|
||||||
pub use webdav::*;
|
pub use webdav::*;
|
||||||
pub use lighteweight::*;
|
|
||||||
|
38
src-tauri/src/cmd/service.rs
Normal file
38
src-tauri/src/cmd/service.rs
Normal 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(())
|
||||||
|
}
|
@ -1,8 +1,7 @@
|
|||||||
use super::CmdResult;
|
use super::CmdResult;
|
||||||
use crate::{
|
use crate::{
|
||||||
core::{self, handle, service, CoreManager},
|
core::{self, handle, CoreManager},
|
||||||
module::sysinfo::PlatformSpecification,
|
module::sysinfo::PlatformSpecification,
|
||||||
wrap_err,
|
|
||||||
};
|
};
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
use std::{
|
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]
|
#[tauri::command]
|
||||||
pub fn get_app_uptime() -> CmdResult<i64> {
|
pub fn get_app_uptime() -> CmdResult<i64> {
|
||||||
|
@ -511,13 +511,6 @@ impl CoreManager {
|
|||||||
Ok(())
|
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> {
|
pub async fn change_core(&self, clash_core: Option<String>) -> Result<(), String> {
|
||||||
if clash_core.is_none() {
|
if clash_core.is_none() {
|
||||||
|
@ -151,10 +151,13 @@ pub fn run() {
|
|||||||
cmd::restart_app,
|
cmd::restart_app,
|
||||||
// 添加新的命令
|
// 添加新的命令
|
||||||
cmd::get_running_mode,
|
cmd::get_running_mode,
|
||||||
cmd::install_service,
|
|
||||||
cmd::repair_service,
|
|
||||||
cmd::get_app_uptime,
|
cmd::get_app_uptime,
|
||||||
cmd::get_auto_launch_status,
|
cmd::get_auto_launch_status,
|
||||||
|
// service 管理
|
||||||
|
cmd::install_service,
|
||||||
|
cmd::uninstall_service,
|
||||||
|
cmd::reinstall_service,
|
||||||
|
cmd::repair_service,
|
||||||
// clash
|
// clash
|
||||||
cmd::get_clash_info,
|
cmd::get_clash_info,
|
||||||
cmd::patch_clash_config,
|
cmd::patch_clash_config,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user