Skip to content

Commit 8605374

Browse files
authored
Merge pull request #25 from JohnTheGr8/feat_fsharp_plugins
Add support for F# plugins
2 parents eb26329 + 1238d86 commit 8605374

File tree

6 files changed

+107
-10
lines changed

6 files changed

+107
-10
lines changed

Flow.Launcher.Core/Plugin/PluginsLoader.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,21 @@ public static class PluginsLoader
2020

2121
public static List<PluginPair> Plugins(List<PluginMetadata> metadatas, PluginsSettings settings)
2222
{
23-
var csharpPlugins = CSharpPlugins(metadatas).ToList();
23+
var dotnetPlugins = DotNetPlugins(metadatas).ToList();
2424
var pythonPlugins = PythonPlugins(metadatas, settings.PythonDirectory);
2525
var executablePlugins = ExecutablePlugins(metadatas);
26-
var plugins = csharpPlugins.Concat(pythonPlugins).Concat(executablePlugins).ToList();
26+
var plugins = dotnetPlugins.Concat(pythonPlugins).Concat(executablePlugins).ToList();
2727
return plugins;
2828
}
2929

30-
public static IEnumerable<PluginPair> CSharpPlugins(List<PluginMetadata> source)
30+
public static IEnumerable<PluginPair> DotNetPlugins(List<PluginMetadata> source)
3131
{
3232
var plugins = new List<PluginPair>();
33-
var metadatas = source.Where(o => o.Language.ToUpper() == AllowedLanguage.CSharp);
33+
var metadatas = source.Where(o => AllowedLanguage.IsDotNet(o.Language));
3434

3535
foreach (var metadata in metadatas)
3636
{
37-
var milliseconds = Stopwatch.Debug($"|PluginsLoader.CSharpPlugins|Constructor init cost for {metadata.Name}", () =>
37+
var milliseconds = Stopwatch.Debug($"|PluginsLoader.DotNetPlugins|Constructor init cost for {metadata.Name}", () =>
3838
{
3939

4040
#if DEBUG
@@ -50,7 +50,7 @@ public static IEnumerable<PluginPair> CSharpPlugins(List<PluginMetadata> source)
5050
}
5151
catch (Exception e)
5252
{
53-
Log.Exception($"|PluginsLoader.CSharpPlugins|Couldn't load assembly for {metadata.Name}", e);
53+
Log.Exception($"|PluginsLoader.DotNetPlugins|Couldn't load assembly for {metadata.Name}", e);
5454
return;
5555
}
5656
var types = assembly.GetTypes();
@@ -61,7 +61,7 @@ public static IEnumerable<PluginPair> CSharpPlugins(List<PluginMetadata> source)
6161
}
6262
catch (InvalidOperationException e)
6363
{
64-
Log.Exception($"|PluginsLoader.CSharpPlugins|Can't find class implement IPlugin for <{metadata.Name}>", e);
64+
Log.Exception($"|PluginsLoader.DotNetPlugins|Can't find class implement IPlugin for <{metadata.Name}>", e);
6565
return;
6666
}
6767
IPlugin plugin;
@@ -71,7 +71,7 @@ public static IEnumerable<PluginPair> CSharpPlugins(List<PluginMetadata> source)
7171
}
7272
catch (Exception e)
7373
{
74-
Log.Exception($"|PluginsLoader.CSharpPlugins|Can't create instance for <{metadata.Name}>", e);
74+
Log.Exception($"|PluginsLoader.DotNetPlugins|Can't create instance for <{metadata.Name}>", e);
7575
return;
7676
}
7777
#endif

Flow.Launcher.Plugin/AllowedLanguage.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,26 @@ public static string CSharp
1212
get { return "CSHARP"; }
1313
}
1414

15+
public static string FSharp
16+
{
17+
get { return "FSHARP"; }
18+
}
19+
1520
public static string Executable
1621
{
1722
get { return "EXECUTABLE"; }
1823
}
1924

25+
public static bool IsDotNet(string language)
26+
{
27+
return language.ToUpper() == CSharp
28+
|| language.ToUpper() == FSharp;
29+
}
30+
2031
public static bool IsAllowed(string language)
2132
{
22-
return language.ToUpper() == Python.ToUpper()
23-
|| language.ToUpper() == CSharp.ToUpper()
33+
return IsDotNet(language)
34+
|| language.ToUpper() == Python.ToUpper()
2435
|| language.ToUpper() == Executable.ToUpper();
2536
}
2637
}

