@@ -60,6 +60,7 @@ public partial class App : Application, OpenClawTray.Services.IAppCommands
6060 public GatewayRegistry ? Registry => _gatewayRegistry ;
6161 public GatewayConnectionManager ? ConnectionManager => _connectionManager ;
6262 internal SettingsManager Settings => _settings ?? throw new InvalidOperationException ( "Settings are not initialized." ) ;
63+ internal SettingsManager ? SettingsOrNull => _settings ;
6364 internal string DataDirectoryPath => DataPath ;
6465
6566 /// <summary>The active hub window, exposed so pages can obtain an HWND for file pickers.</summary>
@@ -699,6 +700,7 @@ _dispatcherQueue is null
699700 ! prewarmIsBootstrapToken )
700701 {
701702 _chatWindow = new ChatWindow ( prewarmUrl , prewarmToken ) ;
703+ ApplyThemePreference ( _chatWindow ) ;
702704 // Window is created but hidden — WebView2 initializes in the background
703705 }
704706
@@ -736,6 +738,7 @@ private void InitializeKeepAliveWindow()
736738 // This prevents GC/threading issues when creating windows after idle
737739 _keepAliveWindow = new Window ( ) ;
738740 _keepAliveWindow . Content = new Microsoft . UI . Xaml . Controls . Grid ( ) ;
741+ ApplyThemePreference ( _keepAliveWindow ) ;
739742 _keepAliveWindow . AppWindow . IsShownInSwitchers = false ;
740743
741744 // Move off-screen and set minimal size
@@ -768,10 +771,28 @@ private void InitializeTrayMenuWindow()
768771 {
769772 // Pre-create menu window once - reuse to avoid crash on window creation after idle
770773 _trayMenuWindow = new TrayMenuWindow ( ) ;
774+ ApplyThemePreference ( _trayMenuWindow ) ;
771775 _trayMenuWindow . MenuItemClicked += OnTrayMenuItemClicked ;
772776 // Don't close - just hide
773777 }
774778
779+ internal void ApplyThemePreferenceToOpenWindows ( )
780+ {
781+ ApplyThemePreference ( _keepAliveWindow ) ;
782+ ApplyThemePreference ( _hubWindow ) ;
783+ ApplyThemePreference ( _trayMenuWindow ) ;
784+ ApplyThemePreference ( _chatWindow ) ;
785+ ApplyThemePreference ( _connectionStatusWindow ) ;
786+ }
787+
788+ private void ApplyThemePreference ( Window ? window )
789+ {
790+ if ( _settings is null )
791+ return ;
792+
793+ ThemeHelper . ApplyTheme ( window , _settings . AppTheme ) ;
794+ }
795+
775796 private void OnTrayIconSelected ( TrayIcon sender , TrayIconEventArgs e )
776797 {
777798 if ( _connectionManager ? . CurrentSnapshot . OperatorState == RoleConnectionState . Connected )
@@ -806,6 +827,7 @@ internal void ShowChatWindow()
806827 if ( _chatWindow == null )
807828 {
808829 _chatWindow = new ChatWindow ( url , token ) ;
830+ ApplyThemePreference ( _chatWindow ) ;
809831 }
810832
811833 // Bug 2: cached ChatWindow may have been pre-warmed with empty/stale credentials
@@ -3334,6 +3356,7 @@ internal void ShowHub(string? navigateTo = null, bool activate = true)
33343356 if ( _hubWindow == null || _hubWindow . IsClosed )
33353357 {
33363358 _hubWindow = new HubWindow ( ) ;
3359+ ApplyThemePreference ( _hubWindow ) ;
33373360 _hubWindow . AppModel = _appState ;
33383361 _hubWindow . BindAppNotifications ( _appNotificationService ! ) ;
33393362 _hubWindow . ApplyNavPaneState ( _settings ! ) ;
@@ -3489,7 +3512,6 @@ private void OnSettingsSaved(object? sender, EventArgs e)
34893512 WireAppCapabilityHandlers ( ) ;
34903513 }
34913514
3492- // Non-connection settings always applied regardless of impact
34933515 if ( _settings ! . GlobalHotkeyEnabled )
34943516 {
34953517 _globalHotkey ??= new GlobalHotkeyService ( ) ;
@@ -3508,19 +3530,24 @@ private void OnSettingsSaved(object? sender, EventArgs e)
35083530 AutoStartManager . SetAutoStartAsync ( _settings . AutoStart ) ,
35093531 "[App] Failed to apply auto-start setting" ) ;
35103532
3511- // Notify ad-hoc listeners (e.g. ChatWindow may be alive but not
3512- // owned by the hub) that settings have changed. Marshal onto the
3513- // UI thread because IAppCommands.NotifySettingsSaved is a public
3514- // entry point that may be invoked from background work; existing
3515- // handlers (DebugPage, ChatWindow) update UI directly and would
3516- // crash if dispatched from a non-UI thread (Hanselman v2 #7).
3533+ // Apply UI-only settings and notify ad-hoc listeners. This public
3534+ // entry point can be invoked from background work, while existing
3535+ // listeners update UI directly.
3536+ void ApplyUiSettingsAndNotify ( )
3537+ {
3538+ ApplyThemePreferenceToOpenWindows ( ) ;
3539+ if ( _hubWindow is { IsClosed : false } )
3540+ _hubWindow . RefreshDiagnosticsNavVisibility ( ) ;
3541+ SettingsChanged ? . Invoke ( this , EventArgs . Empty ) ;
3542+ }
3543+
35173544 if ( _dispatcherQueue != null && ! _dispatcherQueue . HasThreadAccess )
35183545 {
3519- _dispatcherQueue . TryEnqueue ( ( ) => SettingsChanged ? . Invoke ( this , EventArgs . Empty ) ) ;
3546+ _dispatcherQueue . TryEnqueue ( ApplyUiSettingsAndNotify ) ;
35203547 }
35213548 else
35223549 {
3523- SettingsChanged ? . Invoke ( this , EventArgs . Empty ) ;
3550+ ApplyUiSettingsAndNotify ( ) ;
35243551 }
35253552 }
35263553
@@ -3581,6 +3608,7 @@ private void ShowConnectionStatusWindow()
35813608 _connectionManager ! . Diagnostics ,
35823609 _gatewayRegistry ,
35833610 _connectionManager ) ;
3611+ ApplyThemePreference ( _connectionStatusWindow ) ;
35843612 _connectionStatusWindow . Activate ( ) ;
35853613 }
35863614
0 commit comments