From 54888b4e306734cb371be16cbf9bccf9ea819c99 Mon Sep 17 00:00:00 2001 From: rjindael Date: Sun, 4 Sep 2022 14:54:14 -0700 Subject: [PATCH] Match system theme Automatically match Bloxstrap's theme to progress light/dark mode based on system default app theme --- Bloxstrap/Dialogs/Preferences.cs | 1 + Bloxstrap/Enums/BootstrapperStyle.cs | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/Bloxstrap/Dialogs/Preferences.cs b/Bloxstrap/Dialogs/Preferences.cs index 1e9d8ab..2a4a34e 100644 --- a/Bloxstrap/Dialogs/Preferences.cs +++ b/Bloxstrap/Dialogs/Preferences.cs @@ -20,6 +20,7 @@ namespace Bloxstrap.Dialogs { "Legacy (2011 - 2014)", BootstrapperStyle.LegacyDialog2011 }, { "Progress (~2014)", BootstrapperStyle.ProgressDialog }, { "Progress (Dark)", BootstrapperStyle.ProgressDialogDark }, + { "Match system theme", BootstrapperStyle.SystemTheme } }; private static readonly IReadOnlyDictionary SelectableIcons = new Dictionary() diff --git a/Bloxstrap/Enums/BootstrapperStyle.cs b/Bloxstrap/Enums/BootstrapperStyle.cs index 864c836..321a4ea 100644 --- a/Bloxstrap/Enums/BootstrapperStyle.cs +++ b/Bloxstrap/Enums/BootstrapperStyle.cs @@ -1,4 +1,5 @@ -using Bloxstrap.Dialogs.BootstrapperStyles; +using Microsoft.Win32; +using Bloxstrap.Dialogs.BootstrapperStyles; namespace Bloxstrap.Enums { @@ -9,6 +10,7 @@ namespace Bloxstrap.Enums LegacyDialog2011, ProgressDialog, ProgressDialogDark, + SystemTheme, } public static class BootstrapperStyleEx @@ -39,6 +41,20 @@ namespace Bloxstrap.Enums case BootstrapperStyle.ProgressDialogDark: dialog = new ProgressDialogDark(bootstrapper); break; + + case BootstrapperStyle.SystemTheme: + bool darkMode = false; + using (RegistryKey? key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Themes\Personalize")) + { + var value = key?.GetValue("AppsUseLightTheme"); + if (value != null) + { + darkMode = (int)value <= 0; + } + } + + dialog = !darkMode ? new ProgressDialog(bootstrapper) : new ProgressDialogDark(bootstrapper); + break; } if (bootstrapper is null)