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:
Tunglies
2025-10-10 13:05:01 +08:00
parent a4d94c8bc9
commit 8c0af66ca9
33 changed files with 292 additions and 706 deletions

View File

@@ -34,27 +34,22 @@ mod app_init {
/// Initialize singleton monitoring for other instances
pub fn init_singleton_check() {
AsyncHandler::spawn_blocking(move || async move {
logging!(info, Type::Setup, true, "开始检查单例实例...");
logging!(info, Type::Setup, "开始检查单例实例...");
match timeout(Duration::from_millis(500), server::check_singleton()).await {
Ok(result) => {
if result.is_err() {
logging!(info, Type::Setup, true, "检测到已有应用实例运行");
logging!(info, Type::Setup, "检测到已有应用实例运行");
if let Some(app_handle) = APP_HANDLE.get() {
app_handle.exit(0);
} else {
std::process::exit(0);
}
} else {
logging!(info, Type::Setup, true, "未检测到其他应用实例");
logging!(info, Type::Setup, "未检测到其他应用实例");
}
}
Err(_) => {
logging!(
warn,
Type::Setup,
true,
"单例检查超时,假定没有其他实例运行"
);
logging!(warn, Type::Setup, "单例检查超时,假定没有其他实例运行");
}
}
});
@@ -94,7 +89,7 @@ mod app_init {
pub fn setup_deep_links(app: &tauri::App) -> Result<(), Box<dyn std::error::Error>> {
#[cfg(any(target_os = "linux", all(debug_assertions, windows)))]
{
logging!(info, Type::Setup, true, "注册深层链接...");
logging!(info, Type::Setup, "注册深层链接...");
app.deep_link().register_all()?;
}
@@ -103,7 +98,7 @@ mod app_init {
if let Some(url) = url {
AsyncHandler::spawn(|| async {
if let Err(e) = resolve::resolve_scheme(url).await {
logging!(error, Type::Setup, true, "Failed to resolve scheme: {}", e);
logging!(error, Type::Setup, "Failed to resolve scheme: {}", e);
}
});
}
@@ -131,7 +126,7 @@ mod app_init {
/// Setup window state management
pub fn setup_window_state(app: &tauri::App) -> Result<(), Box<dyn std::error::Error>> {
logging!(info, Type::Setup, true, "初始化窗口状态管理...");
logging!(info, Type::Setup, "初始化窗口状态管理...");
let window_state_plugin = tauri_plugin_window_state::Builder::new()
.with_filename("window_state.json")
.with_state_flags(tauri_plugin_window_state::StateFlags::default())
@@ -337,7 +332,7 @@ pub fn run() {
// Create and configure the Tauri builder
let builder = app_init::setup_plugins(tauri::Builder::default())
.setup(|app| {
logging!(info, Type::Setup, true, "开始应用初始化...");
logging!(info, Type::Setup, "开始应用初始化...");
#[allow(clippy::expect_used)]
APP_HANDLE
@@ -346,38 +341,26 @@ pub fn run() {
// Setup autostart plugin
if let Err(e) = app_init::setup_autostart(app) {
logging!(error, Type::Setup, true, "Failed to setup autostart: {}", e);
logging!(error, Type::Setup, "Failed to setup autostart: {}", e);
}
// Setup deep links
if let Err(e) = app_init::setup_deep_links(app) {
logging!(
error,
Type::Setup,
true,
"Failed to setup deep links: {}",
e
);
logging!(error, Type::Setup, "Failed to setup deep links: {}", e);
}
// Setup window state management
if let Err(e) = app_init::setup_window_state(app) {
logging!(
error,
Type::Setup,
true,
"Failed to setup window state: {}",
e
);
logging!(error, Type::Setup, "Failed to setup window state: {}", e);
}
logging!(info, Type::Setup, true, "执行主要设置操作...");
logging!(info, Type::Setup, "执行主要设置操作...");
resolve::resolve_setup_handle();
resolve::resolve_setup_async();
resolve::resolve_setup_sync();
logging!(info, Type::Setup, true, "初始化完成,继续执行");
logging!(info, Type::Setup, "初始化完成,继续执行");
Ok(())
})
.invoke_handler(app_init::generate_handlers());
@@ -395,19 +378,18 @@ pub fn run() {
logging!(
debug,
Type::System,
true,
"handle_ready_resumed: 应用正在退出,跳过处理"
);
return;
}
logging!(info, Type::System, true, "应用就绪或恢复");
logging!(info, Type::System, "应用就绪或恢复");
handle::Handle::global().init();
#[cfg(target_os = "macos")]
{
if let Some(window) = _app_handle.get_webview_window("main") {
logging!(info, Type::Window, true, "设置macOS窗口标题");
logging!(info, Type::Window, "设置macOS窗口标题");
let _ = window.set_title("Clash Verge");
}
}
@@ -419,7 +401,6 @@ pub fn run() {
logging!(
info,
Type::System,
true,
"处理 macOS 应用重新打开事件: has_visible_windows={}",
has_visible_windows
);
@@ -430,18 +411,12 @@ pub fn run() {
// 当没有可见窗口时,设置为 regular 模式并显示主窗口
handle::Handle::global().set_activation_policy_regular();
logging!(info, Type::System, true, "没有可见窗口,尝试显示主窗口");
logging!(info, Type::System, "没有可见窗口,尝试显示主窗口");
let result = WindowManager::show_main_window().await;
logging!(
info,
Type::System,
true,
"窗口显示操作完成,结果: {:?}",
result
);
logging!(info, Type::System, "窗口显示操作完成,结果: {:?}", result);
} else {
logging!(info, Type::System, true, "已有可见窗口,无需额外操作");
logging!(info, Type::System, "已有可见窗口,无需额外操作");
}
}
@@ -460,7 +435,7 @@ pub fn run() {
if let Some(window) = core::handle::Handle::get_window() {
let _ = window.hide();
} else {
logging!(warn, Type::Window, true, "尝试隐藏窗口但窗口不存在");
logging!(warn, Type::Window, "尝试隐藏窗口但窗口不存在");
}
}
}
@@ -482,20 +457,20 @@ pub fn run() {
.register_system_hotkey(SystemHotkey::CmdQ)
.await
{
logging!(error, Type::Hotkey, true, "Failed to register CMD+Q: {}", e);
logging!(error, Type::Hotkey, "Failed to register CMD+Q: {}", e);
}
if let Err(e) = hotkey::Hotkey::global()
.register_system_hotkey(SystemHotkey::CmdW)
.await
{
logging!(error, Type::Hotkey, true, "Failed to register CMD+W: {}", e);
logging!(error, Type::Hotkey, "Failed to register CMD+W: {}", e);
}
}
if !is_enable_global_hotkey
&& let Err(e) = hotkey::Hotkey::global().init().await
{
logging!(error, Type::Hotkey, true, "Failed to init hotkeys: {}", e);
logging!(error, Type::Hotkey, "Failed to init hotkeys: {}", e);
}
return;
}
@@ -507,29 +482,17 @@ pub fn run() {
if let Err(e) =
hotkey::Hotkey::global().unregister_system_hotkey(SystemHotkey::CmdQ)
{
logging!(
error,
Type::Hotkey,
true,
"Failed to unregister CMD+Q: {}",
e
);
logging!(error, Type::Hotkey, "Failed to unregister CMD+Q: {}", e);
}
if let Err(e) =
hotkey::Hotkey::global().unregister_system_hotkey(SystemHotkey::CmdW)
{
logging!(
error,
Type::Hotkey,
true,
"Failed to unregister CMD+W: {}",
e
);
logging!(error, Type::Hotkey, "Failed to unregister CMD+W: {}", e);
}
}
if !is_enable_global_hotkey && let Err(e) = hotkey::Hotkey::global().reset() {
logging!(error, Type::Hotkey, true, "Failed to reset hotkeys: {}", e);
logging!(error, Type::Hotkey, "Failed to reset hotkeys: {}", e);
}
});
}
@@ -545,7 +508,6 @@ pub fn run() {
logging!(
error,
Type::Hotkey,
true,
"Failed to unregister CMD+Q on destroy: {}",
e
);
@@ -556,7 +518,6 @@ pub fn run() {
logging!(
error,
Type::Hotkey,
true,
"Failed to unregister CMD+W on destroy: {}",
e
);
@@ -572,7 +533,6 @@ pub fn run() {
logging!(
error,
Type::Setup,
true,
"Failed to build Tauri application: {}",
e
);
@@ -584,12 +544,7 @@ pub fn run() {
tauri::RunEvent::Ready | tauri::RunEvent::Resumed => {
// 如果正在退出,忽略 Ready/Resumed 事件
if core::handle::Handle::global().is_exiting() {
logging!(
debug,
Type::System,
true,
"忽略 Ready/Resumed 事件,应用正在退出"
);
logging!(debug, Type::System, "忽略 Ready/Resumed 事件,应用正在退出");
return;
}
event_handlers::handle_ready_resumed(app_handle);
@@ -601,7 +556,7 @@ pub fn run() {
} => {
// 如果正在退出,忽略 Reopen 事件
if core::handle::Handle::global().is_exiting() {
logging!(debug, Type::System, true, "忽略 Reopen 事件,应用正在退出");
logging!(debug, Type::System, "忽略 Reopen 事件,应用正在退出");
return;
}
AsyncHandler::spawn(move || async move {
@@ -620,7 +575,6 @@ pub fn run() {
logging!(
info,
Type::System,
true,
"应用正在退出,允许 ExitRequested (code: {:?})",
code
);
@@ -629,7 +583,7 @@ pub fn run() {
// 只阻止外部的无退出码请求(如用户取消系统关机)
if code.is_none() {
logging!(debug, Type::System, true, "阻止外部退出请求");
logging!(debug, Type::System, "阻止外部退出请求");
api.prevent_exit();
}
}