Skip to content

Commit 1fb28ee

Browse files
authored
Reorganize Settings info and diagnostics
Preserve diagnostics visibility for upgrades, prune hidden diagnostics navigation state, and localize the new diagnostics setting label.
1 parent 989f9ff commit 1fb28ee

24 files changed

Lines changed: 1397 additions & 978 deletions

‎src/OpenClaw.Shared/SettingsData.cs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ public record class SettingsData
127127
/// "User interface" section.
128128
/// </summary>
129129
public bool UseLegacyWebChat { get; set; } = false;
130+
public string AppTheme { get; set; } = "System";
131+
public bool? ShowDiagnostics { get; set; }
130132
public List<UserNotificationRule>? UserRules { get; set; }
131133

132134
// ── MXC sandbox ─────────────────────────────────────────────────────

‎src/OpenClaw.Tray.WinUI/App.xaml.cs‎

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#if OPENCLAW_TRAY_TESTS
2+
namespace OpenClawTray.Helpers;
3+
4+
internal static class DiagnosticsGate
5+
{
6+
public static bool BuildDefault => true;
7+
public static bool IsVisible => BuildDefault;
8+
}
9+
#else
10+
using Microsoft.UI.Xaml;
11+
12+
namespace OpenClawTray.Helpers;
13+
14+
/// <summary>
15+
/// Gates the Diagnostics page. Diagnostics remain visible by default for
16+
/// compatibility with existing installs; users can explicitly hide or show them
17+
/// via Settings (SettingsManager.ShowDiagnosticsOverride).
18+
/// </summary>
19+
internal static class DiagnosticsGate
20+
{
21+
public static bool BuildDefault =>
22+
true;
23+
24+
/// <summary>Effective visibility: user override if set, else the build default.</summary>
25+
public static bool IsVisible =>
26+
(Application.Current as OpenClawTray.App)?.SettingsOrNull?.ShowDiagnosticsEffective ?? BuildDefault;
27+
}
28+
#endif

‎src/OpenClaw.Tray.WinUI/Helpers/ThemeHelper.cs‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,20 @@ public static ElementTheme GetCurrentTheme()
3030
return IsDarkMode() ? ElementTheme.Dark : ElementTheme.Light;
3131
}
3232

33+
public static ElementTheme GetRequestedTheme(string? preference) =>
34+
SettingsManager.NormalizeAppTheme(preference) switch
35+
{
36+
SettingsManager.AppThemeLight => ElementTheme.Light,
37+
SettingsManager.AppThemeDark => ElementTheme.Dark,
38+
_ => ElementTheme.Default
39+
};
40+
41+
public static void ApplyTheme(Window? window, string? preference)
42+
{
43+
if (window?.Content is FrameworkElement rootElement)
44+
rootElement.RequestedTheme = GetRequestedTheme(preference);
45+
}
46+
3347
public static Color GetAccentColor()
3448
{
3549
// Returns the user's Windows accent color (previously hard-coded to

‎src/OpenClaw.Tray.WinUI/Pages/AboutPage.xaml‎

Lines changed: 0 additions & 110 deletions
This file was deleted.

0 commit comments

Comments
 (0)