Skip to content

Commit caa5a48

Browse files
committed
Use enum instead of constants & Use vm property
1 parent c7a2dee commit caa5a48

File tree

7 files changed

+23
-25
lines changed

7 files changed

+23
-25
lines changed

Flow.Launcher.Core/Resource/Theme.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ public void ColorizeWindow(string Mode)
457457
// ✅ 설정의 ColorScheme을 우선 사용
458458
int themeValue = (int)Registry.GetValue(@"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize", "AppsUseLightTheme", 1);
459459
bool isSystemDark = themeValue == 0;
460-
bool useDarkMode = Mode == "Dark" || (Mode == "Auto" && _settings.ColorScheme == "System" && isSystemDark) || (_settings.ColorScheme == "Dark");
460+
bool useDarkMode = Mode == "Dark" || (Mode == "Auto" && _settings.ColorScheme == ColorSchemes.System && isSystemDark) || (_settings.ColorScheme == ColorSchemes.Dark);
461461

462462
Color selectedBG = useDarkMode ? DarkBG : LightBG;
463463
ApplyPreviewBackground(selectedBG);

Flow.Launcher.Infrastructure/Constant.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,6 @@ public static class Constant
4040

4141
public const string DefaultTheme = "Win11Light";
4242

43-
public const string Light = "Light";
44-
public const string Dark = "Dark";
45-
public const string System = "System";
46-
4743
public const string Themes = "Themes";
4844
public const string Settings = "Settings";
4945
public const string Logs = "Logs";

Flow.Launcher.Infrastructure/UserSettings/Settings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public void Save()
3737
private string _theme = Constant.DefaultTheme;
3838
public string Hotkey { get; set; } = $"{KeyConstant.Alt} + {KeyConstant.Space}";
3939
public string OpenResultModifiers { get; set; } = KeyConstant.Alt;
40-
public string ColorScheme { get; set; } = "System";
40+
public ColorSchemes ColorScheme { get; set; } = ColorSchemes.System;
4141
public bool ShowOpenResultHotkey { get; set; } = true;
4242
public double WindowSize { get; set; } = 580;
4343
public string PreviewHotkey { get; set; } = $"F1";

Flow.Launcher/MainWindow.xaml.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -998,11 +998,11 @@ private void MoveQueryTextToEnd()
998998

999999
public void InitializeColorScheme()
10001000
{
1001-
if (_settings.ColorScheme == Constant.Light)
1001+
if (_settings.ColorScheme == ColorSchemes.Light)
10021002
{
10031003
ModernWpf.ThemeManager.Current.ApplicationTheme = ModernWpf.ApplicationTheme.Light;
10041004
}
1005-
else if (_settings.ColorScheme == Constant.Dark)
1005+
else if (_settings.ColorScheme == ColorSchemes.Dark)
10061006
{
10071007
ModernWpf.ThemeManager.Current.ApplicationTheme = ModernWpf.ApplicationTheme.Dark;
10081008
}

Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
using ModernWpf;
1616
using ThemeManager = Flow.Launcher.Core.Resource.ThemeManager;
1717
using ThemeManagerForColorSchemeSwitch = ModernWpf.ThemeManager;
18-
using static Flow.Launcher.Core.Resource.Theme;
19-
using System.Windows.Interop;
2018

2119
namespace Flow.Launcher.SettingPages.ViewModels;
2220

@@ -38,8 +36,11 @@ public Theme.ThemeData SelectedTheme
3836
ThemeManager.Instance.ChangeTheme(value.FileNameWithoutExtension);
3937

4038
if (ThemeManager.Instance.BlurEnabled && Settings.UseDropShadowEffect == false)
39+
{
4140
DropShadowEffect = true;
4241
OnPropertyChanged(nameof(IsDropShadowEnabled));
42+
}
43+
4344
ThemeManager.Instance.RefreshFrame();
4445
//ThemeManager.Instance.SetBlurForWindow();
4546
}
@@ -107,6 +108,16 @@ public double ResultSubItemFontSize
107108
public class ColorSchemeData : DropdownDataGeneric<ColorSchemes> { }
108109

109110
public List<ColorSchemeData> ColorSchemes { get; } = DropdownDataGeneric<ColorSchemes>.GetValues<ColorSchemeData>("ColorScheme");
111+
public ColorSchemes ColorScheme
112+
{
113+
get => Settings.ColorScheme;
114+
set
115+
{
116+
UpdateColorScheme();
117+
118+
Settings.ColorScheme = value;
119+
}
120+
}
110121

111122
public List<string> TimeFormatList { get; } = new()
112123
{
@@ -463,13 +474,13 @@ private void OpenThemesFolder()
463474
App.API.OpenDirectory(Path.Combine(DataLocation.DataDirectory(), Constant.Themes));
464475
}
465476

466-
public void UpdateColorScheme()
477+
private void UpdateColorScheme()
467478
{
468479
ThemeManagerForColorSchemeSwitch.Current.ApplicationTheme = Settings.ColorScheme switch
469480
{
470-
Constant.Light => ApplicationTheme.Light,
471-
Constant.Dark => ApplicationTheme.Dark,
472-
Constant.System => null,
481+
Infrastructure.UserSettings.ColorSchemes.Light => ApplicationTheme.Light,
482+
Infrastructure.UserSettings.ColorSchemes.Dark => ApplicationTheme.Dark,
483+
Infrastructure.UserSettings.ColorSchemes.System => null,
473484
_ => ThemeManagerForColorSchemeSwitch.Current.ApplicationTheme
474485
};
475486
ThemeManager.Instance.RefreshFrame();

Flow.Launcher/SettingPages/Views/SettingsPaneTheme.xaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -688,9 +688,8 @@
688688
DisplayMemberPath="Display"
689689
FontSize="14"
690690
ItemsSource="{Binding ColorSchemes}"
691-
SelectedValue="{Binding Settings.ColorScheme}"
692-
SelectedValuePath="Value"
693-
SelectionChanged="Selector_OnSelectionChanged" />
691+
SelectedValue="{Binding ColorScheme, Mode=TwoWay}"
692+
SelectedValuePath="Value" />
694693
</cc:Card>
695694

696695
<!-- Theme folder -->

Flow.Launcher/SettingPages/Views/SettingsPaneTheme.xaml.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
using System;
2-
using System.Windows;
3-
using System.Windows.Controls;
4-
using System.Windows.Media;
52
using System.Windows.Navigation;
63
using Flow.Launcher.SettingPages.ViewModels;
74
using Page = ModernWpf.Controls.Page;
@@ -25,9 +22,4 @@ protected override void OnNavigatedTo(NavigationEventArgs e)
2522

2623
base.OnNavigatedTo(e);
2724
}
28-
29-
private void Selector_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
30-
{
31-
_viewModel.UpdateColorScheme();
32-
}
3325
}

0 commit comments

Comments
 (0)