Skip to content

Commit 4bc4518

Browse files
committed
fix(desktop): add native startup window reveal fallback
1 parent 393187c commit 4bc4518

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

  • apps/desktop/src-tauri/src

apps/desktop/src-tauri/src/lib.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ mod web_http;
1515
mod window_state;
1616
mod windows;
1717

18+
use std::time::Duration;
19+
1820
use ai_http::{request_ai_provider_json, request_native_chat, request_native_chat_stream};
1921
use app_exit::handle_app_exit_requested;
2022
use backup::backup_markdown_folder;
@@ -59,6 +61,8 @@ use windows::{
5961
spawn_blank_editor_window, spawn_settings_window,
6062
};
6163

64+
const STARTUP_WINDOW_NATIVE_REVEAL_FALLBACK_MS: u64 = 2400;
65+
6266
fn window_state_restore_flags() -> StateFlags {
6367
StateFlags::all() - StateFlags::VISIBLE
6468
}
@@ -70,6 +74,28 @@ fn focus_main_window<R: tauri::Runtime>(app: &tauri::AppHandle<R>) {
7074
}
7175
}
7276

77+
fn show_main_window_if_hidden<R: tauri::Runtime>(app: &tauri::AppHandle<R>) {
78+
if let Some(window) = app.get_webview_window("main") {
79+
if window.is_visible().unwrap_or(false) {
80+
return;
81+
}
82+
83+
let _ = window.show();
84+
let _ = window.set_focus();
85+
}
86+
}
87+
88+
fn spawn_startup_window_reveal_fallback<R: tauri::Runtime>(app: &tauri::AppHandle<R>) {
89+
let app = app.clone();
90+
91+
std::thread::spawn(move || {
92+
std::thread::sleep(Duration::from_millis(
93+
STARTUP_WINDOW_NATIVE_REVEAL_FALLBACK_MS,
94+
));
95+
show_main_window_if_hidden(&app);
96+
});
97+
}
98+
7399
#[cfg_attr(mobile, tauri::mobile_entry_point)]
74100
pub fn run() {
75101
let builder = tauri::Builder::default()
@@ -101,6 +127,7 @@ pub fn run() {
101127
.plugin(tauri_plugin_updater::Builder::new().build())
102128
.setup(|app| {
103129
apply_main_window_chrome(app);
130+
spawn_startup_window_reveal_fallback(&app.handle());
104131
if let Some(window) = app.get_webview_window("main") {
105132
remember_native_menu_webview_window(&window);
106133
}
@@ -268,6 +295,18 @@ mod tests {
268295
);
269296
}
270297

298+
#[test]
299+
fn desktop_registers_native_startup_window_reveal_fallback() {
300+
let lib_source = include_str!("lib.rs");
301+
let fallback_registration =
302+
["spawn_startup_window", "_reveal_fallback(&app.handle())"].concat();
303+
304+
assert!(
305+
lib_source.contains(&fallback_registration),
306+
"Tauri setup should register a native startup reveal fallback so hidden dev windows cannot stay Dock-only"
307+
);
308+
}
309+
271310
#[test]
272311
fn desktop_registers_single_instance_plugin_before_other_plugins() {
273312
let manifest = include_str!("../Cargo.toml");

0 commit comments

Comments
 (0)