Skip to content

Commit 1b31e9c

Browse files
committed
Create Flow Launcher Theme Selector plugin
1 parent 2c39cf7 commit 1b31e9c

File tree

4 files changed

+140
-0
lines changed

4 files changed

+140
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
2+
<Project Sdk="Microsoft.NET.Sdk">
3+
4+
<PropertyGroup>
5+
<OutputType>Library</OutputType>
6+
<TargetFramework>net7.0-windows</TargetFramework>
7+
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
8+
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
9+
</PropertyGroup>
10+
11+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
12+
<OutputPath>..\..\Output\Debug\Plugins\Flow.Launcher.Plugin.FlowThemeSelector</OutputPath>
13+
</PropertyGroup>
14+
15+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
16+
<OutputPath>..\..\Output\Release\Plugins\Flow.Launcher.Plugin.FlowThemeSelector</OutputPath>
17+
</PropertyGroup>
18+
19+
<ItemGroup>
20+
<ProjectReference Include="..\..\Flow.Launcher.Infrastructure\Flow.Launcher.Infrastructure.csproj" />
21+
<ProjectReference Include="..\..\Flow.Launcher.Core\Flow.Launcher.Core.csproj" />
22+
<ProjectReference Include="..\..\Flow.Launcher.Plugin\Flow.Launcher.Plugin.csproj" />
23+
</ItemGroup>
24+
25+
<ItemGroup>
26+
<None Include="plugin.json">
27+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
28+
</None>
29+
</ItemGroup>
30+
31+
<ItemGroup>
32+
<None Update="icon.png">
33+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
34+
</None>
35+
</ItemGroup>
36+
37+
</Project>
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using Flow.Launcher.Core.Resource;
6+
7+
namespace Flow.Launcher.Plugin.FlowThemeSelector
8+
{
9+
public class FlowThemeSelector : IPlugin, IReloadable, IDisposable
10+
{
11+
private PluginInitContext context;
12+
private IEnumerable<string> themes;
13+
14+
public void Init(PluginInitContext context)
15+
{
16+
this.context = context;
17+
context.API.VisibilityChanged += OnVisibilityChanged;
18+
}
19+
20+
public List<Result> Query(Query query)
21+
{
22+
if (query.IsReQuery)
23+
{
24+
LoadThemes();
25+
}
26+
27+
if (string.IsNullOrWhiteSpace(query.Search))
28+
{
29+
return themes.Select(CreateThemeResult)
30+
.OrderBy(x => x.Title)
31+
.ToList();
32+
}
33+
34+
return themes.Select(theme => (theme, matchResult: context.API.FuzzySearch(query.Search, theme)))
35+
.Where(x => x.matchResult.IsSearchPrecisionScoreMet())
36+
.Select(x => CreateThemeResult(x.theme, x.matchResult.Score, x.matchResult.MatchData))
37+
.OrderBy(x => x.Title)
38+
.ToList();
39+
}
40+
41+
private void OnVisibilityChanged(object sender, VisibilityChangedEventArgs args)
42+
{
43+
if (args.IsVisible && !context.CurrentPluginMetadata.Disabled)
44+
{
45+
LoadThemes();
46+
}
47+
}
48+
49+
public void LoadThemes() => themes = ThemeManager.Instance.LoadAvailableThemes().Select(Path.GetFileNameWithoutExtension);
50+
51+
public static Result CreateThemeResult(string theme) => CreateThemeResult(theme, 0, null);
52+
53+
public static Result CreateThemeResult(string theme, int score, IList<int> highlightData)
54+
{
55+
string title;
56+
if (theme == ThemeManager.Instance.Settings.Theme)
57+
{
58+
title = $"{theme} ★";
59+
score = 2000;
60+
}
61+
else
62+
{
63+
title = theme;
64+
}
65+
66+
return new Result
67+
{
68+
Title = title,
69+
TitleHighlightData = highlightData,
70+
Glyph = new GlyphInfo("/Resources/#Segoe Fluent Icons", "\ue790"),
71+
Score = score,
72+
Action = c =>
73+
{
74+
ThemeManager.Instance.ChangeTheme(theme);
75+
return true;
76+
}
77+
};
78+
}
79+
80+
public void ReloadData() => LoadThemes();
81+
82+
public void Dispose()
83+
{
84+
if (context != null && context.API != null)
85+
{
86+
context.API.VisibilityChanged -= OnVisibilityChanged;
87+
}
88+
}
89+
90+
}
91+
}
6.47 KB
Loading
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"ID": "4DFA743E1086414BAB0AA3071D561D75",
3+
"ActionKeyword": "flowtheme",
4+
"Name": "Flow Launcher Theme Selector",
5+
"Description": "Quickly switch your Flow Launcher theme.",
6+
"Author": "Odotocodot",
7+
"Version": "1.0.0",
8+
"Language": "csharp",
9+
"Website": "https://github.com/Flow-Launcher/Flow.Launcher",
10+
"IcoPath": "icon.png",
11+
"ExecuteFileName": "Flow.Launcher.Plugin.FlowThemeSelector.dll"
12+
}

0 commit comments

Comments
 (0)