Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Flow.Launcher.Core/Resource/Theme.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
using Flow.Launcher.Infrastructure;
using Flow.Launcher.Infrastructure.Logger;
using Flow.Launcher.Infrastructure.UserSettings;
using CommunityToolkit.Mvvm.DependencyInjection;
using Flow.Launcher.Plugin;

namespace Flow.Launcher.Core.Resource
Expand All @@ -35,6 +34,8 @@ public class Theme
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
<ItemGroup>
<ProjectReference Include="..\..\Flow.Launcher.Infrastructure\Flow.Launcher.Infrastructure.csproj" />
<ProjectReference Include="..\..\Flow.Launcher.Plugin\Flow.Launcher.Plugin.csproj" />
<ProjectReference Include="..\..\Flow.Launcher.Core\Flow.Launcher.Core.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion Plugins/Flow.Launcher.Plugin.Sys/Languages/en.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<system:String x:Key="flowlauncher_plugin_sys_open_docs_tips_cmd">Flow Launcher Tips</system:String>
<system:String x:Key="flowlauncher_plugin_sys_open_userdata_location_cmd">Flow Launcher UserData Folder</system:String>
<system:String x:Key="flowlauncher_plugin_sys_toggle_game_mode_cmd">Toggle Game Mode</system:String>
<system:String x:Key="flowlauncher_plugin_sys_theme_selector_cmd">Set the Flow Launcher Theme</system:String>

<!-- Command Descriptions -->
<system:String x:Key="flowlauncher_plugin_sys_shutdown_computer">Shutdown Computer</system:String>
Expand All @@ -49,8 +50,9 @@
<system:String x:Key="flowlauncher_plugin_sys_open_docs_tips">Visit Flow Launcher's documentation for more help and how to use tips</system:String>
<system:String x:Key="flowlauncher_plugin_sys_open_userdata_location">Open the location where Flow Launcher's settings are stored</system:String>
<system:String x:Key="flowlauncher_plugin_sys_toggle_game_mode">Toggle Game Mode</system:String>
<system:String x:Key="flowlauncher_plugin_sys_theme_selector">Quickly change the Flow Launcher theme</system:String>

<!-- Dialogs -->
<!-- Dialogs -->
<system:String x:Key="flowlauncher_plugin_sys_dlgtitle_success">Success</system:String>
<system:String x:Key="flowlauncher_plugin_sys_dlgtext_all_settings_saved">All Flow Launcher settings saved</system:String>
<system:String x:Key="flowlauncher_plugin_sys_dlgtext_all_applicableplugins_reloaded">Reloaded all applicable plugin data</system:String>
Expand Down
23 changes: 21 additions & 2 deletions Plugins/Flow.Launcher.Plugin.Sys/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
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;
Expand All @@ -20,6 +19,7 @@ namespace Flow.Launcher.Plugin.Sys
public class Main : IPlugin, ISettingProvider, IPluginI18n
{
private PluginInitContext context;
private ThemeSelector themeSelector;
private Dictionary<string, string> KeywordTitleMappings = new Dictionary<string, string>();

// SHTDN_REASON_MAJOR_OTHER indicates a generic shutdown reason that isn't categorized under hardware failure, software updates, or other predefined reasons.
Expand All @@ -34,6 +34,11 @@ public Control CreateSettingPanel()

public List<Result> Query(Query query)
{
if(query.Search.StartsWith(ThemeSelector.Keyword))
{
return themeSelector.Query(query);
}

var commands = Commands();
var results = new List<Result>();
foreach (var c in commands)
Expand Down Expand Up @@ -82,6 +87,7 @@ private string GetDynamicTitle(Query query, Result result)
public void Init(PluginInitContext context)
{
this.context = context;
themeSelector = new ThemeSelector(context);
KeywordTitleMappings = new Dictionary<string, string>{
{"Shutdown", "flowlauncher_plugin_sys_shutdown_computer_cmd"},
{"Restart", "flowlauncher_plugin_sys_restart_computer_cmd"},
Expand All @@ -102,7 +108,8 @@ public void Init(PluginInitContext context)
{"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"}
};
}

Expand Down Expand Up @@ -451,6 +458,18 @@ private List<Result> Commands()
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;
}
}
});

Expand Down
115 changes: 115 additions & 0 deletions Plugins/Flow.Launcher.Plugin.Sys/ThemeSelector.cs
Original file line number Diff line number Diff line change
@@ -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<Theme.ThemeData> Themes => _theme.LoadAvailableThemes();

#endregion

public ThemeSelector(PluginInitContext context)
{
_context = context;
_theme = Ioc.Default.GetRequiredService<Theme>();
_settings = Ioc.Default.GetRequiredService<Settings>();
}

public List<Result> 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<int> 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;
}
};
}
}
}
Loading