mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-10-17 23:38:00 +00:00
Fixed the system theme overriding a fixed color theme
This commit is contained in:
3 files changed
+18
-8
No files matched your search
@@ -102,4 +102,4 @@
|
||||
</MudLayout>
|
||||
</MudPaper>
|
||||
|
||||
<MudThemeProvider @ref="@this.themeProvider" Theme="@this.ColorTheme" IsDarkMode="@this.useDarkMode" />
|
||||
<MudThemeProvider @ref="@this.themeProvider" Theme="@this.ColorTheme" IsDarkMode="@this.useDarkMode" ObserveSystemThemeChange="@this.FollowSystemTheme" />
|
||||
@@ -144,7 +144,7 @@ public partial class MainLayout : LayoutComponentBase, IMessageBusReceiver, ILan
|
||||
// Send a message to start the plugin system:
|
||||
await this.MessageBus.SendMessage<bool>(this, Event.STARTUP_PLUGIN_SYSTEM);
|
||||
|
||||
await this.themeProvider.WatchSystemDarkModeAsync(this.SystemeThemeChanged);
|
||||
await this.themeProvider.WatchSystemDarkModeAsync(this.SystemThemeChanged);
|
||||
await this.UpdateThemeConfiguration();
|
||||
this.LoadNavItems();
|
||||
this.LoadEmbeddingItem();
|
||||
@@ -564,19 +564,28 @@ public partial class MainLayout : LayoutComponentBase, IMessageBusReceiver, ILan
|
||||
}
|
||||
}
|
||||
|
||||
private async Task SystemeThemeChanged(bool isDark)
|
||||
/// <summary>
|
||||
/// True, when the user wants AI Studio to follow the light or dark mode of the operating system.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This also decides whether the MudThemeProvider watches the operating system at all. On a system
|
||||
/// change, the provider takes the new mode into its own state first and calls our handler only
|
||||
/// afterward, so the handler cannot prevent it. Nor can a new render of this layout undo it: the
|
||||
/// provider takes over its IsDarkMode parameter only when that value changes, and with a fixed theme,
|
||||
/// it never does. Were the provider watching while the user chose a fixed theme, MudBlazor would show
|
||||
/// the colors of the system from the next render on, while the rest of the app kept the chosen ones.
|
||||
/// </remarks>
|
||||
private bool FollowSystemTheme => this.SettingsManager.ConfigurationData.App.PreferredTheme is Themes.SYSTEM;
|
||||
|
||||
private async Task SystemThemeChanged(bool isDark)
|
||||
{
|
||||
this.Logger.LogInformation($"The system theme changed to {(isDark ? "dark" : "light")}.");
|
||||
|
||||
if (this.SettingsManager.ConfigurationData.App.PreferredTheme is not Themes.SYSTEM)
|
||||
return;
|
||||
|
||||
await this.UpdateThemeConfiguration();
|
||||
}
|
||||
|
||||
private async Task UpdateThemeConfiguration()
|
||||
{
|
||||
if (this.SettingsManager.ConfigurationData.App.PreferredTheme is Themes.SYSTEM)
|
||||
if (this.FollowSystemTheme)
|
||||
this.useDarkMode = await this.themeProvider.GetSystemDarkModeAsync();
|
||||
else
|
||||
this.useDarkMode = this.SettingsManager.ConfigurationData.App.PreferredTheme == Themes.DARK;
|
||||
|
||||
Reference in new issue
Block a user