From caa5a4825de6d96a00b19eef9884fb9680b721c5 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Fri, 14 Mar 2025 13:32:46 +0800 Subject: [PATCH 1/3] Use enum instead of constants & Use vm property --- Flow.Launcher.Core/Resource/Theme.cs | 2 +- Flow.Launcher.Infrastructure/Constant.cs | 4 ---- .../UserSettings/Settings.cs | 2 +- Flow.Launcher/MainWindow.xaml.cs | 4 ++-- .../ViewModels/SettingsPaneThemeViewModel.cs | 23 ++++++++++++++----- .../SettingPages/Views/SettingsPaneTheme.xaml | 5 ++-- .../Views/SettingsPaneTheme.xaml.cs | 8 ------- 7 files changed, 23 insertions(+), 25 deletions(-) diff --git a/Flow.Launcher.Core/Resource/Theme.cs b/Flow.Launcher.Core/Resource/Theme.cs index da3f9f708..5edf8584c 100644 --- a/Flow.Launcher.Core/Resource/Theme.cs +++ b/Flow.Launcher.Core/Resource/Theme.cs @@ -457,7 +457,7 @@ namespace Flow.Launcher.Core.Resource // ✅ 설정의 ColorScheme을 우선 사용 int themeValue = (int)Registry.GetValue(@"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize", "AppsUseLightTheme", 1); bool isSystemDark = themeValue == 0; - bool useDarkMode = Mode == "Dark" || (Mode == "Auto" && _settings.ColorScheme == "System" && isSystemDark) || (_settings.ColorScheme == "Dark"); + bool useDarkMode = Mode == "Dark" || (Mode == "Auto" && _settings.ColorScheme == ColorSchemes.System && isSystemDark) || (_settings.ColorScheme == ColorSchemes.Dark); Color selectedBG = useDarkMode ? DarkBG : LightBG; ApplyPreviewBackground(selectedBG); diff --git a/Flow.Launcher.Infrastructure/Constant.cs b/Flow.Launcher.Infrastructure/Constant.cs index c86ed4324..8a73b8f05 100644 --- a/Flow.Launcher.Infrastructure/Constant.cs +++ b/Flow.Launcher.Infrastructure/Constant.cs @@ -40,10 +40,6 @@ namespace Flow.Launcher.Infrastructure public const string DefaultTheme = "Win11Light"; - public const string Light = "Light"; - public const string Dark = "Dark"; - public const string System = "System"; - public const string Themes = "Themes"; public const string Settings = "Settings"; public const string Logs = "Logs"; diff --git a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs index 8277e8e0b..1a46282bc 100644 --- a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs +++ b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs @@ -37,7 +37,7 @@ namespace Flow.Launcher.Infrastructure.UserSettings private string _theme = Constant.DefaultTheme; public string Hotkey { get; set; } = $"{KeyConstant.Alt} + {KeyConstant.Space}"; public string OpenResultModifiers { get; set; } = KeyConstant.Alt; - public string ColorScheme { get; set; } = "System"; + public ColorSchemes ColorScheme { get; set; } = ColorSchemes.System; public bool ShowOpenResultHotkey { get; set; } = true; public double WindowSize { get; set; } = 580; public string PreviewHotkey { get; set; } = $"F1"; diff --git a/Flow.Launcher/MainWindow.xaml.cs b/Flow.Launcher/MainWindow.xaml.cs index 9f8063a87..5194e02d0 100644 --- a/Flow.Launcher/MainWindow.xaml.cs +++ b/Flow.Launcher/MainWindow.xaml.cs @@ -998,11 +998,11 @@ namespace Flow.Launcher public void InitializeColorScheme() { - if (_settings.ColorScheme == Constant.Light) + if (_settings.ColorScheme == ColorSchemes.Light) { ModernWpf.ThemeManager.Current.ApplicationTheme = ModernWpf.ApplicationTheme.Light; } - else if (_settings.ColorScheme == Constant.Dark) + else if (_settings.ColorScheme == ColorSchemes.Dark) { ModernWpf.ThemeManager.Current.ApplicationTheme = ModernWpf.ApplicationTheme.Dark; } diff --git a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs index 77b9ab3cf..516e6ca95 100644 --- a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs +++ b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs @@ -15,8 +15,6 @@ using Flow.Launcher.ViewModel; using ModernWpf; using ThemeManager = Flow.Launcher.Core.Resource.ThemeManager; using ThemeManagerForColorSchemeSwitch = ModernWpf.ThemeManager; -using static Flow.Launcher.Core.Resource.Theme; -using System.Windows.Interop; namespace Flow.Launcher.SettingPages.ViewModels; @@ -38,8 +36,11 @@ public partial class SettingsPaneThemeViewModel : BaseModel ThemeManager.Instance.ChangeTheme(value.FileNameWithoutExtension); if (ThemeManager.Instance.BlurEnabled && Settings.UseDropShadowEffect == false) + { DropShadowEffect = true; OnPropertyChanged(nameof(IsDropShadowEnabled)); + } + ThemeManager.Instance.RefreshFrame(); //ThemeManager.Instance.SetBlurForWindow(); } @@ -107,6 +108,16 @@ public partial class SettingsPaneThemeViewModel : BaseModel public class ColorSchemeData : DropdownDataGeneric { } public List ColorSchemes { get; } = DropdownDataGeneric.GetValues("ColorScheme"); + public ColorSchemes ColorScheme + { + get => Settings.ColorScheme; + set + { + UpdateColorScheme(); + + Settings.ColorScheme = value; + } + } public List TimeFormatList { get; } = new() { @@ -463,13 +474,13 @@ public partial class SettingsPaneThemeViewModel : BaseModel App.API.OpenDirectory(Path.Combine(DataLocation.DataDirectory(), Constant.Themes)); } - public void UpdateColorScheme() + private void UpdateColorScheme() { ThemeManagerForColorSchemeSwitch.Current.ApplicationTheme = Settings.ColorScheme switch { - Constant.Light => ApplicationTheme.Light, - Constant.Dark => ApplicationTheme.Dark, - Constant.System => null, + Infrastructure.UserSettings.ColorSchemes.Light => ApplicationTheme.Light, + Infrastructure.UserSettings.ColorSchemes.Dark => ApplicationTheme.Dark, + Infrastructure.UserSettings.ColorSchemes.System => null, _ => ThemeManagerForColorSchemeSwitch.Current.ApplicationTheme }; ThemeManager.Instance.RefreshFrame(); diff --git a/Flow.Launcher/SettingPages/Views/SettingsPaneTheme.xaml b/Flow.Launcher/SettingPages/Views/SettingsPaneTheme.xaml index ec068cb5c..d45556e1d 100644 --- a/Flow.Launcher/SettingPages/Views/SettingsPaneTheme.xaml +++ b/Flow.Launcher/SettingPages/Views/SettingsPaneTheme.xaml @@ -688,9 +688,8 @@ DisplayMemberPath="Display" FontSize="14" ItemsSource="{Binding ColorSchemes}" - SelectedValue="{Binding Settings.ColorScheme}" - SelectedValuePath="Value" - SelectionChanged="Selector_OnSelectionChanged" /> + SelectedValue="{Binding ColorScheme, Mode=TwoWay}" + SelectedValuePath="Value" /> diff --git a/Flow.Launcher/SettingPages/Views/SettingsPaneTheme.xaml.cs b/Flow.Launcher/SettingPages/Views/SettingsPaneTheme.xaml.cs index 7f32728c2..18d3a31a2 100644 --- a/Flow.Launcher/SettingPages/Views/SettingsPaneTheme.xaml.cs +++ b/Flow.Launcher/SettingPages/Views/SettingsPaneTheme.xaml.cs @@ -1,7 +1,4 @@ using System; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Media; using System.Windows.Navigation; using Flow.Launcher.SettingPages.ViewModels; using Page = ModernWpf.Controls.Page; @@ -25,9 +22,4 @@ public partial class SettingsPaneTheme : Page base.OnNavigatedTo(e); } - - private void Selector_OnSelectionChanged(object sender, SelectionChangedEventArgs e) - { - _viewModel.UpdateColorScheme(); - } } From 8484c2b87a38af000683a62d8f01223d34eade1f Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Fri, 14 Mar 2025 13:39:04 +0800 Subject: [PATCH 2/3] Fix color scheme change issue & Code cleanup --- .../ViewModels/SettingsPaneThemeViewModel.cs | 38 ++++++++----------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs index 516e6ca95..e4d047f7a 100644 --- a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs +++ b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs @@ -113,7 +113,15 @@ public partial class SettingsPaneThemeViewModel : BaseModel get => Settings.ColorScheme; set { - UpdateColorScheme(); + ThemeManagerForColorSchemeSwitch.Current.ApplicationTheme = value switch + { + Infrastructure.UserSettings.ColorSchemes.Light => ApplicationTheme.Light, + Infrastructure.UserSettings.ColorSchemes.Dark => ApplicationTheme.Dark, + Infrastructure.UserSettings.ColorSchemes.System => null, + _ => ThemeManagerForColorSchemeSwitch.Current.ApplicationTheme + }; + + ThemeManager.Instance.RefreshFrame(); Settings.ColorScheme = value; } @@ -220,9 +228,8 @@ public partial class SettingsPaneThemeViewModel : BaseModel public BackdropTypes BackdropType { get => Enum.IsDefined(typeof(BackdropTypes), Settings.BackdropType) - ? (BackdropTypes)Settings.BackdropType + ? Settings.BackdropType : BackdropTypes.None; - set { if (!Enum.IsDefined(typeof(BackdropTypes), value)) @@ -241,9 +248,6 @@ public partial class SettingsPaneThemeViewModel : BaseModel } } - - - public bool UseSound { get => Settings.UseSound; @@ -468,29 +472,17 @@ public partial class SettingsPaneThemeViewModel : BaseModel public string ThemeImage => Constant.QueryTextBoxIconImagePath; + public SettingsPaneThemeViewModel(Settings settings) + { + Settings = settings; + } + [RelayCommand] private void OpenThemesFolder() { App.API.OpenDirectory(Path.Combine(DataLocation.DataDirectory(), Constant.Themes)); } - private void UpdateColorScheme() - { - ThemeManagerForColorSchemeSwitch.Current.ApplicationTheme = Settings.ColorScheme switch - { - Infrastructure.UserSettings.ColorSchemes.Light => ApplicationTheme.Light, - Infrastructure.UserSettings.ColorSchemes.Dark => ApplicationTheme.Dark, - Infrastructure.UserSettings.ColorSchemes.System => null, - _ => ThemeManagerForColorSchemeSwitch.Current.ApplicationTheme - }; - ThemeManager.Instance.RefreshFrame(); - } - - public SettingsPaneThemeViewModel(Settings settings) - { - Settings = settings; - } - [RelayCommand] public void Reset() { From c17dcad896dbc43f919eb9676babd052a51d8cef Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Fri, 14 Mar 2025 13:49:26 +0800 Subject: [PATCH 3/3] Revert "Use enum instead of constants" --- Flow.Launcher.Core/Resource/Theme.cs | 2 +- Flow.Launcher.Infrastructure/Constant.cs | 4 ++++ Flow.Launcher.Infrastructure/UserSettings/Settings.cs | 2 +- Flow.Launcher/MainWindow.xaml.cs | 4 ++-- .../SettingPages/ViewModels/SettingsPaneThemeViewModel.cs | 8 ++++---- 5 files changed, 12 insertions(+), 8 deletions(-) diff --git a/Flow.Launcher.Core/Resource/Theme.cs b/Flow.Launcher.Core/Resource/Theme.cs index 5edf8584c..da3f9f708 100644 --- a/Flow.Launcher.Core/Resource/Theme.cs +++ b/Flow.Launcher.Core/Resource/Theme.cs @@ -457,7 +457,7 @@ namespace Flow.Launcher.Core.Resource // ✅ 설정의 ColorScheme을 우선 사용 int themeValue = (int)Registry.GetValue(@"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize", "AppsUseLightTheme", 1); bool isSystemDark = themeValue == 0; - bool useDarkMode = Mode == "Dark" || (Mode == "Auto" && _settings.ColorScheme == ColorSchemes.System && isSystemDark) || (_settings.ColorScheme == ColorSchemes.Dark); + bool useDarkMode = Mode == "Dark" || (Mode == "Auto" && _settings.ColorScheme == "System" && isSystemDark) || (_settings.ColorScheme == "Dark"); Color selectedBG = useDarkMode ? DarkBG : LightBG; ApplyPreviewBackground(selectedBG); diff --git a/Flow.Launcher.Infrastructure/Constant.cs b/Flow.Launcher.Infrastructure/Constant.cs index 8a73b8f05..c86ed4324 100644 --- a/Flow.Launcher.Infrastructure/Constant.cs +++ b/Flow.Launcher.Infrastructure/Constant.cs @@ -40,6 +40,10 @@ namespace Flow.Launcher.Infrastructure public const string DefaultTheme = "Win11Light"; + public const string Light = "Light"; + public const string Dark = "Dark"; + public const string System = "System"; + public const string Themes = "Themes"; public const string Settings = "Settings"; public const string Logs = "Logs"; diff --git a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs index 1a46282bc..8277e8e0b 100644 --- a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs +++ b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs @@ -37,7 +37,7 @@ namespace Flow.Launcher.Infrastructure.UserSettings private string _theme = Constant.DefaultTheme; public string Hotkey { get; set; } = $"{KeyConstant.Alt} + {KeyConstant.Space}"; public string OpenResultModifiers { get; set; } = KeyConstant.Alt; - public ColorSchemes ColorScheme { get; set; } = ColorSchemes.System; + public string ColorScheme { get; set; } = "System"; public bool ShowOpenResultHotkey { get; set; } = true; public double WindowSize { get; set; } = 580; public string PreviewHotkey { get; set; } = $"F1"; diff --git a/Flow.Launcher/MainWindow.xaml.cs b/Flow.Launcher/MainWindow.xaml.cs index 5194e02d0..9f8063a87 100644 --- a/Flow.Launcher/MainWindow.xaml.cs +++ b/Flow.Launcher/MainWindow.xaml.cs @@ -998,11 +998,11 @@ namespace Flow.Launcher public void InitializeColorScheme() { - if (_settings.ColorScheme == ColorSchemes.Light) + if (_settings.ColorScheme == Constant.Light) { ModernWpf.ThemeManager.Current.ApplicationTheme = ModernWpf.ApplicationTheme.Light; } - else if (_settings.ColorScheme == ColorSchemes.Dark) + else if (_settings.ColorScheme == Constant.Dark) { ModernWpf.ThemeManager.Current.ApplicationTheme = ModernWpf.ApplicationTheme.Dark; } diff --git a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs index e4d047f7a..d7bae5e80 100644 --- a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs +++ b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs @@ -108,16 +108,16 @@ public partial class SettingsPaneThemeViewModel : BaseModel public class ColorSchemeData : DropdownDataGeneric { } public List ColorSchemes { get; } = DropdownDataGeneric.GetValues("ColorScheme"); - public ColorSchemes ColorScheme + public string ColorScheme { get => Settings.ColorScheme; set { ThemeManagerForColorSchemeSwitch.Current.ApplicationTheme = value switch { - Infrastructure.UserSettings.ColorSchemes.Light => ApplicationTheme.Light, - Infrastructure.UserSettings.ColorSchemes.Dark => ApplicationTheme.Dark, - Infrastructure.UserSettings.ColorSchemes.System => null, + Constant.Light => ApplicationTheme.Light, + Constant.Dark => ApplicationTheme.Dark, + Constant.System => null, _ => ThemeManagerForColorSchemeSwitch.Current.ApplicationTheme };