From fe8f73afb89ccd9b297ec89e7ed9c7b63b0a35ae Mon Sep 17 00:00:00 2001 From: Space Time Date: Tue, 3 Dec 2024 23:41:25 +0800 Subject: [PATCH] =?UTF-8?q?1.1.3=20->=201.1.4=20=E7=AC=AC24=E6=AC=A1?= =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Consts/SettingsMultilangConst.zh.resx | 4 ++-- Preses/GlobalPres.cs | 18 +++++++++++++++++- Props/Settings.Designer.cs | 14 +++++++++++++- Props/Settings.settings | 3 +++ Utils/BorderThemeSetter.cs | 3 +++ 5 files changed, 38 insertions(+), 4 deletions(-) diff --git a/Consts/SettingsMultilangConst.zh.resx b/Consts/SettingsMultilangConst.zh.resx index b5df3c1..4fa03e9 100644 --- a/Consts/SettingsMultilangConst.zh.resx +++ b/Consts/SettingsMultilangConst.zh.resx @@ -98,13 +98,13 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - 跟随系统 + 亮色模式 暗色模式 - 亮色模式 + 跟随系统 点击切换显示主题 diff --git a/Preses/GlobalPres.cs b/Preses/GlobalPres.cs index c02deb0..e8fdf70 100644 --- a/Preses/GlobalPres.cs +++ b/Preses/GlobalPres.cs @@ -1,12 +1,25 @@ -using System.Windows; +using System.Diagnostics; +using System.Windows; using CommunityToolkit.Mvvm.ComponentModel; using MaterialDesignThemes.Wpf; +using Sheas_Cealer.Props; using Sheas_Cealer.Utils; namespace Sheas_Cealer.Preses; internal partial class GlobalPres : ObservableObject { + internal GlobalPres() + { + IsLightTheme = Settings.Default.IsLightTheme switch + { + -1 => null, + 0 => false, + 1 => true, + _ => throw new UnreachableException() + }; + } + [ObservableProperty] private static bool? isLightTheme = null; partial void OnIsLightThemeChanged(bool? value) @@ -19,5 +32,8 @@ internal partial class GlobalPres : ObservableObject foreach (Window currentWindow in Application.Current.Windows) BorderThemeSetter.SetBorderTheme(currentWindow, value); + + Settings.Default.IsLightTheme = (sbyte)(value.HasValue ? value.GetValueOrDefault() ? 1 : 0 : -1); + Settings.Default.Save(); } } \ No newline at end of file diff --git a/Props/Settings.Designer.cs b/Props/Settings.Designer.cs index 4166d68..2de53ce 100644 --- a/Props/Settings.Designer.cs +++ b/Props/Settings.Designer.cs @@ -12,7 +12,7 @@ namespace Sheas_Cealer.Props { [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.10.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.12.0.0")] internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); @@ -58,5 +58,17 @@ namespace Sheas_Cealer.Props { this["ExtraArgs"] = value; } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("-1")] + public sbyte IsLightTheme { + get { + return ((sbyte)(this["IsLightTheme"])); + } + set { + this["IsLightTheme"] = value; + } + } } } diff --git a/Props/Settings.settings b/Props/Settings.settings index ae75391..61b1d77 100644 --- a/Props/Settings.settings +++ b/Props/Settings.settings @@ -11,5 +11,8 @@ + + -1 + \ No newline at end of file diff --git a/Utils/BorderThemeSetter.cs b/Utils/BorderThemeSetter.cs index 80d7bdf..0e017df 100644 --- a/Utils/BorderThemeSetter.cs +++ b/Utils/BorderThemeSetter.cs @@ -16,6 +16,9 @@ internal static partial class BorderThemeSetter internal static void SetBorderTheme(Window window, bool? isLightTheme) { + if (!window.IsLoaded) + return; + nint isDarkTheme; nint desktopHwnd = nint.Zero; nint windowHwnd = new WindowInteropHelper(window).EnsureHandle();