diff --git a/Flow.Launcher.Core/Resource/Theme.cs b/Flow.Launcher.Core/Resource/Theme.cs index cffba59ed..36b63a9c2 100644 --- a/Flow.Launcher.Core/Resource/Theme.cs +++ b/Flow.Launcher.Core/Resource/Theme.cs @@ -45,6 +45,8 @@ namespace Flow.Launcher.Core.Resource private string DirectoryPath => Path.Combine(Constant.ProgramDirectory, Folder); private string UserDirectoryPath => Path.Combine(DataLocation.DataDirectory(), Folder); + public string CurrentTheme => _settings.Theme; + public bool BlurEnabled { get; set; } private double mainWindowWidth; diff --git a/Flow.Launcher/Languages/en.xaml b/Flow.Launcher/Languages/en.xaml index 1275570c6..2aebebd6f 100644 --- a/Flow.Launcher/Languages/en.xaml +++ b/Flow.Launcher/Languages/en.xaml @@ -308,6 +308,9 @@ User Data Location User settings and installed plugins are saved in the user data folder. This location may vary depending on whether it's in portable mode or not. Open Folder + Log Level + Debug + Info Select File Manager diff --git a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneAboutViewModel.cs b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneAboutViewModel.cs index ade650284..6b44be7c1 100644 --- a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneAboutViewModel.cs +++ b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneAboutViewModel.cs @@ -8,6 +8,7 @@ using CommunityToolkit.Mvvm.Input; using Flow.Launcher.Core; using Flow.Launcher.Core.Resource; using Flow.Launcher.Infrastructure; +using Flow.Launcher.Infrastructure.Logger; using Flow.Launcher.Infrastructure.UserSettings; using Flow.Launcher.Plugin; @@ -45,10 +46,35 @@ public partial class SettingsPaneAboutViewModel : BaseModel _settings.ActivateTimes ); + public class LogLevelData : DropdownDataGeneric { } + + public List LogLevels { get; } = + DropdownDataGeneric.GetValues("LogLevel"); + + public LOGLEVEL LogLevel + { + get => _settings.LogLevel; + set + { + if (_settings.LogLevel != value) + { + _settings.LogLevel = value; + + Log.SetLogLevel(value); + } + } + } + public SettingsPaneAboutViewModel(Settings settings, Updater updater) { _settings = settings; _updater = updater; + UpdateEnumDropdownLocalizations(); + } + + private void UpdateEnumDropdownLocalizations() + { + DropdownDataGeneric.UpdateLabels(LogLevels); } [RelayCommand] @@ -138,5 +164,4 @@ public partial class SettingsPaneAboutViewModel : BaseModel return "0 B"; } - } diff --git a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs index e4f88432a..de4f158ad 100644 --- a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs +++ b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs @@ -1,13 +1,11 @@ using System; using System.Collections.Generic; -using System.Linq; using System.Windows.Forms; using CommunityToolkit.Mvvm.Input; using Flow.Launcher.Core; using Flow.Launcher.Core.Configuration; using Flow.Launcher.Core.Resource; using Flow.Launcher.Helper; -using Flow.Launcher.Infrastructure.Logger; using Flow.Launcher.Infrastructure.UserSettings; using Flow.Launcher.Plugin; using Flow.Launcher.Plugin.SharedModels; @@ -32,7 +30,6 @@ public partial class SettingsPaneGeneralViewModel : BaseModel public class SearchWindowAlignData : DropdownDataGeneric { } public class SearchPrecisionData : DropdownDataGeneric { } public class LastQueryModeData : DropdownDataGeneric { } - public class LogLevelData : DropdownDataGeneric { } public bool StartFlowLauncherOnSystemStartup { @@ -145,16 +142,12 @@ public partial class SettingsPaneGeneralViewModel : BaseModel public List LastQueryModes { get; } = DropdownDataGeneric.GetValues("LastQuery"); - public List LogLevels { get; } = - DropdownDataGeneric.GetValues("LogLevel"); - private void UpdateEnumDropdownLocalizations() { DropdownDataGeneric.UpdateLabels(SearchWindowScreens); DropdownDataGeneric.UpdateLabels(SearchWindowAligns); DropdownDataGeneric.UpdateLabels(SearchPrecisionScores); DropdownDataGeneric.UpdateLabels(LastQueryModes); - DropdownDataGeneric.UpdateLabels(LogLevels); } public string Language @@ -222,22 +215,6 @@ public partial class SettingsPaneGeneralViewModel : BaseModel } } - public LOGLEVEL LogLevel - { - get => Settings.LogLevel; - set - { - if (Settings.LogLevel != value) - { - Settings.LogLevel = value; - - Log.SetLogLevel(value); - - UpdateEnumDropdownLocalizations(); - } - } - } - [RelayCommand] private void SelectPython() { diff --git a/Flow.Launcher/SettingPages/Views/SettingsPaneAbout.xaml b/Flow.Launcher/SettingPages/Views/SettingsPaneAbout.xaml index e33fee02b..75c513411 100644 --- a/Flow.Launcher/SettingPages/Views/SettingsPaneAbout.xaml +++ b/Flow.Launcher/SettingPages/Views/SettingsPaneAbout.xaml @@ -123,6 +123,14 @@ + + + + - - - - diff --git a/Plugins/Flow.Launcher.Plugin.Sys/Flow.Launcher.Plugin.Sys.csproj b/Plugins/Flow.Launcher.Plugin.Sys/Flow.Launcher.Plugin.Sys.csproj index dbc36ad42..266c24170 100644 --- a/Plugins/Flow.Launcher.Plugin.Sys/Flow.Launcher.Plugin.Sys.csproj +++ b/Plugins/Flow.Launcher.Plugin.Sys/Flow.Launcher.Plugin.Sys.csproj @@ -39,6 +39,7 @@ + diff --git a/Plugins/Flow.Launcher.Plugin.Sys/Images/theme_selector.png b/Plugins/Flow.Launcher.Plugin.Sys/Images/theme_selector.png new file mode 100644 index 000000000..704e9474e Binary files /dev/null and b/Plugins/Flow.Launcher.Plugin.Sys/Images/theme_selector.png differ diff --git a/Plugins/Flow.Launcher.Plugin.Sys/Languages/en.xaml b/Plugins/Flow.Launcher.Plugin.Sys/Languages/en.xaml index 91f32a844..2a266f8f6 100644 --- a/Plugins/Flow.Launcher.Plugin.Sys/Languages/en.xaml +++ b/Plugins/Flow.Launcher.Plugin.Sys/Languages/en.xaml @@ -27,6 +27,7 @@ Flow Launcher Tips Flow Launcher UserData Folder Toggle Game Mode + Set the Flow Launcher Theme Shutdown Computer @@ -49,8 +50,9 @@ Visit Flow Launcher's documentation for more help and how to use tips Open the location where Flow Launcher's settings are stored Toggle Game Mode + Quickly change the Flow Launcher theme - + Success All Flow Launcher settings saved Reloaded all applicable plugin data diff --git a/Plugins/Flow.Launcher.Plugin.Sys/Main.cs b/Plugins/Flow.Launcher.Plugin.Sys/Main.cs index 2331ee68c..28747cc7c 100644 --- a/Plugins/Flow.Launcher.Plugin.Sys/Main.cs +++ b/Plugins/Flow.Launcher.Plugin.Sys/Main.cs @@ -7,7 +7,6 @@ using System.Windows; using Flow.Launcher.Infrastructure; using Flow.Launcher.Infrastructure.Logger; using Flow.Launcher.Infrastructure.UserSettings; -using Flow.Launcher.Plugin.SharedCommands; using Windows.Win32; using Windows.Win32.Foundation; using Windows.Win32.Security; @@ -20,6 +19,7 @@ namespace Flow.Launcher.Plugin.Sys public class Main : IPlugin, ISettingProvider, IPluginI18n { private PluginInitContext context; + private ThemeSelector themeSelector; private Dictionary KeywordTitleMappings = new Dictionary(); // SHTDN_REASON_MAJOR_OTHER indicates a generic shutdown reason that isn't categorized under hardware failure, software updates, or other predefined reasons. @@ -34,6 +34,11 @@ namespace Flow.Launcher.Plugin.Sys public List Query(Query query) { + if(query.Search.StartsWith(ThemeSelector.Keyword)) + { + return themeSelector.Query(query); + } + var commands = Commands(); var results = new List(); foreach (var c in commands) @@ -82,6 +87,7 @@ namespace Flow.Launcher.Plugin.Sys public void Init(PluginInitContext context) { this.context = context; + themeSelector = new ThemeSelector(context); KeywordTitleMappings = new Dictionary{ {"Shutdown", "flowlauncher_plugin_sys_shutdown_computer_cmd"}, {"Restart", "flowlauncher_plugin_sys_restart_computer_cmd"}, @@ -102,7 +108,8 @@ namespace Flow.Launcher.Plugin.Sys {"Open Log Location", "flowlauncher_plugin_sys_open_log_location_cmd"}, {"Flow Launcher Tips", "flowlauncher_plugin_sys_open_docs_tips_cmd"}, {"Flow Launcher UserData Folder", "flowlauncher_plugin_sys_open_userdata_location_cmd"}, - {"Toggle Game Mode", "flowlauncher_plugin_sys_toggle_game_mode_cmd"} + {"Toggle Game Mode", "flowlauncher_plugin_sys_toggle_game_mode_cmd"}, + {"Set Flow Launcher Theme", "flowlauncher_plugin_sys_theme_selector_cmd"} }; } @@ -451,6 +458,18 @@ namespace Flow.Launcher.Plugin.Sys context.API.ToggleGameMode(); return true; } + }, + new Result + { + Title = "Set Flow Launcher Theme", + SubTitle = context.API.GetTranslation("flowlauncher_plugin_sys_theme_selector"), + IcoPath = "Images\\app.png", + Glyph = new GlyphInfo (FontFamily:"/Resources/#Segoe Fluent Icons", Glyph:"\ue7fc"), + Action = c => + { + context.API.ChangeQuery($"{ThemeSelector.Keyword} "); + return false; + } } }); diff --git a/Plugins/Flow.Launcher.Plugin.Sys/ThemeSelector.cs b/Plugins/Flow.Launcher.Plugin.Sys/ThemeSelector.cs new file mode 100644 index 000000000..38619cbbc --- /dev/null +++ b/Plugins/Flow.Launcher.Plugin.Sys/ThemeSelector.cs @@ -0,0 +1,115 @@ +using System.Collections.Generic; +using System.Linq; +using CommunityToolkit.Mvvm.DependencyInjection; +using Flow.Launcher.Core.Resource; +using Flow.Launcher.Infrastructure.UserSettings; + +namespace Flow.Launcher.Plugin.Sys +{ + public class ThemeSelector + { + public const string Keyword = "fltheme"; + + private readonly Settings _settings; + private readonly Theme _theme; + private readonly PluginInitContext _context; + + #region Theme Selection + + // Theme select codes simplified from SettingsPaneThemeViewModel.cs + + private Theme.ThemeData _selectedTheme; + private Theme.ThemeData SelectedTheme + { + get => _selectedTheme ??= Themes.Find(v => v.FileNameWithoutExtension == _theme.CurrentTheme); + set + { + _selectedTheme = value; + _theme.ChangeTheme(value.FileNameWithoutExtension); + + if (_theme.BlurEnabled && _settings.UseDropShadowEffect) + { + _theme.RemoveDropShadowEffectFromCurrentTheme(); + _settings.UseDropShadowEffect = false; + } + } + } + + private List Themes => _theme.LoadAvailableThemes(); + + #endregion + + public ThemeSelector(PluginInitContext context) + { + _context = context; + _theme = Ioc.Default.GetRequiredService(); + _settings = Ioc.Default.GetRequiredService(); + } + + public List Query(Query query) + { + var search = query.SecondToEndSearch; + if (string.IsNullOrWhiteSpace(search)) + { + return Themes.Select(CreateThemeResult) + .OrderBy(x => x.Title) + .ToList(); + } + + return Themes.Select(theme => (theme, matchResult: _context.API.FuzzySearch(search, theme.Name))) + .Where(x => x.matchResult.IsSearchPrecisionScoreMet()) + .Select(x => CreateThemeResult(x.theme, x.matchResult.Score, x.matchResult.MatchData)) + .OrderBy(x => x.Title) + .ToList(); + } + + private Result CreateThemeResult(Theme.ThemeData theme) => CreateThemeResult(theme, 0, null); + + private Result CreateThemeResult(Theme.ThemeData theme, int score, IList highlightData) + { + string themeName = theme.Name; + string title; + if (theme == SelectedTheme) + { + title = $"{theme.Name} ★"; + // Set current theme to the top + score = 2000; + } + else + { + title = theme.Name; + // Set them to 1000 so that they are higher than other non-theme records + score = 1000; + } + + string description = string.Empty; + if (theme.IsDark == true) + { + description += _context.API.GetTranslation("TypeIsDarkToolTip"); + } + + if (theme.HasBlur == true) + { + if (!string.IsNullOrEmpty(description)) + description += " "; + description += _context.API.GetTranslation("TypeHasBlurToolTip"); + } + + return new Result + { + Title = title, + TitleHighlightData = highlightData, + SubTitle = description, + IcoPath = "Images\\theme_selector.png", + Glyph = new GlyphInfo("/Resources/#Segoe Fluent Icons", "\ue790"), + Score = score, + Action = c => + { + SelectedTheme = theme; + _context.API.ReQuery(); + return false; + } + }; + } + } +}