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:
@@ -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
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user