From ee497cc65db752726abb30af53e2583e18640340 Mon Sep 17 00:00:00 2001 From: Tunglies <77394545+Tunglies@users.noreply.github.com> Date: Sun, 6 Sep 2026 04:21:57 +0800 Subject: [PATCH] refactor(ipc): remove unused commands --- .../src/commands.rs | 6 ---- src-tauri/src/cmd/app.rs | 11 ------- src-tauri/src/cmd/clash.rs | 25 -------------- src-tauri/src/cmd/lightweight.rs | 6 ---- src-tauri/src/cmd/mod.rs | 1 - src-tauri/src/cmd/runtime.rs | 7 +--- src-tauri/src/cmd/validate.rs | 33 +------------------ src-tauri/src/core/autostart.rs | 27 --------------- src-tauri/src/lib.rs | 9 ----- src-tauri/src/utils/schtasks.rs | 8 ----- 10 files changed, 2 insertions(+), 131 deletions(-) diff --git a/crates/tauri-plugin-clash-verge-sysinfo/src/commands.rs b/crates/tauri-plugin-clash-verge-sysinfo/src/commands.rs index 419c83098..0c2a8f56c 100644 --- a/crates/tauri-plugin-clash-verge-sysinfo/src/commands.rs +++ b/crates/tauri-plugin-clash-verge-sysinfo/src/commands.rs @@ -42,12 +42,6 @@ pub fn get_app_uptime(state: State<'_, RwLock>) -> Result Ok(state.inner().read().appinfo.app_startup_time.elapsed().as_millis()) } -/// 检查应用是否以管理员身份运行 -#[command] -pub fn app_is_admin(state: State<'_, RwLock>) -> Result { - Ok(state.inner().read().appinfo.app_is_admin) -} - #[command] pub fn export_diagnostic_info( app_handle: AppHandle, diff --git a/src-tauri/src/cmd/app.rs b/src-tauri/src/cmd/app.rs index 885759a3c..635c8f959 100644 --- a/src-tauri/src/cmd/app.rs +++ b/src-tauri/src/cmd/app.rs @@ -1,5 +1,4 @@ use super::CmdResult; -use crate::core::autostart; use crate::{cmd::StringifyErr as _, feat, utils::dirs}; use smartstring::alias::String; use tauri::{AppHandle, Manager as _}; @@ -45,22 +44,12 @@ pub async fn restart_app() -> CmdResult<()> { Ok(()) } -#[tauri::command] -pub fn get_portable_flag() -> bool { - *dirs::PORTABLE_FLAG.get().unwrap_or(&false) -} - #[tauri::command] pub fn get_app_dir() -> CmdResult { let app_home_dir = dirs::app_home_dir().stringify_err()?.to_string_lossy().into(); Ok(app_home_dir) } -#[tauri::command] -pub fn get_auto_launch_status() -> CmdResult { - autostart::get_launch_status().stringify_err() -} - #[tauri::command] pub async fn download_icon_cache(url: String, name: String) -> CmdResult { feat::download_icon_cache(url, name).await diff --git a/src-tauri/src/cmd/clash.rs b/src-tauri/src/cmd/clash.rs index e16046540..16f908e72 100644 --- a/src-tauri/src/cmd/clash.rs +++ b/src-tauri/src/cmd/clash.rs @@ -80,31 +80,6 @@ pub async fn change_clash_core(clash_core: String) -> CmdResult CmdResult { - let result = CoreManager::global() - .start_core() - .await - .map_err(|error| proxy_aware_coded_error(&error, "CORE_START_FAILED")); - if result.is_ok() { - handle::Handle::refresh_clash(); - } - result -} - -#[tauri::command] -pub async fn stop_core() -> CmdResult { - logging_error!(Type::Core, profiles_save_file_safe().await); - let result = CoreManager::global() - .stop_core() - .await - .map_err(|error| proxy_aware_coded_error(&error, "CORE_STOP_FAILED")); - if result.is_ok() { - handle::Handle::refresh_clash(); - } - result -} - #[tauri::command] pub async fn restart_core() -> CmdResult { logging_error!(Type::Core, profiles_save_file_safe().await); diff --git a/src-tauri/src/cmd/lightweight.rs b/src-tauri/src/cmd/lightweight.rs index a3ba51bfb..470254969 100644 --- a/src-tauri/src/cmd/lightweight.rs +++ b/src-tauri/src/cmd/lightweight.rs @@ -7,9 +7,3 @@ pub async fn entry_lightweight_mode() -> CmdResult { lightweight::entry_lightweight_mode().await; Ok(()) } - -#[tauri::command] -pub async fn exit_lightweight_mode() -> CmdResult { - lightweight::exit_lightweight_mode().await; - Ok(()) -} diff --git a/src-tauri/src/cmd/mod.rs b/src-tauri/src/cmd/mod.rs index a633db8d4..a8c6bca68 100644 --- a/src-tauri/src/cmd/mod.rs +++ b/src-tauri/src/cmd/mod.rs @@ -125,7 +125,6 @@ pub use save_profile::*; pub use service::*; pub use system::*; pub use uwp::*; -pub use validate::*; pub use verge::*; pub use webdav::*; diff --git a/src-tauri/src/cmd/runtime.rs b/src-tauri/src/cmd/runtime.rs index 644a98b2b..24cac919a 100644 --- a/src-tauri/src/cmd/runtime.rs +++ b/src-tauri/src/cmd/runtime.rs @@ -4,7 +4,7 @@ use anyhow::{Context as _, anyhow}; use clash_verge_logging::{Type, logging}; use serde_yaml_ng::Mapping; use smartstring::alias::String; -use std::collections::{HashMap, HashSet}; +use std::collections::HashMap; #[tauri::command] pub async fn get_runtime_config() -> CmdResult> { @@ -27,11 +27,6 @@ pub async fn get_runtime_yaml() -> CmdResult { .stringify_err() } -#[tauri::command] -pub async fn get_runtime_exists() -> CmdResult> { - Ok(Config::runtime().await.latest_arc().exists_keys.clone()) -} - #[tauri::command] pub async fn get_runtime_logs() -> CmdResult>> { Ok(Config::runtime().await.latest_arc().chain_logs.clone()) diff --git a/src-tauri/src/cmd/validate.rs b/src-tauri/src/cmd/validate.rs index b17adbe82..138f597d8 100644 --- a/src-tauri/src/cmd/validate.rs +++ b/src-tauri/src/cmd/validate.rs @@ -1,10 +1,8 @@ -use super::CmdResult; use crate::core::{ handle, - validate::{CoreConfigValidator, ValidationErrorKind, ValidationOutcome}, + validate::{ValidationErrorKind, ValidationOutcome}, }; use clash_verge_logging::{Type, logging}; -use smartstring::alias::String; #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum ValidationNoticeTarget { @@ -13,35 +11,6 @@ pub enum ValidationNoticeTarget { Script, } -/// 发送脚本验证通知消息 -#[tauri::command] -pub async fn script_validate_notice(status: String, msg: String) -> CmdResult { - handle::Handle::notice_message(status.as_str(), msg.as_str()); - Ok(()) -} - -/// 验证指定脚本文件 -#[tauri::command] -pub async fn validate_script_file(file_path: String) -> CmdResult { - logging!(info, Type::Config, "验证脚本文件: {}", file_path); - - match CoreConfigValidator::validate_config_file_outcome(&file_path, None).await { - Ok(outcome) => { - handle_validation_notice(&outcome, ValidationNoticeTarget::Script, "脚本文件"); - Ok(outcome) - } - Err(e) => { - let error_msg = e.to_string(); - logging!(error, Type::Config, "验证脚本文件过程发生错误: {}", error_msg); - handle::Handle::notice_message("config_validate::process_terminated", &error_msg); - Ok(ValidationOutcome::invalid( - ValidationErrorKind::ProcessTerminated, - error_msg, - )) - } - } -} - const fn notice_key(kind: ValidationErrorKind, target: ValidationNoticeTarget) -> &'static str { match kind { ValidationErrorKind::FileMissing => "config_validate::file_not_found", diff --git a/src-tauri/src/core/autostart.rs b/src-tauri/src/core/autostart.rs index bd2ddb8c4..7b01a9fbf 100644 --- a/src-tauri/src/core/autostart.rs +++ b/src-tauri/src/core/autostart.rs @@ -34,30 +34,3 @@ pub async fn update_launch() -> Result<()> { Ok(()) } - -pub fn get_launch_status() -> Result { - #[cfg(target_os = "windows")] - { - let enabled = schtasks::is_auto_launch_enabled(); - if let Ok(status) = enabled { - logging!(info, Type::System, "Auto-launch status (scheduled task): {status}"); - } - enabled - } - - #[cfg(not(target_os = "windows"))] - { - let app_handle = Handle::app_handle(); - let autostart_manager = app_handle.autolaunch(); - match autostart_manager.is_enabled() { - Ok(status) => { - logging!(info, Type::System, "Auto-launch status: {status}"); - Ok(status) - } - Err(e) => { - logging!(error, Type::System, "Failed to get auto-launch status: {e}"); - Err(anyhow::anyhow!("Failed to get auto-launch status: {}", e)) - } - } - } -} diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 589272772..6b55f24df 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -120,7 +120,6 @@ mod app_init { tauri::generate_handler![ tauri_plugin_clash_verge_sysinfo::commands::get_system_info, tauri_plugin_clash_verge_sysinfo::commands::get_app_uptime, - tauri_plugin_clash_verge_sysinfo::commands::app_is_admin, tauri_plugin_clash_verge_sysinfo::commands::export_diagnostic_info, cmd::probe_listener, cmd::save_proxy_ports, @@ -130,19 +129,14 @@ mod app_init { cmd::open_app_dir, cmd::open_logs_dir, cmd::open_core_dir, - cmd::get_portable_flag, cmd::get_network_interfaces, cmd::get_system_hostname, cmd::restart_app, - cmd::start_core, - cmd::stop_core, cmd::restart_core, cmd::upgrade_clash_core, cmd::get_runtime_state, cmd::get_pending_failures, - cmd::get_auto_launch_status, cmd::entry_lightweight_mode, - cmd::exit_lightweight_mode, cmd::install_service, cmd::uninstall_service, cmd::reinstall_service, @@ -156,7 +150,6 @@ mod app_init { cmd::get_runtime_config, cmd::get_proxy_view, cmd::get_runtime_yaml, - cmd::get_runtime_exists, cmd::get_runtime_logs, cmd::get_runtime_proxy_chain_config, cmd::update_proxy_chain_config_in_runtime, @@ -192,8 +185,6 @@ mod app_init { cmd::read_profile_file, cmd::save_profile_file, cmd::get_next_update_time, - cmd::script_validate_notice, - cmd::validate_script_file, cmd::create_local_backup, cmd::list_local_backup, cmd::delete_local_backup, diff --git a/src-tauri/src/utils/schtasks.rs b/src-tauri/src/utils/schtasks.rs index 87edbaa70..ee09040a4 100644 --- a/src-tauri/src/utils/schtasks.rs +++ b/src-tauri/src/utils/schtasks.rs @@ -373,11 +373,3 @@ pub async fn set_auto_launch(is_enable: bool, is_admin: bool) -> Result<()> { Ok(()) } - -pub fn is_auto_launch_enabled() -> Result { - if is_task_enabled(TaskMode::Admin)? { - return Ok(true); - } - - is_task_enabled(TaskMode::User) -}