Since we have created a CI for your plugin in the previous step, which includes creating a release when you push/merge to the 'main' branch, it is then necessary to create another git branch separate to your 'main' branch so you can continue to work on your plugin with git commits and pushes without creating a new release each time.
It is a good practice that you create a branch for each of the new feature/fixes you are releasing for your plugin, if you are not sure how to do so then follow this video tutorial. Once you have fully finished developing your plugin with your new branch, then you can merge it into the 'main' branch, which will consequently create a new release for your plugin with a version from your plugin.json
.
your main.js should look something like below:
const open = require('./node_modules/open');
const { method, parameters, settings } = JSON.parse(process.argv[2]);
if (method === "query") {
console.log(JSON.stringify(
{
"result": [{
"Title": "Hello World Typescript",
"Subtitle": "Showing your query parameters: " + parameters + ". Click to open Flow's website",
"JsonRPCAction": {
"method": "do_something_for_query",
"parameters": ["https://github.com/Flow-Launcher/Flow.Launcher"]
},
"IcoPath": "Images\\app.png",
"score" : 0
}]
}
));
}
if (method === "do_something_for_query") {
url = parameters[0];
do_something_for_query(url);
}
function do_something_for_query(url) {
open(url);
}
if (method === "query")
This if statement captures the args passed via JSON-RPC defined as const { method, parameters } = JSON.parse(process.argv[2])
, so if method
is 'query'
then the console.log's code block will be run. As the result
property is an array, you can also specify a single or multiple results.
JsonRPCAction
This is where you specify the method that will be executed when the user selects on the result.
In this example, if the user selects the result, the do_something_for_query
method will be called with the url parameter which opens the Flow Launcher GitHub repo.
The node.bat file is the entry Flow uses to call main.js, it will set the working directory to the plugin's own location before calling main.js with node.
@echo off
SET plugin_dir=%~dp0%
node "%plugin_dir%/main.js" %*
The score
field provides the ability to assign a weight to your score; the higher the score is, the higher the result from the plugin would show in flow's result list. The range in which you assign the score is usually between 0–100. You can keep it as 0 if your plugin generally uses an action keyword to trigger, but if you are using a global action keyword - *
then the average weight for a plugin would be 50. Additionally, users can tweak the score via Flow's plugin setting as well.
You will also need to, if not yet already, create a plugin.json file that will instruct Flow on how to load your plugin.
This file should be placed in the top level folder.
To revisit what to include in your plugin.json, visit here