-
Notifications
You must be signed in to change notification settings - Fork 0
Devs Getting Started
Stardust D.L edited this page Apr 16, 2018
·
1 revision
- Add Reference
- reCLI.Core
- reCLI.Plugin
- reCLI.Plugin.UI (If you want to add icons)
- Write a class which implements the class
reCLI.Plugin.IPlugin- Your plugin will be called when user input your keyword at first.
- If you want to build a global query plugin, please implements the class
reCLI.Plugin.IGlobalQuery - Add
plugin.jsonto your output directory which contains your plugin's metadata. - You can use the PluginContext to access the public API.
A hello-world plugin.
using reCLI.Core;
using reCLI.Plugin;
using reCLI.Plugin.UI;
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Media;
using System.Windows.Media.Imaging;
namespace HelloWorld
{
public class Main : IPluginWithIcon, IGlobalQuery
{
PluginContext context;
ImageSource icon;
//The id that reCLI gives you on runtime
public Guid ID { get => context.ID; }
public string Name { get => "Hello World"; }
public string Description { get => "Hello World"; }
public ImageSource Icon => icon;
//Keyword to invoke your plugin
public string Keyword => "hw";
public Task<bool> Initialize(PluginContext context)
{
void LoadIcon()
{
}
return Task.Run(() =>
{
this.context = context;
LoadIcon();
return true;
});
}
public Task<IEnumerable<Answer>> Query(Query query)
{
return Task.Run(() =>
{
var result = new AnswerWithIcon
{
Title = "Hello World",
SubTitle = $"Query: {query.Arguments}",
OriginalQuery = $"hw {query.Arguments}",
Icon = icon,
Execute = _ =>
{
context.API.ShowMessage("Hello World, " + query.Arguments, TimeSpan.FromSeconds(2), MessageIcon.Success);
return Task.FromResult(Result.NotAutoHide);
}
};
return (IEnumerable<Answer>)(new Answer[] { result });
});
}
public Task<IEnumerable<Answer>> GlobalQuery(Query query) => Query(query);
public Task Uninitialize()
{
return Task.CompletedTask;
}
}
}{
"ID": "9F579291-E980-4A5A-B1CD-D001190DB6DD",//Guid, must be unique
"Name": "Hello World",
"Description": "Hello World",
"Author": "StardustDL",
"Version": "1.0.0",
"Website": "https://github.com/StardustDL",
"ExecuteFileName": "HelloWorld.dll",
"PluginTypes": [ "HelloWorld.Main" ] //You can added more than one type name which means different plugin
}