From 4795bf8b66df1b74cc77aa43eee6f355ca03e9e3 Mon Sep 17 00:00:00 2001 From: Bugadinho <31747009+Bugadinho@users.noreply.github.com> Date: Sun, 5 Jan 2025 23:37:01 -0300 Subject: [PATCH 1/3] Use WinRT to get dark theme --- Bloxstrap/Extensions/ThemeEx.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Bloxstrap/Extensions/ThemeEx.cs b/Bloxstrap/Extensions/ThemeEx.cs index f5fc70ca4..2a1b924ae 100644 --- a/Bloxstrap/Extensions/ThemeEx.cs +++ b/Bloxstrap/Extensions/ThemeEx.cs @@ -1,4 +1,4 @@ -using Microsoft.Win32; +using Windows.UI.ViewManagement; namespace Bloxstrap.Extensions { @@ -9,9 +9,9 @@ public static Theme GetFinal(this Theme dialogTheme) if (dialogTheme != Theme.Default) return dialogTheme; - using var key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize"); - - if (key?.GetValue("AppsUseLightTheme") is int value && value == 0) + var settings = new UISettings(); + var background = settings.GetColorValue(UIColorType.Background); + if (((5 * background.G) + (2 * background.R) + background.B) < (8 * 128)) return Theme.Dark; return Theme.Light; From e9838141767577db4fe2cabe73eff31cdc70d224 Mon Sep 17 00:00:00 2001 From: Bugadinho <31747009+Bugadinho@users.noreply.github.com> Date: Mon, 6 Jan 2025 20:54:32 -0300 Subject: [PATCH 2/3] ColorValuesChanged now reapplies the theme --- Bloxstrap/UI/Elements/Base/WpfUiWindow.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Bloxstrap/UI/Elements/Base/WpfUiWindow.cs b/Bloxstrap/UI/Elements/Base/WpfUiWindow.cs index db06e7f5e..ccc7181e5 100644 --- a/Bloxstrap/UI/Elements/Base/WpfUiWindow.cs +++ b/Bloxstrap/UI/Elements/Base/WpfUiWindow.cs @@ -4,23 +4,27 @@ using Wpf.Ui.Controls; using Wpf.Ui.Mvvm.Contracts; using Wpf.Ui.Mvvm.Services; +using Windows.UI.ViewManagement; namespace Bloxstrap.UI.Elements.Base { public abstract class WpfUiWindow : UiWindow { private readonly IThemeService _themeService = new ThemeService(); + private UISettings _settings; public WpfUiWindow() { ApplyTheme(); + _settings = new UISettings(); + _settings.ColorValuesChanged += ColorValuesChanged; } public void ApplyTheme() { _themeService.SetTheme(App.Settings.Prop.Theme.GetFinal() == Enums.Theme.Dark ? ThemeType.Dark : ThemeType.Light); _themeService.SetSystemAccent(); - + #if QA_BUILD this.BorderBrush = System.Windows.Media.Brushes.Red; this.BorderThickness = new Thickness(4); @@ -37,5 +41,13 @@ protected override void OnSourceInitialized(EventArgs e) base.OnSourceInitialized(e); } + + private async void ColorValuesChanged(UISettings sender, object args) + { + await Dispatcher.InvokeAsync(() => + { + ApplyTheme(); + }); + } } } From f23d2bce887bd7b883e1ceb545f8a70e7d8adf79 Mon Sep 17 00:00:00 2001 From: Bugadinho <31747009+Bugadinho@users.noreply.github.com> Date: Mon, 6 Jan 2025 21:24:29 -0300 Subject: [PATCH 3/3] Set WindowBackdropType to allow for dynamic theme change --- Bloxstrap/UI/Elements/ContextMenu/ServerHistory.xaml | 1 + Bloxstrap/UI/Elements/ContextMenu/ServerInformation.xaml | 1 + Bloxstrap/UI/Elements/Dialogs/AddFastFlagDialog.xaml | 1 + Bloxstrap/UI/Elements/Dialogs/ConnectivityDialog.xaml | 1 + Bloxstrap/UI/Elements/Dialogs/ExceptionDialog.xaml | 1 + Bloxstrap/UI/Elements/Dialogs/FluentMessageBox.xaml | 1 + Bloxstrap/UI/Elements/Dialogs/LanguageSelectorDialog.xaml | 1 + Bloxstrap/UI/Elements/Dialogs/LaunchMenuDialog.xaml | 1 + Bloxstrap/UI/Elements/Dialogs/UninstallerDialog.xaml | 1 + 9 files changed, 9 insertions(+) diff --git a/Bloxstrap/UI/Elements/ContextMenu/ServerHistory.xaml b/Bloxstrap/UI/Elements/ContextMenu/ServerHistory.xaml index bb723a943..1d91aa414 100644 --- a/Bloxstrap/UI/Elements/ContextMenu/ServerHistory.xaml +++ b/Bloxstrap/UI/Elements/ContextMenu/ServerHistory.xaml @@ -18,6 +18,7 @@ Height="420" Background="{ui:ThemeResource ApplicationBackgroundBrush}" ExtendsContentIntoTitleBar="True" + WindowBackdropType="Mica" WindowStartupLocation="CenterScreen"> diff --git a/Bloxstrap/UI/Elements/ContextMenu/ServerInformation.xaml b/Bloxstrap/UI/Elements/ContextMenu/ServerInformation.xaml index 3f123020a..8a3e6bfee 100644 --- a/Bloxstrap/UI/Elements/ContextMenu/ServerInformation.xaml +++ b/Bloxstrap/UI/Elements/ContextMenu/ServerInformation.xaml @@ -18,6 +18,7 @@ ResizeMode="NoResize" Background="{ui:ThemeResource ApplicationBackgroundBrush}" ExtendsContentIntoTitleBar="True" + WindowBackdropType="Mica" WindowStartupLocation="CenterScreen"> diff --git a/Bloxstrap/UI/Elements/Dialogs/AddFastFlagDialog.xaml b/Bloxstrap/UI/Elements/Dialogs/AddFastFlagDialog.xaml index f4ea9b67c..3291f48ff 100644 --- a/Bloxstrap/UI/Elements/Dialogs/AddFastFlagDialog.xaml +++ b/Bloxstrap/UI/Elements/Dialogs/AddFastFlagDialog.xaml @@ -16,6 +16,7 @@ ResizeMode="NoResize" Background="{ui:ThemeResource ApplicationBackgroundBrush}" ExtendsContentIntoTitleBar="True" + WindowBackdropType="Mica" WindowStartupLocation="CenterScreen"> diff --git a/Bloxstrap/UI/Elements/Dialogs/ConnectivityDialog.xaml b/Bloxstrap/UI/Elements/Dialogs/ConnectivityDialog.xaml index 03817bb1a..ef709e49a 100644 --- a/Bloxstrap/UI/Elements/Dialogs/ConnectivityDialog.xaml +++ b/Bloxstrap/UI/Elements/Dialogs/ConnectivityDialog.xaml @@ -15,6 +15,7 @@ Title="{x:Static resources:Strings.Dialog_Connectivity_Title}" Background="{ui:ThemeResource ApplicationBackgroundBrush}" ExtendsContentIntoTitleBar="True" + WindowBackdropType="Mica" WindowStartupLocation="CenterScreen"> diff --git a/Bloxstrap/UI/Elements/Dialogs/ExceptionDialog.xaml b/Bloxstrap/UI/Elements/Dialogs/ExceptionDialog.xaml index b98372dc4..7f84a2af9 100644 --- a/Bloxstrap/UI/Elements/Dialogs/ExceptionDialog.xaml +++ b/Bloxstrap/UI/Elements/Dialogs/ExceptionDialog.xaml @@ -16,6 +16,7 @@ SizeToContent="Height" Background="{ui:ThemeResource ApplicationBackgroundBrush}" ExtendsContentIntoTitleBar="True" + WindowBackdropType="Mica" WindowStartupLocation="CenterScreen"> diff --git a/Bloxstrap/UI/Elements/Dialogs/FluentMessageBox.xaml b/Bloxstrap/UI/Elements/Dialogs/FluentMessageBox.xaml index 3d3ec62da..a13fcc74c 100644 --- a/Bloxstrap/UI/Elements/Dialogs/FluentMessageBox.xaml +++ b/Bloxstrap/UI/Elements/Dialogs/FluentMessageBox.xaml @@ -18,6 +18,7 @@ ResizeMode="NoResize" Background="{ui:ThemeResource ApplicationBackgroundBrush}" ExtendsContentIntoTitleBar="True" + WindowBackdropType="Mica" WindowStartupLocation="CenterScreen"> diff --git a/Bloxstrap/UI/Elements/Dialogs/LanguageSelectorDialog.xaml b/Bloxstrap/UI/Elements/Dialogs/LanguageSelectorDialog.xaml index ab9d48e4a..9a3906aec 100644 --- a/Bloxstrap/UI/Elements/Dialogs/LanguageSelectorDialog.xaml +++ b/Bloxstrap/UI/Elements/Dialogs/LanguageSelectorDialog.xaml @@ -16,6 +16,7 @@ ResizeMode="NoResize" Background="{ui:ThemeResource ApplicationBackgroundBrush}" ExtendsContentIntoTitleBar="True" + WindowBackdropType="Mica" WindowStartupLocation="CenterScreen"> diff --git a/Bloxstrap/UI/Elements/Dialogs/LaunchMenuDialog.xaml b/Bloxstrap/UI/Elements/Dialogs/LaunchMenuDialog.xaml index 7388f73ab..f69a65d8f 100644 --- a/Bloxstrap/UI/Elements/Dialogs/LaunchMenuDialog.xaml +++ b/Bloxstrap/UI/Elements/Dialogs/LaunchMenuDialog.xaml @@ -17,6 +17,7 @@ ResizeMode="NoResize" Background="{ui:ThemeResource ApplicationBackgroundBrush}" ExtendsContentIntoTitleBar="True" + WindowBackdropType="Mica" WindowStartupLocation="CenterScreen"> diff --git a/Bloxstrap/UI/Elements/Dialogs/UninstallerDialog.xaml b/Bloxstrap/UI/Elements/Dialogs/UninstallerDialog.xaml index 4bc15469e..183692d4d 100644 --- a/Bloxstrap/UI/Elements/Dialogs/UninstallerDialog.xaml +++ b/Bloxstrap/UI/Elements/Dialogs/UninstallerDialog.xaml @@ -19,6 +19,7 @@ ResizeMode="NoResize" Background="{ui:ThemeResource ApplicationBackgroundBrush}" ExtendsContentIntoTitleBar="True" + WindowBackdropType="Mica" WindowStartupLocation="CenterScreen">