Flow is written in C#, so plugins written in dotnet platform can directly communicate with Flow without extra protocols.
For C# Plugins, We recommand you use the dotnet template to generate a plugin template.
In order to be recongized as a Flow DotNet plugin, the directory needs to have at least two files
plugin.json
- A Dotnet Assembly that implements IPlugin or IAsyncPlugin (remember to refrence Flow.Launcher.Plugin by Nuget). The plugin template will add the reference and create a
Main.cs
that implementsIPlugin
.
Find our API Reference here
A sample CSharp Plugin here
The Main
class that implements IPlugin or IAsyncPlugin will handle the query search with Flow.
IPlugin interface contains two required methods:
void Init(PluginInitContext context)
- PluginInitContext exposes some API from Flow and an metadata object for your plugin.
- It will be invoked before the invocation of
Query
, so you can do some preparation here. - We recommand you do expensive operations in this method instead of Object Constructor because this method will be executed in parallel with other plugins.
List<Result> Query(Query query)
Query
will be invoked when user activate this plugin with specific ActionKeyword.- A
List
of Result object should be returned.
IAsyncPlugin is the async version of IPlugin
- Instead of implmenting
Init
andQuery
, you will need to implementInitAsync
andQueryAsync
, which useTask
,Task<List<Result>
as return value to allow usingasync/await
strategy QueryAsync
provides aCancellationToken token
to allow you to check whether user has typed a new query.
Besides the basic implementation of IPlugin/IAsyncPlugin, plugins can also implement a series of interfaces that belongs to IFeatures to control more communication with Flow.
Remarks: You should implement these interfaces in the same class that implements IPlugin/IAsyncPlugin.
LoadContextMenus
will be invoked when users expand the context menu of a specific Result.
The return value of LoadContextMenus
is similar to Results from Query/QueryAsync
.
ReloadData/ReloadDataAsync
will be invoked when users click the Reload Plugin Data
command from sys plugin. Generally, it is used to reload some cache (such as the programs information cached in Program plugin).
IPluginI18n means the plugin has been internationalized. Therefore, Flow will load the additional lauguage resources from /Languages
when loading the plugin.
By implementing this interface with additional language files, Flow will be able to load plugin-sepcified localized language resources. You will be able to get the translated text with IPublicAPI.GetTranslation(string key)
.
A Language Resource file will have name of the specific Language Code with suffix .xaml
. The information of the Language Code can be found here AvailableLanguages.cs.
The Language Resource file will need to be a list of key/value pair. Follow the examples found here.
Plugins are required to implement IPublicI18n to let Flow load Language resources.
Implementing IResultUpdated provides a way to return part of the query results early. This is generally useful for plugins with long running queries.
To early return a result to Flow, you will need to invoke ResultUpdated
event with an ResultUpdatedEventArgs
, which includes the current Query
object and the List of Result
objects similar to the return value in Query(Async)
.
IDisposable Flow 1.8.0 or higher
Implementing IDisposable to dispose unmanaged resource in the plugin. Dispose()
will be called when Flow exit.