Move Theme Selector into Sys plugin

This commit is contained in:
Odotocodot 2024-06-15 12:16:36 +01:00
parent 5e69bd7023
commit 49a71d7d53
7 changed files with 45 additions and 62 deletions

View file

@ -1,37 +0,0 @@

<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFramework>net7.0-windows</TargetFramework>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<OutputPath>..\..\Output\Debug\Plugins\Flow.Launcher.Plugin.FlowThemeSelector</OutputPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<OutputPath>..\..\Output\Release\Plugins\Flow.Launcher.Plugin.FlowThemeSelector</OutputPath>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\Flow.Launcher.Infrastructure\Flow.Launcher.Infrastructure.csproj" />
<ProjectReference Include="..\..\Flow.Launcher.Core\Flow.Launcher.Core.csproj" />
<ProjectReference Include="..\..\Flow.Launcher.Plugin\Flow.Launcher.Plugin.csproj" />
</ItemGroup>
<ItemGroup>
<None Include="plugin.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<None Update="icon.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

View file

@ -1,12 +0,0 @@
{
"ID": "4DFA743E1086414BAB0AA3071D561D75",
"ActionKeyword": "flowtheme",
"Name": "Flow Launcher Theme Selector",
"Description": "Quickly switch your Flow Launcher theme.",
"Author": "Odotocodot",
"Version": "1.0.0",
"Language": "csharp",
"Website": "https://github.com/Flow-Launcher/Flow.Launcher",
"IcoPath": "icon.png",
"ExecuteFileName": "Flow.Launcher.Plugin.FlowThemeSelector.dll"
}

View file

@ -38,6 +38,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>

View file

Before

Width:  |  Height:  |  Size: 6.5 KiB

After

Width:  |  Height:  |  Size: 6.5 KiB

View file

@ -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>
@ -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>

View file

@ -18,9 +18,10 @@ using MessageBox = System.Windows.MessageBox;
namespace Flow.Launcher.Plugin.Sys
{
public class Main : IPlugin, ISettingProvider, IPluginI18n
public class Main : IPlugin, ISettingProvider, IPluginI18n, IDisposable
{
private PluginInitContext context;
private ThemeSelector themeSelector;
private Dictionary<string, string> KeywordTitleMappings = new Dictionary<string, string>();
#region DllImport
@ -58,6 +59,11 @@ namespace Flow.Launcher.Plugin.Sys
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)
@ -106,6 +112,7 @@ namespace Flow.Launcher.Plugin.Sys
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"},
@ -126,7 +133,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"}
};
}
@ -426,6 +434,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\\theme_selector.png",
Glyph = new GlyphInfo("/Resources/#Segoe Fluent Icons", "\ue790"),
Action = c =>
{
context.API.ChangeQuery($"{ThemeSelector.Keyword} ");
return false;
}
}
});
@ -441,5 +461,10 @@ namespace Flow.Launcher.Plugin.Sys
{
return context.API.GetTranslation("flowlauncher_plugin_sys_plugin_description");
}
public void Dispose()
{
themeSelector.Dispose();
}
}
}

View file

@ -4,14 +4,16 @@ using System.IO;
using System.Linq;
using Flow.Launcher.Core.Resource;
namespace Flow.Launcher.Plugin.FlowThemeSelector
namespace Flow.Launcher.Plugin.Sys
{
public class FlowThemeSelector : IPlugin, IReloadable, IDisposable
public class ThemeSelector : IReloadable, IDisposable
{
private PluginInitContext context;
public const string Keyword = "fltheme";
private readonly PluginInitContext context;
private IEnumerable<string> themes;
public void Init(PluginInitContext context)
public ThemeSelector(PluginInitContext context)
{
this.context = context;
context.API.VisibilityChanged += OnVisibilityChanged;
@ -24,14 +26,16 @@ namespace Flow.Launcher.Plugin.FlowThemeSelector
LoadThemes();
}
if (string.IsNullOrWhiteSpace(query.Search))
string search = query.Search[(query.Search.IndexOf(Keyword, StringComparison.Ordinal) + Keyword.Length + 1)..];
if (string.IsNullOrWhiteSpace(search))
{
return themes.Select(CreateThemeResult)
.OrderBy(x => x.Title)
.ToList();
}
return themes.Select(theme => (theme, matchResult: context.API.FuzzySearch(query.Search, theme)))
return themes.Select(theme => (theme, matchResult: context.API.FuzzySearch(search, theme)))
.Where(x => x.matchResult.IsSearchPrecisionScoreMet())
.Select(x => CreateThemeResult(x.theme, x.matchResult.Score, x.matchResult.MatchData))
.OrderBy(x => x.Title)
@ -46,11 +50,12 @@ namespace Flow.Launcher.Plugin.FlowThemeSelector
}
}
public void LoadThemes() => themes = ThemeManager.Instance.LoadAvailableThemes().Select(Path.GetFileNameWithoutExtension);
private void LoadThemes()
=> themes = ThemeManager.Instance.LoadAvailableThemes().Select(Path.GetFileNameWithoutExtension);
public static Result CreateThemeResult(string theme) => CreateThemeResult(theme, 0, null);
private static Result CreateThemeResult(string theme) => CreateThemeResult(theme, 0, null);
public static Result CreateThemeResult(string theme, int score, IList<int> highlightData)
private static Result CreateThemeResult(string theme, int score, IList<int> highlightData)
{
string title;
if (theme == ThemeManager.Instance.Settings.Theme)
@ -86,6 +91,5 @@ namespace Flow.Launcher.Plugin.FlowThemeSelector
context.API.VisibilityChanged -= OnVisibilityChanged;
}
}
}
}