Flow.Launcher.sln

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Flow.Launcher.Plugin.Browse
7474
EndProject
7575
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Flow.Launcher.Plugin.Calculator", "Plugins\Flow.Launcher.Plugin.Calculator\Flow.Launcher.Plugin.Calculator.csproj", "{59BD9891-3837-438A-958D-ADC7F91F6F7E}"
7676
EndProject
77+
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "HelloWorldFSharp", "Plugins\HelloWorldFSharp\HelloWorldFSharp.fsproj", "{30DDA7D9-3712-44F4-BD18-DC1C05B2DD9E}"
78+
EndProject
7779
Global
7880
GlobalSection(SolutionConfigurationPlatforms) = preSolution
7981
Debug|Any CPU = Debug|Any CPU
@@ -313,6 +315,18 @@ Global
313315
{59BD9891-3837-438A-958D-ADC7F91F6F7E}.Release|x64.Build.0 = Release|Any CPU
314316
{59BD9891-3837-438A-958D-ADC7F91F6F7E}.Release|x86.ActiveCfg = Release|Any CPU
315317
{59BD9891-3837-438A-958D-ADC7F91F6F7E}.Release|x86.Build.0 = Release|Any CPU
318+
{30DDA7D9-3712-44F4-BD18-DC1C05B2DD9E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
319+
{30DDA7D9-3712-44F4-BD18-DC1C05B2DD9E}.Debug|Any CPU.Build.0 = Debug|Any CPU
320+
{30DDA7D9-3712-44F4-BD18-DC1C05B2DD9E}.Debug|x64.ActiveCfg = Debug|Any CPU
321+
{30DDA7D9-3712-44F4-BD18-DC1C05B2DD9E}.Debug|x64.Build.0 = Debug|Any CPU
322+
{30DDA7D9-3712-44F4-BD18-DC1C05B2DD9E}.Debug|x86.ActiveCfg = Debug|Any CPU
323+
{30DDA7D9-3712-44F4-BD18-DC1C05B2DD9E}.Debug|x86.Build.0 = Debug|Any CPU
324+
{30DDA7D9-3712-44F4-BD18-DC1C05B2DD9E}.Release|Any CPU.ActiveCfg = Release|Any CPU
325+
{30DDA7D9-3712-44F4-BD18-DC1C05B2DD9E}.Release|Any CPU.Build.0 = Release|Any CPU
326+
{30DDA7D9-3712-44F4-BD18-DC1C05B2DD9E}.Release|x64.ActiveCfg = Release|Any CPU
327+
{30DDA7D9-3712-44F4-BD18-DC1C05B2DD9E}.Release|x64.Build.0 = Release|Any CPU
328+
{30DDA7D9-3712-44F4-BD18-DC1C05B2DD9E}.Release|x86.ActiveCfg = Release|Any CPU
329+
{30DDA7D9-3712-44F4-BD18-DC1C05B2DD9E}.Release|x86.Build.0 = Release|Any CPU
316330
EndGlobalSection
317331
GlobalSection(SolutionProperties) = preSolution
318332
HideSolutionNode = FALSE
@@ -332,6 +346,7 @@ Global
332346
{C21BFF9C-2C99-4B5F-B7C9-A5E6DDDB37B0} = {3A73F5A7-0335-40D8-BF7C-F20BE5D0BA87}
333347
{9B130CC5-14FB-41FF-B310-0A95B6894C37} = {3A73F5A7-0335-40D8-BF7C-F20BE5D0BA87}
334348
{59BD9891-3837-438A-958D-ADC7F91F6F7E} = {3A73F5A7-0335-40D8-BF7C-F20BE5D0BA87}
349+
{30DDA7D9-3712-44F4-BD18-DC1C05B2DD9E} = {3A73F5A7-0335-40D8-BF7C-F20BE5D0BA87}
335350
EndGlobalSection
336351
GlobalSection(ExtensibilityGlobals) = postSolution
337352
SolutionGuid = {F26ACB50-3F6C-4907-B0C9-1ADACC1D0DED}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp3.1</TargetFramework>
5+
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
6+
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
7+
</PropertyGroup>
8+
9+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
10+
<OutputPath>..\..\Output\Debug\Plugins\HelloWorldFSharp\</OutputPath>
11+
<DefineConstants>DEBUG;TRACE</DefineConstants>
12+
</PropertyGroup>
13+
14+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
15+
<OutputPath>..\..\Output\Release\Plugins\HelloWorldFSharp\</OutputPath>
16+
</PropertyGroup>
17+
18+
<ItemGroup>
19+
<Content Include="plugin.json">
20+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
21+
</Content>
22+
<Compile Include="Main.fs" />
23+
</ItemGroup>
24+
25+
<ItemGroup>
26+
<ProjectReference Include="..\..\Flow.Launcher.Plugin\Flow.Launcher.Plugin.csproj" />
27+
</ItemGroup>
28+
29+
</Project>

Plugins/HelloWorldFSharp/Main.fs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
namespace HelloWorldFSharp
2+
3+
open Flow.Launcher.Plugin
4+
open System.Collections.Generic
5+
6+
type HelloWorldFSharpPlugin() =
7+
8+
let mutable initContext = PluginInitContext()
9+
10+
interface IPlugin with
11+
member this.Init (context: PluginInitContext) =
12+
initContext <- context
13+
14+
member this.Query (query: Query) =
15+
List<Result> [
16+
Result (Title = "Hello World from F#",
17+
SubTitle = sprintf "Query: %s" query.Search)
18+
19+
Result (Title = "Browse source code of this plugin",
20+
SubTitle = "click to open in browser",
21+
Action = (fun ctx ->
22+
initContext.CurrentPluginMetadata.Website
23+
|> System.Diagnostics.Process.Start
24+
|> ignore
25+
true))
26+
27+
Result (Title = "Trigger a tray message",
28+
Action = (fun _ ->
29+
initContext.API.ShowMsg ("Sample tray message", "from the F# plugin")
30+
false))
31+
]

Plugins/HelloWorldFSharp/plugin.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"ID":"8FF5D5C1F8194958A12E8668FB7ECC04",
3+
"ActionKeyword":"hf",
4+
"Name":"Hello World FSharp",
5+
"Description":"Hello World FSharp",
6+
"Author":"Ioannis G.",
7+
"Version":"1.0.0",
8+
"Language":"fsharp",
9+
"Website":"https://github.com/Flow-Launcher/Flow.Launcher",
10+
"ExecuteFileName":"HelloWorldFSharp.dll"
11+
}

0 commit comments

Comments
 (0)