From e0206ba8e25907cf9e42efb45fde01f6e2ae72be Mon Sep 17 00:00:00 2001 From: saladday <1203511142@qq.com> Date: Sun, 9 Aug 2026 09:28:30 -0400 Subject: [PATCH] fix(windows): show window after themed page loads --- src-tauri/src/lib.rs | 22 ++++++++++++++++++++++ src-tauri/tauri.conf.json | 1 - 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 1c630e84b..119044e4f 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -70,6 +70,8 @@ pub use store::AppState; use tauri_plugin_deep_link::DeepLinkExt; use tauri_plugin_dialog::{DialogExt, MessageDialogButtons, MessageDialogKind}; +#[cfg(target_os = "windows")] +use std::sync::atomic::{AtomicBool, Ordering}; use std::{fmt, sync::Arc}; #[cfg(target_os = "macos")] use tauri::image::Image; @@ -368,6 +370,22 @@ pub fn run() { })); } + #[cfg(target_os = "windows")] + { + let startup_page_handled = AtomicBool::new(false); + builder = builder.on_page_load(move |webview, payload| { + if webview.label() == "main" + && payload.event() == tauri::webview::PageLoadEvent::Finished + && payload.url().scheme() != "about" + && !startup_page_handled.swap(true, Ordering::Relaxed) + && !crate::settings::get_settings().silent_startup + { + let _ = webview.window().show(); + log::info!("主页面加载完成,主窗口已显示"); + } + }); + } + let builder = builder // 注册 deep-link 插件(处理 macOS AppleEvent 和其他平台的深链接) .plugin(tauri_plugin_deep_link::init()) @@ -1299,7 +1317,11 @@ pub fn run() { log::info!("静默启动模式:主窗口已隐藏"); } else { // 正常启动模式:显示窗口 + #[cfg(not(target_os = "windows"))] let _ = window.show(); + #[cfg(target_os = "windows")] + log::info!("正常启动模式:等待主页面加载完成后显示主窗口"); + #[cfg(not(target_os = "windows"))] log::info!("正常启动模式:主窗口已显示"); // Linux: 解决首次启动 UI 无响应问题(Tauri #10746 + wry #637)。 diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 5ed6c78f3..fd5b36057 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -20,7 +20,6 @@ "minWidth": 900, "minHeight": 600, "visible": false, - "backgroundColor": "#1e1e22", "resizable": true, "fullscreen": false, "center": true