From 1774e8ee73f5a674e7047486a448d385ce8031d1 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 12 Dec 2025 17:04:12 +0000 Subject: [PATCH 01/17] Initial plan From 5e1c6c3faed738f7a2a2c109d1d81b0006132639 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 12 Dec 2025 17:07:17 +0000 Subject: [PATCH 02/17] Add dark mode theme handling Co-authored-by: mrbbbaixue <17956756+mrbbbaixue@users.noreply.github.com> --- Ra3.BattleNet.Downloader/MainWindow.xaml.cs | 30 +++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/Ra3.BattleNet.Downloader/MainWindow.xaml.cs b/Ra3.BattleNet.Downloader/MainWindow.xaml.cs index 02ada2f..48cc055 100644 --- a/Ra3.BattleNet.Downloader/MainWindow.xaml.cs +++ b/Ra3.BattleNet.Downloader/MainWindow.xaml.cs @@ -1,4 +1,6 @@ using System.Windows; +using System.Windows.Media; +using Microsoft.Win32; namespace Ra3.BattleNet.Downloader; @@ -10,6 +12,7 @@ public partial class MainWindow : Window public MainWindow() { InitializeComponent(); + ApplySystemTheme(); ChangeLanguage(chinese: true); } @@ -35,4 +38,31 @@ private void Hyperlink_Click(object sender, RoutedEventArgs e) { Download.OpenAndLocateFile(Download.DownloadPath); } + + private void ApplySystemTheme() + { + if (!IsSystemInDarkMode()) + { + return; + } + + Background = Brushes.Black; + Foreground = Brushes.White; + DownloadProgressBar.Background = Brushes.Black; + DownloadProgressBar.Foreground = Brushes.White; + } + + private static bool IsSystemInDarkMode() + { + try + { + using var personalize = Registry.CurrentUser.OpenSubKey(@"Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize"); + var appsUseLightTheme = personalize?.GetValue("AppsUseLightTheme"); + return appsUseLightTheme is int value && value == 0; + } + catch + { + return false; + } + } } From ad91c790ed6f09b558c64fb10166a639f2da24e6 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 12 Dec 2025 17:08:19 +0000 Subject: [PATCH 03/17] Refine dark mode handling Co-authored-by: mrbbbaixue <17956756+mrbbbaixue@users.noreply.github.com> --- Ra3.BattleNet.Downloader/MainWindow.xaml.cs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Ra3.BattleNet.Downloader/MainWindow.xaml.cs b/Ra3.BattleNet.Downloader/MainWindow.xaml.cs index 48cc055..0b095f3 100644 --- a/Ra3.BattleNet.Downloader/MainWindow.xaml.cs +++ b/Ra3.BattleNet.Downloader/MainWindow.xaml.cs @@ -1,4 +1,5 @@ -using System.Windows; +using System.Diagnostics; +using System.Windows; using System.Windows.Media; using Microsoft.Win32; @@ -39,6 +40,8 @@ private void Hyperlink_Click(object sender, RoutedEventArgs e) Download.OpenAndLocateFile(Download.DownloadPath); } + private const string PersonalizeRegistryKeyPath = @"Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize"; + private void ApplySystemTheme() { if (!IsSystemInDarkMode()) @@ -49,19 +52,19 @@ private void ApplySystemTheme() Background = Brushes.Black; Foreground = Brushes.White; DownloadProgressBar.Background = Brushes.Black; - DownloadProgressBar.Foreground = Brushes.White; } private static bool IsSystemInDarkMode() { try { - using var personalize = Registry.CurrentUser.OpenSubKey(@"Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize"); + using var personalize = Registry.CurrentUser.OpenSubKey(PersonalizeRegistryKeyPath); var appsUseLightTheme = personalize?.GetValue("AppsUseLightTheme"); return appsUseLightTheme is int value && value == 0; } - catch + catch (Exception ex) { + Debug.WriteLine(ex); return false; } } From 0ec512ed518d5ab56de00c6bb550f3be80211e6c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 12 Dec 2025 17:09:03 +0000 Subject: [PATCH 04/17] Tidy dark mode registry handling Co-authored-by: mrbbbaixue <17956756+mrbbbaixue@users.noreply.github.com> --- Ra3.BattleNet.Downloader/MainWindow.xaml.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Ra3.BattleNet.Downloader/MainWindow.xaml.cs b/Ra3.BattleNet.Downloader/MainWindow.xaml.cs index 0b095f3..20d59d6 100644 --- a/Ra3.BattleNet.Downloader/MainWindow.xaml.cs +++ b/Ra3.BattleNet.Downloader/MainWindow.xaml.cs @@ -40,7 +40,7 @@ private void Hyperlink_Click(object sender, RoutedEventArgs e) Download.OpenAndLocateFile(Download.DownloadPath); } - private const string PersonalizeRegistryKeyPath = @"Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize"; + private const string PersonalizeRegistryKeyPath = @"Software\Microsoft\Windows\CurrentVersion\Themes\Personalize"; private void ApplySystemTheme() { @@ -64,7 +64,7 @@ private static bool IsSystemInDarkMode() } catch (Exception ex) { - Debug.WriteLine(ex); + Debug.WriteLine($"Failed to read dark mode registry setting: {ex}"); return false; } } From de1d09d9960de7f1f586c1473f05346576334030 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 12 Dec 2025 17:09:42 +0000 Subject: [PATCH 05/17] Handle registry errors explicitly Co-authored-by: mrbbbaixue <17956756+mrbbbaixue@users.noreply.github.com> --- Ra3.BattleNet.Downloader/MainWindow.xaml.cs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/Ra3.BattleNet.Downloader/MainWindow.xaml.cs b/Ra3.BattleNet.Downloader/MainWindow.xaml.cs index 20d59d6..a427e80 100644 --- a/Ra3.BattleNet.Downloader/MainWindow.xaml.cs +++ b/Ra3.BattleNet.Downloader/MainWindow.xaml.cs @@ -1,4 +1,5 @@ using System.Diagnostics; +using System.Security; using System.Windows; using System.Windows.Media; using Microsoft.Win32; @@ -10,6 +11,8 @@ namespace Ra3.BattleNet.Downloader; /// public partial class MainWindow : Window { + private const string PersonalizeRegistryKeyPath = @"Software\Microsoft\Windows\CurrentVersion\Themes\Personalize"; + public MainWindow() { InitializeComponent(); @@ -40,8 +43,6 @@ private void Hyperlink_Click(object sender, RoutedEventArgs e) Download.OpenAndLocateFile(Download.DownloadPath); } - private const string PersonalizeRegistryKeyPath = @"Software\Microsoft\Windows\CurrentVersion\Themes\Personalize"; - private void ApplySystemTheme() { if (!IsSystemInDarkMode()) @@ -62,7 +63,17 @@ private static bool IsSystemInDarkMode() var appsUseLightTheme = personalize?.GetValue("AppsUseLightTheme"); return appsUseLightTheme is int value && value == 0; } - catch (Exception ex) + catch (SecurityException ex) + { + Debug.WriteLine($"Failed to read dark mode registry setting: {ex}"); + return false; + } + catch (UnauthorizedAccessException ex) + { + Debug.WriteLine($"Failed to read dark mode registry setting: {ex}"); + return false; + } + catch (ArgumentException ex) { Debug.WriteLine($"Failed to read dark mode registry setting: {ex}"); return false; From 7af635cc0e0f21d0191ef759ce90ccaacb5d4448 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 12 Dec 2025 17:10:16 +0000 Subject: [PATCH 06/17] Consolidate theme error handling Co-authored-by: mrbbbaixue <17956756+mrbbbaixue@users.noreply.github.com> --- Ra3.BattleNet.Downloader/MainWindow.xaml.cs | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/Ra3.BattleNet.Downloader/MainWindow.xaml.cs b/Ra3.BattleNet.Downloader/MainWindow.xaml.cs index a427e80..ec3fa11 100644 --- a/Ra3.BattleNet.Downloader/MainWindow.xaml.cs +++ b/Ra3.BattleNet.Downloader/MainWindow.xaml.cs @@ -52,7 +52,10 @@ private void ApplySystemTheme() Background = Brushes.Black; Foreground = Brushes.White; - DownloadProgressBar.Background = Brushes.Black; + if (DownloadProgressBar != null) + { + DownloadProgressBar.Background = Brushes.Black; + } } private static bool IsSystemInDarkMode() @@ -63,17 +66,7 @@ private static bool IsSystemInDarkMode() var appsUseLightTheme = personalize?.GetValue("AppsUseLightTheme"); return appsUseLightTheme is int value && value == 0; } - catch (SecurityException ex) - { - Debug.WriteLine($"Failed to read dark mode registry setting: {ex}"); - return false; - } - catch (UnauthorizedAccessException ex) - { - Debug.WriteLine($"Failed to read dark mode registry setting: {ex}"); - return false; - } - catch (ArgumentException ex) + catch (Exception ex) when (ex is SecurityException || ex is UnauthorizedAccessException || ex is ArgumentException) { Debug.WriteLine($"Failed to read dark mode registry setting: {ex}"); return false; From 6d0c5c204a3504ec9c9f21722d0423b94a8d95aa Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 12 Dec 2025 17:10:59 +0000 Subject: [PATCH 07/17] Broaden registry exception filter Co-authored-by: mrbbbaixue <17956756+mrbbbaixue@users.noreply.github.com> --- Ra3.BattleNet.Downloader/MainWindow.xaml.cs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Ra3.BattleNet.Downloader/MainWindow.xaml.cs b/Ra3.BattleNet.Downloader/MainWindow.xaml.cs index ec3fa11..e4b50f1 100644 --- a/Ra3.BattleNet.Downloader/MainWindow.xaml.cs +++ b/Ra3.BattleNet.Downloader/MainWindow.xaml.cs @@ -1,4 +1,5 @@ using System.Diagnostics; +using System.IO; using System.Security; using System.Windows; using System.Windows.Media; @@ -52,10 +53,7 @@ private void ApplySystemTheme() Background = Brushes.Black; Foreground = Brushes.White; - if (DownloadProgressBar != null) - { - DownloadProgressBar.Background = Brushes.Black; - } + DownloadProgressBar.Background = Brushes.Black; } private static bool IsSystemInDarkMode() @@ -66,7 +64,11 @@ private static bool IsSystemInDarkMode() var appsUseLightTheme = personalize?.GetValue("AppsUseLightTheme"); return appsUseLightTheme is int value && value == 0; } - catch (Exception ex) when (ex is SecurityException || ex is UnauthorizedAccessException || ex is ArgumentException) + catch (Exception ex) when (ex is SecurityException + or UnauthorizedAccessException + or ArgumentException + or ObjectDisposedException + or IOException) { Debug.WriteLine($"Failed to read dark mode registry setting: {ex}"); return false; From d5b8c3fa350e51c52d4e5cc7802ffc47da3d23fa Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 12 Dec 2025 17:11:32 +0000 Subject: [PATCH 08/17] Simplify registry exception filter Co-authored-by: mrbbbaixue <17956756+mrbbbaixue@users.noreply.github.com> --- Ra3.BattleNet.Downloader/MainWindow.xaml.cs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Ra3.BattleNet.Downloader/MainWindow.xaml.cs b/Ra3.BattleNet.Downloader/MainWindow.xaml.cs index e4b50f1..cb1d566 100644 --- a/Ra3.BattleNet.Downloader/MainWindow.xaml.cs +++ b/Ra3.BattleNet.Downloader/MainWindow.xaml.cs @@ -1,5 +1,4 @@ using System.Diagnostics; -using System.IO; using System.Security; using System.Windows; using System.Windows.Media; @@ -66,9 +65,7 @@ private static bool IsSystemInDarkMode() } catch (Exception ex) when (ex is SecurityException or UnauthorizedAccessException - or ArgumentException - or ObjectDisposedException - or IOException) + or ArgumentException) { Debug.WriteLine($"Failed to read dark mode registry setting: {ex}"); return false; From 436c750646a5520dee26979336ea0a1cec2ed78c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 12 Dec 2025 17:12:10 +0000 Subject: [PATCH 09/17] Clarify registry access handling Co-authored-by: mrbbbaixue <17956756+mrbbbaixue@users.noreply.github.com> --- Ra3.BattleNet.Downloader/MainWindow.xaml.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Ra3.BattleNet.Downloader/MainWindow.xaml.cs b/Ra3.BattleNet.Downloader/MainWindow.xaml.cs index cb1d566..7c98540 100644 --- a/Ra3.BattleNet.Downloader/MainWindow.xaml.cs +++ b/Ra3.BattleNet.Downloader/MainWindow.xaml.cs @@ -1,4 +1,5 @@ using System.Diagnostics; +using System.IO; using System.Security; using System.Windows; using System.Windows.Media; @@ -60,12 +61,19 @@ private static bool IsSystemInDarkMode() try { using var personalize = Registry.CurrentUser.OpenSubKey(PersonalizeRegistryKeyPath); - var appsUseLightTheme = personalize?.GetValue("AppsUseLightTheme"); + if (personalize is null) + { + return false; + } + + var appsUseLightTheme = personalize.GetValue("AppsUseLightTheme"); return appsUseLightTheme is int value && value == 0; } catch (Exception ex) when (ex is SecurityException or UnauthorizedAccessException - or ArgumentException) + or ArgumentException + or ObjectDisposedException + or IOException) { Debug.WriteLine($"Failed to read dark mode registry setting: {ex}"); return false; From ef9edcd0d34c255d44a7076adf9dd2ba07443860 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 12 Dec 2025 17:13:00 +0000 Subject: [PATCH 10/17] Extract theme brushes and clarify logging Co-authored-by: mrbbbaixue <17956756+mrbbbaixue@users.noreply.github.com> --- Ra3.BattleNet.Downloader/MainWindow.xaml.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Ra3.BattleNet.Downloader/MainWindow.xaml.cs b/Ra3.BattleNet.Downloader/MainWindow.xaml.cs index 7c98540..529ee53 100644 --- a/Ra3.BattleNet.Downloader/MainWindow.xaml.cs +++ b/Ra3.BattleNet.Downloader/MainWindow.xaml.cs @@ -13,6 +13,8 @@ namespace Ra3.BattleNet.Downloader; public partial class MainWindow : Window { private const string PersonalizeRegistryKeyPath = @"Software\Microsoft\Windows\CurrentVersion\Themes\Personalize"; + private static readonly Brush DarkBackgroundBrush = Brushes.Black; + private static readonly Brush DarkForegroundBrush = Brushes.White; public MainWindow() { @@ -51,9 +53,9 @@ private void ApplySystemTheme() return; } - Background = Brushes.Black; - Foreground = Brushes.White; - DownloadProgressBar.Background = Brushes.Black; + Background = DarkBackgroundBrush; + Foreground = DarkForegroundBrush; + DownloadProgressBar.Background = DarkBackgroundBrush; } private static bool IsSystemInDarkMode() @@ -75,7 +77,7 @@ or ArgumentException or ObjectDisposedException or IOException) { - Debug.WriteLine($"Failed to read dark mode registry setting: {ex}"); + Debug.WriteLine($"Failed to read dark mode registry setting, falling back to light mode: {ex}"); return false; } } From 50140cb1784674ea510b776f8993778ed400df29 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 12 Dec 2025 17:13:36 +0000 Subject: [PATCH 11/17] Add registry value constant and log key path Co-authored-by: mrbbbaixue <17956756+mrbbbaixue@users.noreply.github.com> --- Ra3.BattleNet.Downloader/MainWindow.xaml.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Ra3.BattleNet.Downloader/MainWindow.xaml.cs b/Ra3.BattleNet.Downloader/MainWindow.xaml.cs index 529ee53..83b4148 100644 --- a/Ra3.BattleNet.Downloader/MainWindow.xaml.cs +++ b/Ra3.BattleNet.Downloader/MainWindow.xaml.cs @@ -13,6 +13,7 @@ namespace Ra3.BattleNet.Downloader; public partial class MainWindow : Window { private const string PersonalizeRegistryKeyPath = @"Software\Microsoft\Windows\CurrentVersion\Themes\Personalize"; + private const int DarkModeRegistryValue = 0; private static readonly Brush DarkBackgroundBrush = Brushes.Black; private static readonly Brush DarkForegroundBrush = Brushes.White; @@ -69,7 +70,7 @@ private static bool IsSystemInDarkMode() } var appsUseLightTheme = personalize.GetValue("AppsUseLightTheme"); - return appsUseLightTheme is int value && value == 0; + return appsUseLightTheme is int value && value == DarkModeRegistryValue; } catch (Exception ex) when (ex is SecurityException or UnauthorizedAccessException @@ -77,7 +78,7 @@ or ArgumentException or ObjectDisposedException or IOException) { - Debug.WriteLine($"Failed to read dark mode registry setting, falling back to light mode: {ex}"); + Debug.WriteLine($"Failed to read dark mode registry setting from {PersonalizeRegistryKeyPath}, falling back to light mode: {ex}"); return false; } } From 0c0c5d6479c7dc11ef6812dbd456dd3fffe71ea0 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 12 Dec 2025 17:14:14 +0000 Subject: [PATCH 12/17] Clarify dark mode registry value comment Co-authored-by: mrbbbaixue <17956756+mrbbbaixue@users.noreply.github.com> --- Ra3.BattleNet.Downloader/MainWindow.xaml.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Ra3.BattleNet.Downloader/MainWindow.xaml.cs b/Ra3.BattleNet.Downloader/MainWindow.xaml.cs index 83b4148..1cd998c 100644 --- a/Ra3.BattleNet.Downloader/MainWindow.xaml.cs +++ b/Ra3.BattleNet.Downloader/MainWindow.xaml.cs @@ -13,7 +13,7 @@ namespace Ra3.BattleNet.Downloader; public partial class MainWindow : Window { private const string PersonalizeRegistryKeyPath = @"Software\Microsoft\Windows\CurrentVersion\Themes\Personalize"; - private const int DarkModeRegistryValue = 0; + private const int DarkModeRegistryValue = 0; // 0 means AppsUseLightTheme is disabled (dark mode) private static readonly Brush DarkBackgroundBrush = Brushes.Black; private static readonly Brush DarkForegroundBrush = Brushes.White; From a9ef689f210e08fa41bf2acd774f2b919cf22dbf Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 12 Dec 2025 17:14:47 +0000 Subject: [PATCH 13/17] Reword dark mode registry comment Co-authored-by: mrbbbaixue <17956756+mrbbbaixue@users.noreply.github.com> --- Ra3.BattleNet.Downloader/MainWindow.xaml.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Ra3.BattleNet.Downloader/MainWindow.xaml.cs b/Ra3.BattleNet.Downloader/MainWindow.xaml.cs index 1cd998c..d472776 100644 --- a/Ra3.BattleNet.Downloader/MainWindow.xaml.cs +++ b/Ra3.BattleNet.Downloader/MainWindow.xaml.cs @@ -13,7 +13,7 @@ namespace Ra3.BattleNet.Downloader; public partial class MainWindow : Window { private const string PersonalizeRegistryKeyPath = @"Software\Microsoft\Windows\CurrentVersion\Themes\Personalize"; - private const int DarkModeRegistryValue = 0; // 0 means AppsUseLightTheme is disabled (dark mode) + private const int DarkModeRegistryValue = 0; // 0 means AppsUseLightTheme is false (dark mode enabled) private static readonly Brush DarkBackgroundBrush = Brushes.Black; private static readonly Brush DarkForegroundBrush = Brushes.White; From deb3af575c90fdb4efb99b6ab528d92400e9292b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 12 Dec 2025 17:15:24 +0000 Subject: [PATCH 14/17] Adjust comment and debug logging guard Co-authored-by: mrbbbaixue <17956756+mrbbbaixue@users.noreply.github.com> --- Ra3.BattleNet.Downloader/MainWindow.xaml.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Ra3.BattleNet.Downloader/MainWindow.xaml.cs b/Ra3.BattleNet.Downloader/MainWindow.xaml.cs index d472776..0591c05 100644 --- a/Ra3.BattleNet.Downloader/MainWindow.xaml.cs +++ b/Ra3.BattleNet.Downloader/MainWindow.xaml.cs @@ -13,7 +13,7 @@ namespace Ra3.BattleNet.Downloader; public partial class MainWindow : Window { private const string PersonalizeRegistryKeyPath = @"Software\Microsoft\Windows\CurrentVersion\Themes\Personalize"; - private const int DarkModeRegistryValue = 0; // 0 means AppsUseLightTheme is false (dark mode enabled) + private const int DarkModeRegistryValue = 0; // 0 indicates dark mode is enabled (AppsUseLightTheme registry value is 0) private static readonly Brush DarkBackgroundBrush = Brushes.Black; private static readonly Brush DarkForegroundBrush = Brushes.White; @@ -78,7 +78,9 @@ or ArgumentException or ObjectDisposedException or IOException) { +#if DEBUG Debug.WriteLine($"Failed to read dark mode registry setting from {PersonalizeRegistryKeyPath}, falling back to light mode: {ex}"); +#endif return false; } } From add1c65f48c967ac15ae3a77ab0857e1b59721b8 Mon Sep 17 00:00:00 2001 From: mrbbbaixue Date: Sat, 13 Dec 2025 01:18:07 +0800 Subject: [PATCH 15/17] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=BC=96=E8=AF=91?= =?UTF-8?q?=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Ra3.BattleNet.Downloader/MainWindow.xaml.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Ra3.BattleNet.Downloader/MainWindow.xaml.cs b/Ra3.BattleNet.Downloader/MainWindow.xaml.cs index 0591c05..9288f30 100644 --- a/Ra3.BattleNet.Downloader/MainWindow.xaml.cs +++ b/Ra3.BattleNet.Downloader/MainWindow.xaml.cs @@ -1,4 +1,5 @@ -using System.Diagnostics; +using System; +using System.Diagnostics; using System.IO; using System.Security; using System.Windows; @@ -30,6 +31,7 @@ private async void Window_Loaded(object sender, RoutedEventArgs e) } private void ChineseCheckbox_Checked(object sender, RoutedEventArgs e) => ChangeLanguage(chinese: true); + private void EnglishCheckbox_Checked(object sender, RoutedEventArgs e) => ChangeLanguage(chinese: false); private void ChangeLanguage(bool chinese) @@ -84,4 +86,4 @@ or ObjectDisposedException return false; } } -} +} \ No newline at end of file From 05eae9b72d4dff7adec8096e404a3d1db126b202 Mon Sep 17 00:00:00 2001 From: mrbbbaixue Date: Sat, 13 Dec 2025 01:33:54 +0800 Subject: [PATCH 16/17] =?UTF-8?q?=E8=B0=83=E6=88=90=E7=81=B0=E8=89=B2?= =?UTF-8?q?=E8=83=8C=E6=99=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Ra3.BattleNet.Downloader/MainWindow.xaml.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Ra3.BattleNet.Downloader/MainWindow.xaml.cs b/Ra3.BattleNet.Downloader/MainWindow.xaml.cs index 9288f30..8670ef7 100644 --- a/Ra3.BattleNet.Downloader/MainWindow.xaml.cs +++ b/Ra3.BattleNet.Downloader/MainWindow.xaml.cs @@ -15,7 +15,7 @@ public partial class MainWindow : Window { private const string PersonalizeRegistryKeyPath = @"Software\Microsoft\Windows\CurrentVersion\Themes\Personalize"; private const int DarkModeRegistryValue = 0; // 0 indicates dark mode is enabled (AppsUseLightTheme registry value is 0) - private static readonly Brush DarkBackgroundBrush = Brushes.Black; + private static readonly Brush DarkBackgroundBrush = new SolidColorBrush(Color.FromRgb(0x19, 0x19, 0x19)); private static readonly Brush DarkForegroundBrush = Brushes.White; public MainWindow() @@ -59,6 +59,8 @@ private void ApplySystemTheme() Background = DarkBackgroundBrush; Foreground = DarkForegroundBrush; DownloadProgressBar.Background = DarkBackgroundBrush; + ChineseCheckbox.Foreground = DarkForegroundBrush; + EnglishCheckbox.Foreground = DarkForegroundBrush; } private static bool IsSystemInDarkMode() From 13915aae5b475615695ebf34347acdb656bf98c0 Mon Sep 17 00:00:00 2001 From: mrbbbaixue Date: Sat, 13 Dec 2025 01:48:58 +0800 Subject: [PATCH 17/17] Update MainWindow.xaml.cs --- Ra3.BattleNet.Downloader/MainWindow.xaml.cs | 96 +++++++++++++++++++-- 1 file changed, 91 insertions(+), 5 deletions(-) diff --git a/Ra3.BattleNet.Downloader/MainWindow.xaml.cs b/Ra3.BattleNet.Downloader/MainWindow.xaml.cs index 8670ef7..7447367 100644 --- a/Ra3.BattleNet.Downloader/MainWindow.xaml.cs +++ b/Ra3.BattleNet.Downloader/MainWindow.xaml.cs @@ -2,7 +2,9 @@ using System.Diagnostics; using System.IO; using System.Security; +using System.Runtime.InteropServices; using System.Windows; +using System.Windows.Interop; using System.Windows.Media; using Microsoft.Win32; @@ -25,6 +27,15 @@ public MainWindow() ChangeLanguage(chinese: true); } + protected override void OnSourceInitialized(EventArgs e) + { + base.OnSourceInitialized(e); + if (IsSystemInDarkMode()) + { + TrySetDarkTitleBar(); + } + } + private async void Window_Loaded(object sender, RoutedEventArgs e) { await Download.BitTorrentDownload((ViewModel)DataContext); @@ -56,11 +67,18 @@ private void ApplySystemTheme() return; } - Background = DarkBackgroundBrush; - Foreground = DarkForegroundBrush; - DownloadProgressBar.Background = DarkBackgroundBrush; - ChineseCheckbox.Foreground = DarkForegroundBrush; - EnglishCheckbox.Foreground = DarkForegroundBrush; + try + { + Background = DarkBackgroundBrush; + Foreground = DarkForegroundBrush; + DownloadProgressBar.Background = DarkBackgroundBrush; + ChineseCheckbox.Foreground = DarkForegroundBrush; + EnglishCheckbox.Foreground = DarkForegroundBrush; + } + catch + { + // If dark mode application fails, just continue with default colors + } } private static bool IsSystemInDarkMode() @@ -88,4 +106,72 @@ or ObjectDisposedException return false; } } + + // Enable dark title bar (non-client area) for Windows 10 1809+ when dark mode is active. + // Returns true if dark title bar was successfully applied, false otherwise. + private bool TrySetDarkTitleBar() + { + try + { + var handle = new WindowInteropHelper(this).Handle; + if (handle == IntPtr.Zero) + { + return false; + } + + // Get real Windows build from registry (Environment.OSVersion.Build may return compatibility version) + int build = GetWindowsBuild(); + if (build == -1) + { + return false; + } + + // Detect Windows build: 17763 (1809) supports attribute 19, 18362+ (1903) supports 20 + var attribute = build >= 18362 ? DWMWA_USE_IMMERSIVE_DARK_MODE : (build >= 17763 ? DWMWA_USE_IMMERSIVE_DARK_MODE_BEFORE_1903 : -1); + if (attribute == -1) + { + return false; + } + + int useDark = 1; + int result = DwmSetWindowAttribute(handle, attribute, ref useDark, sizeof(int)); + + // S_OK = 0, anything else is failure + return result == 0; + } + catch + { + return false; + } + } + + private static int GetWindowsBuild() + { + try + { + using var key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion"); + if (key is null) + { + return -1; + } + + var buildValue = key.GetValue("CurrentBuildNumber"); + if (buildValue is string buildStr && int.TryParse(buildStr, out int build)) + { + return build; + } + + return -1; + } + catch + { + return -1; + } + } + + private const int DWMWA_USE_IMMERSIVE_DARK_MODE = 20; + private const int DWMWA_USE_IMMERSIVE_DARK_MODE_BEFORE_1903 = 19; + + [DllImport("dwmapi.dll")] + private static extern int DwmSetWindowAttribute(IntPtr hwnd, int dwAttribute, ref int pvAttribute, int cbAttribute); } \ No newline at end of file