@@ -9,6 +9,10 @@ const DMABUF_ENV: &str = "WEBKIT_DISABLE_DMABUF_RENDERER";
99const COMPOSITING_ENV : & str = "WEBKIT_DISABLE_COMPOSITING_MODE" ;
1010#[ cfg( target_os = "linux" ) ]
1111const XDG_SESSION_TYPE_ENV : & str = "XDG_SESSION_TYPE" ;
12+ #[ cfg( target_os = "linux" ) ]
13+ const AUTO_WINDOW_ENV : & str = "AQBOT_LINUX_AUTO_WINDOW" ;
14+ #[ cfg( target_os = "linux" ) ]
15+ const MAIN_WINDOW_LABEL : & str = "main" ;
1216
1317#[ derive( Debug , PartialEq , Eq ) ]
1418enum WorkaroundDecision {
@@ -60,6 +64,41 @@ pub fn apply_startup_workarounds() {
6064 }
6165}
6266
67+ #[ cfg( target_os = "linux" ) ]
68+ pub fn configure_startup_window_creation < R : tauri:: Runtime > ( context : & mut tauri:: Context < R > ) {
69+ let auto_window = should_use_tauri_auto_window_from_env ( ) ;
70+ let window_count = context. config ( ) . app . windows . len ( ) ;
71+
72+ if auto_window {
73+ tracing:: info!(
74+ auto_window_env = %env_value( AUTO_WINDOW_ENV ) ,
75+ window_count,
76+ "Using Tauri automatic window creation for Linux diagnostics"
77+ ) ;
78+ return ;
79+ }
80+
81+ let mut disabled_labels = Vec :: new ( ) ;
82+ for window in & mut context. config_mut ( ) . app . windows {
83+ if window. label == MAIN_WINDOW_LABEL {
84+ window. create = false ;
85+ disabled_labels. push ( window. label . clone ( ) ) ;
86+ }
87+ }
88+
89+ tracing:: info!(
90+ auto_window_env = %env_value( AUTO_WINDOW_ENV ) ,
91+ window_count,
92+ disabled_labels = ?disabled_labels,
93+ "Disabled Tauri automatic main window creation for Linux diagnostics"
94+ ) ;
95+ }
96+
97+ #[ cfg( target_os = "linux" ) ]
98+ pub fn should_create_main_window_in_setup ( ) -> bool {
99+ !should_use_tauri_auto_window_from_env ( )
100+ }
101+
63102fn decide_workaround (
64103 opt_out : Option < & str > ,
65104 user_configured_dmabuf : bool ,
@@ -95,9 +134,23 @@ fn is_truthy(value: &str) -> bool {
95134 )
96135}
97136
137+ fn should_use_tauri_auto_window ( value : Option < & str > ) -> bool {
138+ value. map ( is_truthy) . unwrap_or ( false )
139+ }
140+
141+ #[ cfg( target_os = "linux" ) ]
142+ fn should_use_tauri_auto_window_from_env ( ) -> bool {
143+ should_use_tauri_auto_window ( env:: var ( AUTO_WINDOW_ENV ) . ok ( ) . as_deref ( ) )
144+ }
145+
146+ #[ cfg( target_os = "linux" ) ]
147+ fn env_value ( key : & str ) -> String {
148+ env:: var ( key) . unwrap_or_else ( |_| "<unset>" . to_string ( ) )
149+ }
150+
98151#[ cfg( test) ]
99152mod tests {
100- use super :: { decide_workaround, SkipReason , WorkaroundDecision } ;
153+ use super :: { decide_workaround, should_use_tauri_auto_window , SkipReason , WorkaroundDecision } ;
101154
102155 #[ test]
103156 fn enables_dmabuf_workaround_for_wayland_by_default ( ) {
@@ -142,4 +195,15 @@ mod tests {
142195 WorkaroundDecision :: Skip ( SkipReason :: NotWayland )
143196 ) ;
144197 }
198+
199+ #[ test]
200+ fn tauri_auto_window_is_opt_in ( ) {
201+ assert ! ( !should_use_tauri_auto_window( None ) ) ;
202+ assert ! ( !should_use_tauri_auto_window( Some ( "" ) ) ) ;
203+ assert ! ( !should_use_tauri_auto_window( Some ( "0" ) ) ) ;
204+ assert ! ( should_use_tauri_auto_window( Some ( "1" ) ) ) ;
205+ assert ! ( should_use_tauri_auto_window( Some ( "true" ) ) ) ;
206+ assert ! ( should_use_tauri_auto_window( Some ( "yes" ) ) ) ;
207+ assert ! ( should_use_tauri_auto_window( Some ( "on" ) ) ) ;
208+ }
145209}
0 commit comments