mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-01-29 17:15:38 +08:00
Refactor logging macros to remove print control parameter
- Updated logging macros to eliminate the boolean parameter for print control, simplifying the logging calls throughout the codebase. - Adjusted all logging calls in various modules (lib.rs, lightweight.rs, help.rs, init.rs, logging.rs, resolve/mod.rs, resolve/scheme.rs, resolve/ui.rs, resolve/window.rs, server.rs, singleton.rs, window_manager.rs) to reflect the new macro structure. - Ensured consistent logging behavior across the application by standardizing the logging format.
This commit is contained in:
@@ -97,7 +97,6 @@ impl CoreManager {
|
||||
logging!(
|
||||
warn,
|
||||
Type::Config,
|
||||
true,
|
||||
"无法读取文件以检测类型: {}, 错误: {}",
|
||||
path,
|
||||
err
|
||||
@@ -155,7 +154,6 @@ impl CoreManager {
|
||||
logging!(
|
||||
debug,
|
||||
Type::Config,
|
||||
true,
|
||||
"无法确定文件类型,默认当作YAML处理: {}",
|
||||
path
|
||||
);
|
||||
@@ -179,7 +177,7 @@ impl CoreManager {
|
||||
}
|
||||
/// 验证运行时配置
|
||||
pub async fn validate_config(&self) -> Result<(bool, String)> {
|
||||
logging!(info, Type::Config, true, "生成临时配置文件用于验证");
|
||||
logging!(info, Type::Config, "生成临时配置文件用于验证");
|
||||
let config_path = Config::generate_file(ConfigType::Check).await?;
|
||||
let config_path = dirs::path_to_str(&config_path)?;
|
||||
self.validate_config_internal(config_path).await
|
||||
@@ -192,7 +190,7 @@ impl CoreManager {
|
||||
) -> Result<(bool, String)> {
|
||||
// 检查程序是否正在退出,如果是则跳过验证
|
||||
if handle::Handle::global().is_exiting() {
|
||||
logging!(info, Type::Core, true, "应用正在退出,跳过验证");
|
||||
logging!(info, Type::Core, "应用正在退出,跳过验证");
|
||||
return Ok((true, String::new()));
|
||||
}
|
||||
|
||||
@@ -208,7 +206,6 @@ impl CoreManager {
|
||||
logging!(
|
||||
info,
|
||||
Type::Config,
|
||||
true,
|
||||
"检测到Merge文件,仅进行语法检查: {}",
|
||||
config_path
|
||||
);
|
||||
@@ -226,7 +223,6 @@ impl CoreManager {
|
||||
logging!(
|
||||
warn,
|
||||
Type::Config,
|
||||
true,
|
||||
"无法确定文件类型: {}, 错误: {}",
|
||||
config_path,
|
||||
err
|
||||
@@ -240,7 +236,6 @@ impl CoreManager {
|
||||
logging!(
|
||||
info,
|
||||
Type::Config,
|
||||
true,
|
||||
"检测到脚本文件,使用JavaScript验证: {}",
|
||||
config_path
|
||||
);
|
||||
@@ -251,7 +246,6 @@ impl CoreManager {
|
||||
logging!(
|
||||
info,
|
||||
Type::Config,
|
||||
true,
|
||||
"使用Clash内核验证配置文件: {}",
|
||||
config_path
|
||||
);
|
||||
@@ -261,25 +255,19 @@ impl CoreManager {
|
||||
async fn validate_config_internal(&self, config_path: &str) -> Result<(bool, String)> {
|
||||
// 检查程序是否正在退出,如果是则跳过验证
|
||||
if handle::Handle::global().is_exiting() {
|
||||
logging!(info, Type::Core, true, "应用正在退出,跳过验证");
|
||||
logging!(info, Type::Core, "应用正在退出,跳过验证");
|
||||
return Ok((true, String::new()));
|
||||
}
|
||||
|
||||
logging!(
|
||||
info,
|
||||
Type::Config,
|
||||
true,
|
||||
"开始验证配置文件: {}",
|
||||
config_path
|
||||
);
|
||||
logging!(info, Type::Config, "开始验证配置文件: {}", config_path);
|
||||
|
||||
let clash_core = Config::verge().await.latest_ref().get_valid_clash_core();
|
||||
logging!(info, Type::Config, true, "使用内核: {}", clash_core);
|
||||
logging!(info, Type::Config, "使用内核: {}", clash_core);
|
||||
|
||||
let app_handle = handle::Handle::app_handle();
|
||||
let app_dir = dirs::app_home_dir()?;
|
||||
let app_dir_str = dirs::path_to_str(&app_dir)?;
|
||||
logging!(info, Type::Config, true, "验证目录: {}", app_dir_str);
|
||||
logging!(info, Type::Config, "验证目录: {}", app_dir_str);
|
||||
|
||||
// 使用子进程运行clash验证配置
|
||||
let output = app_handle
|
||||
@@ -297,14 +285,14 @@ impl CoreManager {
|
||||
let has_error =
|
||||
!output.status.success() || error_keywords.iter().any(|&kw| stderr.contains(kw));
|
||||
|
||||
logging!(info, Type::Config, true, "-------- 验证结果 --------");
|
||||
logging!(info, Type::Config, "-------- 验证结果 --------");
|
||||
|
||||
if !stderr.is_empty() {
|
||||
logging!(info, Type::Config, true, "stderr输出:\n{}", stderr);
|
||||
logging!(info, Type::Config, "stderr输出:\n{}", stderr);
|
||||
}
|
||||
|
||||
if has_error {
|
||||
logging!(info, Type::Config, true, "发现错误,开始处理错误信息");
|
||||
logging!(info, Type::Config, "发现错误,开始处理错误信息");
|
||||
let error_msg = if !stdout.is_empty() {
|
||||
stdout.to_string()
|
||||
} else if !stderr.is_empty() {
|
||||
@@ -315,38 +303,38 @@ impl CoreManager {
|
||||
"验证进程被终止".to_string()
|
||||
};
|
||||
|
||||
logging!(info, Type::Config, true, "-------- 验证结束 --------");
|
||||
logging!(info, Type::Config, "-------- 验证结束 --------");
|
||||
Ok((false, error_msg)) // 返回错误消息给调用者处理
|
||||
} else {
|
||||
logging!(info, Type::Config, true, "验证成功");
|
||||
logging!(info, Type::Config, true, "-------- 验证结束 --------");
|
||||
logging!(info, Type::Config, "验证成功");
|
||||
logging!(info, Type::Config, "-------- 验证结束 --------");
|
||||
Ok((true, String::new()))
|
||||
}
|
||||
}
|
||||
/// 只进行文件语法检查,不进行完整验证
|
||||
fn validate_file_syntax(&self, config_path: &str) -> Result<(bool, String)> {
|
||||
logging!(info, Type::Config, true, "开始检查文件: {}", config_path);
|
||||
logging!(info, Type::Config, "开始检查文件: {}", config_path);
|
||||
|
||||
// 读取文件内容
|
||||
let content = match std::fs::read_to_string(config_path) {
|
||||
Ok(content) => content,
|
||||
Err(err) => {
|
||||
let error_msg = format!("Failed to read file: {err}");
|
||||
logging!(error, Type::Config, true, "无法读取文件: {}", error_msg);
|
||||
logging!(error, Type::Config, "无法读取文件: {}", error_msg);
|
||||
return Ok((false, error_msg));
|
||||
}
|
||||
};
|
||||
// 对YAML文件尝试解析,只检查语法正确性
|
||||
logging!(info, Type::Config, true, "进行YAML语法检查");
|
||||
logging!(info, Type::Config, "进行YAML语法检查");
|
||||
match serde_yaml_ng::from_str::<serde_yaml_ng::Value>(&content) {
|
||||
Ok(_) => {
|
||||
logging!(info, Type::Config, true, "YAML语法检查通过");
|
||||
logging!(info, Type::Config, "YAML语法检查通过");
|
||||
Ok((true, String::new()))
|
||||
}
|
||||
Err(err) => {
|
||||
// 使用标准化的前缀,以便错误处理函数能正确识别
|
||||
let error_msg = format!("YAML syntax error: {err}");
|
||||
logging!(error, Type::Config, true, "YAML语法错误: {}", error_msg);
|
||||
logging!(error, Type::Config, "YAML语法错误: {}", error_msg);
|
||||
Ok((false, error_msg))
|
||||
}
|
||||
}
|
||||
@@ -358,13 +346,13 @@ impl CoreManager {
|
||||
Ok(content) => content,
|
||||
Err(err) => {
|
||||
let error_msg = format!("Failed to read script file: {err}");
|
||||
logging!(warn, Type::Config, true, "脚本语法错误: {}", err);
|
||||
logging!(warn, Type::Config, "脚本语法错误: {}", err);
|
||||
//handle::Handle::notice_message("config_validate::script_syntax_error", &error_msg);
|
||||
return Ok((false, error_msg));
|
||||
}
|
||||
};
|
||||
|
||||
logging!(debug, Type::Config, true, "验证脚本文件: {}", path);
|
||||
logging!(debug, Type::Config, "验证脚本文件: {}", path);
|
||||
|
||||
// 使用boa引擎进行基本语法检查
|
||||
use boa_engine::{Context, Source};
|
||||
@@ -374,7 +362,7 @@ impl CoreManager {
|
||||
|
||||
match result {
|
||||
Ok(_) => {
|
||||
logging!(debug, Type::Config, true, "脚本语法验证通过: {}", path);
|
||||
logging!(debug, Type::Config, "脚本语法验证通过: {}", path);
|
||||
|
||||
// 检查脚本是否包含main函数
|
||||
if !content.contains("function main")
|
||||
@@ -382,7 +370,7 @@ impl CoreManager {
|
||||
&& !content.contains("let main")
|
||||
{
|
||||
let error_msg = "Script must contain a main function";
|
||||
logging!(warn, Type::Config, true, "脚本缺少main函数: {}", path);
|
||||
logging!(warn, Type::Config, "脚本缺少main函数: {}", path);
|
||||
//handle::Handle::notice_message("config_validate::script_missing_main", error_msg);
|
||||
return Ok((false, error_msg.to_string()));
|
||||
}
|
||||
@@ -391,7 +379,7 @@ impl CoreManager {
|
||||
}
|
||||
Err(err) => {
|
||||
let error_msg = format!("Script syntax error: {err}");
|
||||
logging!(warn, Type::Config, true, "脚本语法错误: {}", err);
|
||||
logging!(warn, Type::Config, "脚本语法错误: {}", err);
|
||||
//handle::Handle::notice_message("config_validate::script_syntax_error", &error_msg);
|
||||
Ok((false, error_msg))
|
||||
}
|
||||
@@ -401,30 +389,30 @@ impl CoreManager {
|
||||
pub async fn update_config(&self) -> Result<(bool, String)> {
|
||||
// 检查程序是否正在退出,如果是则跳过完整验证流程
|
||||
if handle::Handle::global().is_exiting() {
|
||||
logging!(info, Type::Config, true, "应用正在退出,跳过验证");
|
||||
logging!(info, Type::Config, "应用正在退出,跳过验证");
|
||||
return Ok((true, String::new()));
|
||||
}
|
||||
|
||||
// 1. 先生成新的配置内容
|
||||
logging!(info, Type::Config, true, "生成新的配置内容");
|
||||
logging!(info, Type::Config, "生成新的配置内容");
|
||||
Config::generate().await?;
|
||||
|
||||
// 2. 验证配置
|
||||
match self.validate_config().await {
|
||||
Ok((true, _)) => {
|
||||
// 4. 验证通过后,生成正式的运行时配置
|
||||
logging!(info, Type::Config, true, "配置验证通过, 生成运行时配置");
|
||||
logging!(info, Type::Config, "配置验证通过, 生成运行时配置");
|
||||
let run_path = Config::generate_file(ConfigType::Run).await?;
|
||||
logging_error!(Type::Config, true, self.put_configs_force(run_path).await);
|
||||
logging_error!(Type::Config, self.put_configs_force(run_path).await);
|
||||
Ok((true, "something".into()))
|
||||
}
|
||||
Ok((false, error_msg)) => {
|
||||
logging!(warn, Type::Config, true, "配置验证失败: {}", error_msg);
|
||||
logging!(warn, Type::Config, "配置验证失败: {}", error_msg);
|
||||
Config::runtime().await.discard();
|
||||
Ok((false, error_msg))
|
||||
}
|
||||
Err(e) => {
|
||||
logging!(warn, Type::Config, true, "验证过程发生错误: {}", e);
|
||||
logging!(warn, Type::Config, "验证过程发生错误: {}", e);
|
||||
Config::runtime().await.discard();
|
||||
Err(e)
|
||||
}
|
||||
@@ -433,7 +421,7 @@ impl CoreManager {
|
||||
pub async fn put_configs_force(&self, path_buf: PathBuf) -> Result<(), String> {
|
||||
let run_path_str = dirs::path_to_str(&path_buf).map_err(|e| {
|
||||
let msg = e.to_string();
|
||||
logging_error!(Type::Core, true, "{}", msg);
|
||||
logging_error!(Type::Core, "{}", msg);
|
||||
msg
|
||||
});
|
||||
match handle::Handle::mihomo()
|
||||
@@ -443,13 +431,13 @@ impl CoreManager {
|
||||
{
|
||||
Ok(_) => {
|
||||
Config::runtime().await.apply();
|
||||
logging!(info, Type::Core, true, "Configuration updated successfully");
|
||||
logging!(info, Type::Core, "Configuration updated successfully");
|
||||
Ok(())
|
||||
}
|
||||
Err(e) => {
|
||||
let msg = e.to_string();
|
||||
Config::runtime().await.discard();
|
||||
logging_error!(Type::Core, true, "Failed to update configuration: {}", msg);
|
||||
logging_error!(Type::Core, "Failed to update configuration: {}", msg);
|
||||
Err(msg)
|
||||
}
|
||||
}
|
||||
@@ -459,7 +447,7 @@ impl CoreManager {
|
||||
impl CoreManager {
|
||||
/// 清理多余的 mihomo 进程
|
||||
async fn cleanup_orphaned_mihomo_processes(&self) -> Result<()> {
|
||||
logging!(info, Type::Core, true, "开始清理多余的 mihomo 进程");
|
||||
logging!(info, Type::Core, "开始清理多余的 mihomo 进程");
|
||||
|
||||
// 获取当前管理的进程 PID
|
||||
let current_pid = {
|
||||
@@ -495,7 +483,6 @@ impl CoreManager {
|
||||
logging!(
|
||||
debug,
|
||||
Type::Core,
|
||||
true,
|
||||
"跳过当前管理的进程: {} (PID: {})",
|
||||
process_name,
|
||||
pid
|
||||
@@ -506,13 +493,13 @@ impl CoreManager {
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
logging!(debug, Type::Core, true, "查找进程时发生错误: {}", e);
|
||||
logging!(debug, Type::Core, "查找进程时发生错误: {}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if pids_to_kill.is_empty() {
|
||||
logging!(debug, Type::Core, true, "未发现多余的 mihomo 进程");
|
||||
logging!(debug, Type::Core, "未发现多余的 mihomo 进程");
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
@@ -529,7 +516,6 @@ impl CoreManager {
|
||||
logging!(
|
||||
info,
|
||||
Type::Core,
|
||||
true,
|
||||
"清理完成,共终止了 {} 个多余的 mihomo 进程",
|
||||
killed_count
|
||||
);
|
||||
@@ -638,7 +624,6 @@ impl CoreManager {
|
||||
logging!(
|
||||
info,
|
||||
Type::Core,
|
||||
true,
|
||||
"尝试终止进程: {} (PID: {})",
|
||||
process_name,
|
||||
pid
|
||||
@@ -685,7 +670,6 @@ impl CoreManager {
|
||||
logging!(
|
||||
warn,
|
||||
Type::Core,
|
||||
true,
|
||||
"进程 {} (PID: {}) 终止命令成功但进程仍在运行",
|
||||
process_name,
|
||||
pid
|
||||
@@ -695,7 +679,6 @@ impl CoreManager {
|
||||
logging!(
|
||||
info,
|
||||
Type::Core,
|
||||
true,
|
||||
"成功终止进程: {} (PID: {})",
|
||||
process_name,
|
||||
pid
|
||||
@@ -706,7 +689,6 @@ impl CoreManager {
|
||||
logging!(
|
||||
warn,
|
||||
Type::Core,
|
||||
true,
|
||||
"无法终止进程: {} (PID: {})",
|
||||
process_name,
|
||||
pid
|
||||
@@ -756,7 +738,7 @@ impl CoreManager {
|
||||
}
|
||||
|
||||
async fn start_core_by_sidecar(&self) -> Result<()> {
|
||||
logging!(info, Type::Core, true, "Running core by sidecar");
|
||||
logging!(info, Type::Core, "Running core by sidecar");
|
||||
|
||||
let config_file = &Config::generate_file(ConfigType::Run).await?;
|
||||
let app_handle = handle::Handle::app_handle();
|
||||
@@ -775,13 +757,7 @@ impl CoreManager {
|
||||
.spawn()?;
|
||||
|
||||
let pid = child.pid();
|
||||
logging!(
|
||||
trace,
|
||||
Type::Core,
|
||||
true,
|
||||
"Started core by sidecar pid: {}",
|
||||
pid
|
||||
);
|
||||
logging!(trace, Type::Core, "Started core by sidecar pid: {}", pid);
|
||||
*self.child_sidecar.lock() = Some(CommandChildGuard::new(child));
|
||||
self.set_running_mode(RunningMode::Sidecar);
|
||||
|
||||
@@ -824,18 +800,12 @@ impl CoreManager {
|
||||
Ok(())
|
||||
}
|
||||
fn stop_core_by_sidecar(&self) -> Result<()> {
|
||||
logging!(info, Type::Core, true, "Stopping core by sidecar");
|
||||
logging!(info, Type::Core, "Stopping core by sidecar");
|
||||
|
||||
if let Some(child) = self.child_sidecar.lock().take() {
|
||||
let pid = child.pid();
|
||||
drop(child);
|
||||
logging!(
|
||||
trace,
|
||||
Type::Core,
|
||||
true,
|
||||
"Stopped core by sidecar pid: {:?}",
|
||||
pid
|
||||
);
|
||||
logging!(trace, Type::Core, "Stopped core by sidecar pid: {:?}", pid);
|
||||
}
|
||||
self.set_running_mode(RunningMode::NotRunning);
|
||||
Ok(())
|
||||
@@ -844,14 +814,14 @@ impl CoreManager {
|
||||
|
||||
impl CoreManager {
|
||||
async fn start_core_by_service(&self) -> Result<()> {
|
||||
logging!(info, Type::Core, true, "Running core by service");
|
||||
logging!(info, Type::Core, "Running core by service");
|
||||
let config_file = &Config::generate_file(ConfigType::Run).await?;
|
||||
service::run_core_by_service(config_file).await?;
|
||||
self.set_running_mode(RunningMode::Service);
|
||||
Ok(())
|
||||
}
|
||||
async fn stop_core_by_service(&self) -> Result<()> {
|
||||
logging!(info, Type::Core, true, "Stopping core by service");
|
||||
logging!(info, Type::Core, "Stopping core by service");
|
||||
service::stop_core_by_service().await?;
|
||||
self.set_running_mode(RunningMode::NotRunning);
|
||||
Ok(())
|
||||
@@ -876,17 +846,16 @@ impl CoreManager {
|
||||
logging!(
|
||||
warn,
|
||||
Type::Core,
|
||||
true,
|
||||
"应用初始化时清理多余 mihomo 进程失败: {}",
|
||||
e
|
||||
);
|
||||
}
|
||||
|
||||
// 使用简化的启动流程
|
||||
logging!(info, Type::Core, true, "开始核心初始化");
|
||||
logging!(info, Type::Core, "开始核心初始化");
|
||||
self.start_core().await?;
|
||||
|
||||
logging!(info, Type::Core, true, "核心初始化完成");
|
||||
logging!(info, Type::Core, "核心初始化完成");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -919,10 +888,10 @@ impl CoreManager {
|
||||
|
||||
match self.get_running_mode() {
|
||||
RunningMode::Service => {
|
||||
logging_error!(Type::Core, true, self.start_core_by_service().await);
|
||||
logging_error!(Type::Core, self.start_core_by_service().await);
|
||||
}
|
||||
RunningMode::NotRunning | RunningMode::Sidecar => {
|
||||
logging_error!(Type::Core, true, self.start_core_by_sidecar().await);
|
||||
logging_error!(Type::Core, self.start_core_by_sidecar().await);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -941,7 +910,7 @@ impl CoreManager {
|
||||
|
||||
/// 重启内核
|
||||
pub async fn restart_core(&self) -> Result<()> {
|
||||
logging!(info, Type::Core, true, "Restarting core");
|
||||
logging!(info, Type::Core, "Restarting core");
|
||||
self.stop_core().await?;
|
||||
self.start_core().await?;
|
||||
Ok(())
|
||||
@@ -951,17 +920,17 @@ impl CoreManager {
|
||||
pub async fn change_core(&self, clash_core: Option<String>) -> Result<(), String> {
|
||||
if clash_core.is_none() {
|
||||
let error_message = "Clash core should not be Null";
|
||||
logging!(error, Type::Core, true, "{}", error_message);
|
||||
logging!(error, Type::Core, "{}", error_message);
|
||||
return Err(error_message.to_string());
|
||||
}
|
||||
let core = clash_core.as_ref().ok_or_else(|| {
|
||||
let msg = "Clash core should not be None";
|
||||
logging!(error, Type::Core, true, "{}", msg);
|
||||
logging!(error, Type::Core, "{}", msg);
|
||||
msg.to_string()
|
||||
})?;
|
||||
if !IVerge::VALID_CLASH_CORES.contains(&core.as_str()) {
|
||||
let error_message = format!("Clash core invalid name: {core}");
|
||||
logging!(error, Type::Core, true, "{}", error_message);
|
||||
logging!(error, Type::Core, "{}", error_message);
|
||||
return Err(error_message);
|
||||
}
|
||||
|
||||
@@ -970,11 +939,11 @@ impl CoreManager {
|
||||
|
||||
// 分离数据获取和异步调用避免Send问题
|
||||
let verge_data = Config::verge().await.latest_ref().clone();
|
||||
logging_error!(Type::Core, true, verge_data.save_file().await);
|
||||
logging_error!(Type::Core, verge_data.save_file().await);
|
||||
|
||||
let run_path = Config::generate_file(ConfigType::Run).await.map_err(|e| {
|
||||
let msg = e.to_string();
|
||||
logging_error!(Type::Core, true, "{}", msg);
|
||||
logging_error!(Type::Core, "{}", msg);
|
||||
msg
|
||||
})?;
|
||||
|
||||
|
||||
@@ -401,8 +401,8 @@ impl EventDrivenProxyManager {
|
||||
let disabled_sys = Sysproxy::default();
|
||||
let disabled_auto = Autoproxy::default();
|
||||
|
||||
logging_error!(Type::System, true, disabled_auto.set_auto_proxy());
|
||||
logging_error!(Type::System, true, disabled_sys.set_system_proxy());
|
||||
logging_error!(Type::System, disabled_auto.set_auto_proxy());
|
||||
logging_error!(Type::System, disabled_sys.set_system_proxy());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -411,7 +411,7 @@ impl EventDrivenProxyManager {
|
||||
|
||||
if to_pac {
|
||||
let disabled_sys = Sysproxy::default();
|
||||
logging_error!(Type::System, true, disabled_sys.set_system_proxy());
|
||||
logging_error!(Type::System, disabled_sys.set_system_proxy());
|
||||
|
||||
let expected = Self::get_expected_pac_config().await;
|
||||
if let Err(e) = Self::restore_pac_proxy(&expected.url).await {
|
||||
@@ -419,7 +419,7 @@ impl EventDrivenProxyManager {
|
||||
}
|
||||
} else {
|
||||
let disabled_auto = Autoproxy::default();
|
||||
logging_error!(Type::System, true, disabled_auto.set_auto_proxy());
|
||||
logging_error!(Type::System, disabled_auto.set_auto_proxy());
|
||||
|
||||
let expected = Self::get_expected_sys_proxy().await;
|
||||
if let Err(e) = Self::restore_sys_proxy(&expected).await {
|
||||
|
||||
@@ -418,7 +418,6 @@ impl Handle {
|
||||
logging!(
|
||||
info,
|
||||
Type::Frontend,
|
||||
true,
|
||||
"启动过程中发现错误,加入消息队列: {} - {}",
|
||||
status_str,
|
||||
msg_str
|
||||
@@ -468,7 +467,6 @@ impl Handle {
|
||||
logging!(
|
||||
info,
|
||||
Type::Frontend,
|
||||
true,
|
||||
"发送{}条启动时累积的错误消息: {:?}",
|
||||
errors.len(),
|
||||
errors
|
||||
@@ -536,7 +534,6 @@ impl Handle {
|
||||
logging!(
|
||||
warn,
|
||||
Type::Setup,
|
||||
true,
|
||||
"Failed to set regular activation policy: {}",
|
||||
e
|
||||
);
|
||||
@@ -548,7 +545,6 @@ impl Handle {
|
||||
logging!(
|
||||
warn,
|
||||
Type::Setup,
|
||||
true,
|
||||
"Failed to set accessory activation policy: {}",
|
||||
e
|
||||
);
|
||||
@@ -561,7 +557,6 @@ impl Handle {
|
||||
logging!(
|
||||
warn,
|
||||
Type::Setup,
|
||||
true,
|
||||
"Failed to set prohibited activation policy: {}",
|
||||
e
|
||||
);
|
||||
|
||||
@@ -294,7 +294,6 @@ impl Hotkey {
|
||||
logging!(
|
||||
debug,
|
||||
Type::Hotkey,
|
||||
true,
|
||||
"Initializing global hotkeys: {}",
|
||||
enable_global_hotkey
|
||||
);
|
||||
@@ -310,7 +309,6 @@ impl Hotkey {
|
||||
logging!(
|
||||
debug,
|
||||
Type::Hotkey,
|
||||
true,
|
||||
"Has {} hotkeys need to register",
|
||||
hotkeys.len()
|
||||
);
|
||||
@@ -325,7 +323,6 @@ impl Hotkey {
|
||||
logging!(
|
||||
debug,
|
||||
Type::Hotkey,
|
||||
true,
|
||||
"Registering hotkey: {} -> {}",
|
||||
key,
|
||||
func
|
||||
@@ -334,7 +331,6 @@ impl Hotkey {
|
||||
logging!(
|
||||
error,
|
||||
Type::Hotkey,
|
||||
true,
|
||||
"Failed to register hotkey {} -> {}: {:?}",
|
||||
key,
|
||||
func,
|
||||
@@ -356,7 +352,6 @@ impl Hotkey {
|
||||
logging!(
|
||||
error,
|
||||
Type::Hotkey,
|
||||
true,
|
||||
"Invalid hotkey configuration: `{}`:`{}`",
|
||||
key,
|
||||
func
|
||||
@@ -467,7 +462,6 @@ impl Drop for Hotkey {
|
||||
logging!(
|
||||
error,
|
||||
Type::Hotkey,
|
||||
true,
|
||||
"Error unregistering all hotkeys: {:?}",
|
||||
e
|
||||
);
|
||||
|
||||
@@ -28,7 +28,7 @@ pub struct ServiceManager(ServiceStatus);
|
||||
#[allow(clippy::unused_async)]
|
||||
#[cfg(target_os = "windows")]
|
||||
async fn uninstall_service() -> Result<()> {
|
||||
logging!(info, Type::Service, true, "uninstall service");
|
||||
logging!(info, Type::Service, "uninstall service");
|
||||
|
||||
use deelevate::{PrivilegeLevel, Token};
|
||||
use runas::Command as RunasCommand;
|
||||
@@ -63,7 +63,7 @@ async fn uninstall_service() -> Result<()> {
|
||||
#[allow(clippy::unused_async)]
|
||||
#[cfg(target_os = "windows")]
|
||||
async fn install_service() -> Result<()> {
|
||||
logging!(info, Type::Service, true, "install service");
|
||||
logging!(info, Type::Service, "install service");
|
||||
|
||||
use deelevate::{PrivilegeLevel, Token};
|
||||
use runas::Command as RunasCommand;
|
||||
@@ -97,17 +97,11 @@ async fn install_service() -> Result<()> {
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
async fn reinstall_service() -> Result<()> {
|
||||
logging!(info, Type::Service, true, "reinstall service");
|
||||
logging!(info, Type::Service, "reinstall service");
|
||||
|
||||
// 先卸载服务
|
||||
if let Err(err) = uninstall_service().await {
|
||||
logging!(
|
||||
warn,
|
||||
Type::Service,
|
||||
true,
|
||||
"failed to uninstall service: {}",
|
||||
err
|
||||
);
|
||||
logging!(warn, Type::Service, "failed to uninstall service: {}", err);
|
||||
}
|
||||
|
||||
// 再安装服务
|
||||
@@ -122,7 +116,7 @@ async fn reinstall_service() -> Result<()> {
|
||||
#[allow(clippy::unused_async)]
|
||||
#[cfg(target_os = "linux")]
|
||||
async fn uninstall_service() -> Result<()> {
|
||||
logging!(info, Type::Service, true, "uninstall service");
|
||||
logging!(info, Type::Service, "uninstall service");
|
||||
use users::get_effective_uid;
|
||||
|
||||
let uninstall_path = tauri::utils::platform::current_exe()?.with_file_name("uninstall-service");
|
||||
@@ -145,7 +139,6 @@ async fn uninstall_service() -> Result<()> {
|
||||
logging!(
|
||||
info,
|
||||
Type::Service,
|
||||
true,
|
||||
"uninstall status code:{}",
|
||||
status.code().unwrap_or(-1)
|
||||
);
|
||||
@@ -163,7 +156,7 @@ async fn uninstall_service() -> Result<()> {
|
||||
#[cfg(target_os = "linux")]
|
||||
#[allow(clippy::unused_async)]
|
||||
async fn install_service() -> Result<()> {
|
||||
logging!(info, Type::Service, true, "install service");
|
||||
logging!(info, Type::Service, "install service");
|
||||
use users::get_effective_uid;
|
||||
|
||||
let install_path = tauri::utils::platform::current_exe()?.with_file_name("install-service");
|
||||
@@ -186,7 +179,6 @@ async fn install_service() -> Result<()> {
|
||||
logging!(
|
||||
info,
|
||||
Type::Service,
|
||||
true,
|
||||
"install status code:{}",
|
||||
status.code().unwrap_or(-1)
|
||||
);
|
||||
@@ -203,7 +195,7 @@ async fn install_service() -> Result<()> {
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
async fn reinstall_service() -> Result<()> {
|
||||
logging!(info, Type::Service, true, "reinstall service");
|
||||
logging!(info, Type::Service, "reinstall service");
|
||||
|
||||
// 先卸载服务
|
||||
if let Err(err) = uninstall_service().await {
|
||||
@@ -229,7 +221,7 @@ async fn reinstall_service() -> Result<()> {
|
||||
async fn uninstall_service() -> Result<()> {
|
||||
use crate::utils::i18n::t;
|
||||
|
||||
logging!(info, Type::Service, true, "uninstall service");
|
||||
logging!(info, Type::Service, "uninstall service");
|
||||
|
||||
let binary_path = dirs::service_path()?;
|
||||
let uninstall_path = binary_path.with_file_name("uninstall-service");
|
||||
@@ -245,7 +237,7 @@ async fn uninstall_service() -> Result<()> {
|
||||
r#"do shell script "sudo '{uninstall_shell}'" with administrator privileges with prompt "{prompt}""#
|
||||
);
|
||||
|
||||
// logging!(debug, Type::Service, true, "uninstall command: {}", command);
|
||||
// logging!(debug, Type::Service, "uninstall command: {}", command);
|
||||
|
||||
let status = StdCommand::new("osascript")
|
||||
.args(vec!["-e", &command])
|
||||
@@ -265,7 +257,7 @@ async fn uninstall_service() -> Result<()> {
|
||||
async fn install_service() -> Result<()> {
|
||||
use crate::utils::i18n::t;
|
||||
|
||||
logging!(info, Type::Service, true, "install service");
|
||||
logging!(info, Type::Service, "install service");
|
||||
|
||||
let binary_path = dirs::service_path()?;
|
||||
let install_path = binary_path.with_file_name("install-service");
|
||||
@@ -281,7 +273,7 @@ async fn install_service() -> Result<()> {
|
||||
r#"do shell script "sudo '{install_shell}'" with administrator privileges with prompt "{prompt}""#
|
||||
);
|
||||
|
||||
// logging!(debug, Type::Service, true, "install command: {}", command);
|
||||
// logging!(debug, Type::Service, "install command: {}", command);
|
||||
|
||||
let status = StdCommand::new("osascript")
|
||||
.args(vec!["-e", &command])
|
||||
@@ -299,17 +291,11 @@ async fn install_service() -> Result<()> {
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
async fn reinstall_service() -> Result<()> {
|
||||
logging!(info, Type::Service, true, "reinstall service");
|
||||
logging!(info, Type::Service, "reinstall service");
|
||||
|
||||
// 先卸载服务
|
||||
if let Err(err) = uninstall_service().await {
|
||||
logging!(
|
||||
warn,
|
||||
Type::Service,
|
||||
true,
|
||||
"failed to uninstall service: {}",
|
||||
err
|
||||
);
|
||||
logging!(warn, Type::Service, "failed to uninstall service: {}", err);
|
||||
}
|
||||
|
||||
// 再安装服务
|
||||
@@ -323,9 +309,9 @@ async fn reinstall_service() -> Result<()> {
|
||||
|
||||
/// 强制重装服务(UI修复按钮)
|
||||
pub async fn force_reinstall_service() -> Result<()> {
|
||||
logging!(info, Type::Service, true, "用户请求强制重装服务");
|
||||
logging!(info, Type::Service, "用户请求强制重装服务");
|
||||
reinstall_service().await.map_err(|err| {
|
||||
logging!(error, Type::Service, true, "强制重装服务失败: {}", err);
|
||||
logging!(error, Type::Service, "强制重装服务失败: {}", err);
|
||||
err
|
||||
})
|
||||
}
|
||||
@@ -333,7 +319,7 @@ pub async fn force_reinstall_service() -> Result<()> {
|
||||
/// 检查服务版本 - 使用IPC通信
|
||||
async fn check_service_version() -> Result<String> {
|
||||
let version_arc: Result<String> = {
|
||||
logging!(info, Type::Service, true, "开始检查服务版本 (IPC)");
|
||||
logging!(info, Type::Service, "开始检查服务版本 (IPC)");
|
||||
let payload = serde_json::json!({});
|
||||
let response = send_ipc_request(IpcCommand::GetVersion, payload).await?;
|
||||
|
||||
@@ -367,7 +353,7 @@ pub async fn check_service_needs_reinstall() -> bool {
|
||||
|
||||
/// 尝试使用服务启动core
|
||||
pub(super) async fn start_with_existing_service(config_file: &PathBuf) -> Result<()> {
|
||||
logging!(info, Type::Service, true, "尝试使用现有服务启动核心");
|
||||
logging!(info, Type::Service, "尝试使用现有服务启动核心");
|
||||
|
||||
let verge_config = Config::verge().await;
|
||||
let clash_core = verge_config.latest_ref().get_valid_clash_core();
|
||||
@@ -405,25 +391,25 @@ pub(super) async fn start_with_existing_service(config_file: &PathBuf) -> Result
|
||||
bail!("启动核心失败: {}", msg);
|
||||
}
|
||||
|
||||
logging!(info, Type::Service, true, "服务成功启动核心");
|
||||
logging!(info, Type::Service, "服务成功启动核心");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// 以服务启动core
|
||||
pub(super) async fn run_core_by_service(config_file: &PathBuf) -> Result<()> {
|
||||
logging!(info, Type::Service, true, "正在尝试通过服务启动核心");
|
||||
logging!(info, Type::Service, "正在尝试通过服务启动核心");
|
||||
|
||||
if check_service_needs_reinstall().await {
|
||||
reinstall_service().await?;
|
||||
}
|
||||
|
||||
logging!(info, Type::Service, true, "服务已运行且版本匹配,直接使用");
|
||||
logging!(info, Type::Service, "服务已运行且版本匹配,直接使用");
|
||||
start_with_existing_service(config_file).await
|
||||
}
|
||||
|
||||
/// 通过服务停止core
|
||||
pub(super) async fn stop_core_by_service() -> Result<()> {
|
||||
logging!(info, Type::Service, true, "通过服务停止核心 (IPC)");
|
||||
logging!(info, Type::Service, "通过服务停止核心 (IPC)");
|
||||
|
||||
let payload = serde_json::json!({});
|
||||
let response = send_ipc_request(IpcCommand::StopClash, payload)
|
||||
@@ -432,7 +418,7 @@ pub(super) async fn stop_core_by_service() -> Result<()> {
|
||||
|
||||
if !response.success {
|
||||
let err_msg = response.error.unwrap_or_else(|| "停止核心失败".to_string());
|
||||
logging!(error, Type::Service, true, "停止核心失败: {}", err_msg);
|
||||
logging!(error, Type::Service, "停止核心失败: {}", err_msg);
|
||||
bail!(err_msg);
|
||||
}
|
||||
|
||||
@@ -449,7 +435,6 @@ pub(super) async fn stop_core_by_service() -> Result<()> {
|
||||
logging!(
|
||||
error,
|
||||
Type::Service,
|
||||
true,
|
||||
"停止核心返回错误: code={}, msg={}",
|
||||
code_value,
|
||||
msg
|
||||
@@ -458,7 +443,7 @@ pub(super) async fn stop_core_by_service() -> Result<()> {
|
||||
}
|
||||
}
|
||||
|
||||
logging!(info, Type::Service, true, "服务成功停止核心");
|
||||
logging!(info, Type::Service, "服务成功停止核心");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -479,11 +464,7 @@ impl ServiceManager {
|
||||
|
||||
pub async fn refresh(&mut self) -> Result<()> {
|
||||
let status = self.check_service_comprehensive().await;
|
||||
logging_error!(
|
||||
Type::Service,
|
||||
true,
|
||||
self.handle_service_status(&status).await
|
||||
);
|
||||
logging_error!(Type::Service, self.handle_service_status(&status).await);
|
||||
self.0 = status;
|
||||
Ok(())
|
||||
}
|
||||
@@ -492,16 +473,16 @@ impl ServiceManager {
|
||||
pub async fn check_service_comprehensive(&self) -> ServiceStatus {
|
||||
match is_service_available().await {
|
||||
Ok(_) => {
|
||||
logging!(info, Type::Service, true, "服务当前可用,检查是否需要重装");
|
||||
logging!(info, Type::Service, "服务当前可用,检查是否需要重装");
|
||||
if check_service_needs_reinstall().await {
|
||||
logging!(info, Type::Service, true, "服务需要重装且允许重装");
|
||||
logging!(info, Type::Service, "服务需要重装且允许重装");
|
||||
ServiceStatus::NeedsReinstall
|
||||
} else {
|
||||
ServiceStatus::Ready
|
||||
}
|
||||
}
|
||||
Err(err) => {
|
||||
logging!(warn, Type::Service, true, "服务不可用,检查安装状态");
|
||||
logging!(warn, Type::Service, "服务不可用,检查安装状态");
|
||||
ServiceStatus::Unavailable(err.to_string())
|
||||
}
|
||||
}
|
||||
@@ -511,34 +492,29 @@ impl ServiceManager {
|
||||
pub async fn handle_service_status(&mut self, status: &ServiceStatus) -> Result<()> {
|
||||
match status {
|
||||
ServiceStatus::Ready => {
|
||||
logging!(info, Type::Service, true, "服务就绪,直接启动");
|
||||
logging!(info, Type::Service, "服务就绪,直接启动");
|
||||
Ok(())
|
||||
}
|
||||
ServiceStatus::NeedsReinstall | ServiceStatus::ReinstallRequired => {
|
||||
logging!(info, Type::Service, true, "服务需要重装,执行重装流程");
|
||||
logging!(info, Type::Service, "服务需要重装,执行重装流程");
|
||||
reinstall_service().await?;
|
||||
self.0 = ServiceStatus::Ready;
|
||||
Ok(())
|
||||
}
|
||||
ServiceStatus::ForceReinstallRequired => {
|
||||
logging!(
|
||||
info,
|
||||
Type::Service,
|
||||
true,
|
||||
"服务需要强制重装,执行强制重装流程"
|
||||
);
|
||||
logging!(info, Type::Service, "服务需要强制重装,执行强制重装流程");
|
||||
force_reinstall_service().await?;
|
||||
self.0 = ServiceStatus::Ready;
|
||||
Ok(())
|
||||
}
|
||||
ServiceStatus::InstallRequired => {
|
||||
logging!(info, Type::Service, true, "需要安装服务,执行安装流程");
|
||||
logging!(info, Type::Service, "需要安装服务,执行安装流程");
|
||||
install_service().await?;
|
||||
self.0 = ServiceStatus::Ready;
|
||||
Ok(())
|
||||
}
|
||||
ServiceStatus::UninstallRequired => {
|
||||
logging!(info, Type::Service, true, "服务需要卸载,执行卸载流程");
|
||||
logging!(info, Type::Service, "服务需要卸载,执行卸载流程");
|
||||
uninstall_service().await?;
|
||||
self.0 = ServiceStatus::Unavailable("Service Uninstalled".into());
|
||||
Ok(())
|
||||
@@ -547,7 +523,6 @@ impl ServiceManager {
|
||||
logging!(
|
||||
info,
|
||||
Type::Service,
|
||||
true,
|
||||
"服务不可用: {},将使用Sidecar模式",
|
||||
reason
|
||||
);
|
||||
|
||||
@@ -139,7 +139,6 @@ pub async fn send_ipc_request(
|
||||
logging!(
|
||||
warn,
|
||||
Type::Service,
|
||||
true,
|
||||
"IPC请求失败,准备重试: 命令={}, 错误={}",
|
||||
command_type,
|
||||
e
|
||||
@@ -165,7 +164,6 @@ pub async fn send_ipc_request(
|
||||
logging!(
|
||||
error,
|
||||
Type::Service,
|
||||
true,
|
||||
"IPC请求最终失败,重试已耗尽: 命令={}, 错误={}",
|
||||
command_type,
|
||||
e
|
||||
@@ -204,12 +202,12 @@ async fn send_ipc_request_windows(
|
||||
let mut pipe = match ClientOptions::new().open(IPC_SOCKET_NAME) {
|
||||
Ok(p) => p,
|
||||
Err(e) => {
|
||||
logging!(error, Type::Service, true, "连接到服务命名管道失败: {}", e);
|
||||
logging!(error, Type::Service, "连接到服务命名管道失败: {}", e);
|
||||
return Err(anyhow::anyhow!("无法连接到服务命名管道: {}", e));
|
||||
}
|
||||
};
|
||||
|
||||
logging!(info, Type::Service, true, "服务连接成功 (Windows)");
|
||||
logging!(info, Type::Service, "服务连接成功 (Windows)");
|
||||
|
||||
pipe.write_all(&len_bytes).await?;
|
||||
pipe.write_all(request_bytes).await?;
|
||||
@@ -226,7 +224,7 @@ async fn send_ipc_request_windows(
|
||||
.map_err(|e| anyhow::anyhow!("解析响应失败: {}", e))?;
|
||||
|
||||
if !verify_response_signature(&response)? {
|
||||
logging!(error, Type::Service, true, "服务响应签名验证失败");
|
||||
logging!(error, Type::Service, "服务响应签名验证失败");
|
||||
bail!("服务响应签名验证失败");
|
||||
}
|
||||
|
||||
@@ -245,7 +243,7 @@ async fn send_ipc_request_unix(
|
||||
let mut stream = match UnixStream::connect(IPC_SOCKET_NAME).await {
|
||||
Ok(s) => s,
|
||||
Err(e) => {
|
||||
logging!(error, Type::Service, true, "连接到Unix套接字失败: {}", e);
|
||||
logging!(error, Type::Service, "连接到Unix套接字失败: {}", e);
|
||||
return Err(anyhow::anyhow!("无法连接到服务Unix套接字: {}", e));
|
||||
}
|
||||
};
|
||||
@@ -269,7 +267,7 @@ async fn send_ipc_request_unix(
|
||||
.map_err(|e| anyhow::anyhow!("解析响应失败: {}", e))?;
|
||||
|
||||
if !verify_response_signature(&response)? {
|
||||
logging!(error, Type::Service, true, "服务响应签名验证失败");
|
||||
logging!(error, Type::Service, "服务响应签名验证失败");
|
||||
bail!("服务响应签名验证失败");
|
||||
}
|
||||
|
||||
|
||||
@@ -230,7 +230,12 @@ impl Sysopt {
|
||||
pub async fn update_launch(&self) -> Result<()> {
|
||||
let enable_auto_launch = { Config::verge().await.latest_ref().enable_auto_launch };
|
||||
let is_enable = enable_auto_launch.unwrap_or(false);
|
||||
logging!(info, true, "Setting auto-launch state to: {:?}", is_enable);
|
||||
logging!(
|
||||
info,
|
||||
Type::System,
|
||||
"Setting auto-launch state to: {:?}",
|
||||
is_enable
|
||||
);
|
||||
|
||||
// 首先尝试使用快捷方式方法
|
||||
#[cfg(target_os = "windows")]
|
||||
@@ -266,9 +271,9 @@ impl Sysopt {
|
||||
let autostart_manager = app_handle.autolaunch();
|
||||
|
||||
if is_enable {
|
||||
logging_error!(Type::System, true, "{:?}", autostart_manager.enable());
|
||||
logging_error!(Type::System, "{:?}", autostart_manager.enable());
|
||||
} else {
|
||||
logging_error!(Type::System, true, "{:?}", autostart_manager.disable());
|
||||
logging_error!(Type::System, "{:?}", autostart_manager.disable());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ impl Timer {
|
||||
if let Err(e) = self.refresh().await {
|
||||
// Reset initialization flag on error
|
||||
self.initialized.store(false, Ordering::SeqCst);
|
||||
logging_error!(Type::Timer, false, "Failed to initialize timer: {}", e);
|
||||
logging_error!(Type::Timer, "Failed to initialize timer: {}", e);
|
||||
return Err(e);
|
||||
}
|
||||
|
||||
@@ -501,7 +501,7 @@ impl Timer {
|
||||
}
|
||||
},
|
||||
Err(_) => {
|
||||
logging_error!(Type::Timer, false, "Timer task timed out for uid: {}", uid);
|
||||
logging_error!(Type::Timer, "Timer task timed out for uid: {}", uid);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -971,13 +971,7 @@ fn on_menu_event(_: &AppHandle, event: MenuEvent) {
|
||||
match event.id.as_ref() {
|
||||
mode @ ("rule_mode" | "global_mode" | "direct_mode") => {
|
||||
let mode = &mode[0..mode.len() - 5]; // Removing the "_mode" suffix
|
||||
logging!(
|
||||
info,
|
||||
Type::ProxyMode,
|
||||
true,
|
||||
"Switch Proxy Mode To: {}",
|
||||
mode
|
||||
);
|
||||
logging!(info, Type::ProxyMode, "Switch Proxy Mode To: {}", mode);
|
||||
feat::change_clash_mode(mode.into()).await;
|
||||
}
|
||||
"open_window" => {
|
||||
|
||||
Reference in New Issue
Block a user