|
| 1 | +### 1. Start with a branch |
| 2 | +Since we have created a CI for your plugin in the [previous step](https://flow-launcher.github.io/docs/#/py-setup-project), which includes creating a release when you push/merge to the 'main' branch, it is then neccessary 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. |
| 3 | + |
| 4 | +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](https://www.gitkraken.com/learn/git/problems/create-git-branch). 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`. |
| 5 | + |
| 6 | +### 2. main.py |
| 7 | +your main.js should look something like below: |
| 8 | +``` |
| 9 | +const open = require('./node_modules/open') |
| 10 | +
|
| 11 | +const { method, parameters } = JSON.parse(process.argv[2]) |
| 12 | +
|
| 13 | +if (method === "query") { |
| 14 | + console.log(JSON.stringify( |
| 15 | + { |
| 16 | + "result": [{ |
| 17 | + "Title": "Hello World Typescript", |
| 18 | + "Subtitle": "Showing your query parameters: " + parameters + ". Click to open Flow's website", |
| 19 | + "JsonRPCAction": { |
| 20 | + "method": "do_something_for_query", |
| 21 | + "parameters": ["https://github.com/Flow-Launcher/Flow.Launcher"] |
| 22 | + }, |
| 23 | + "IcoPath": "Images\\app.png" |
| 24 | + }] |
| 25 | + } |
| 26 | + )); |
| 27 | +} |
| 28 | +
|
| 29 | +if (method === "do_something_for_query") { |
| 30 | + url = parameters[0] |
| 31 | + do_something_for_query(url) |
| 32 | +} |
| 33 | +
|
| 34 | +function do_something_for_query(url) { |
| 35 | + open(url); |
| 36 | +} |
| 37 | +``` |
| 38 | + |
| 39 | +<br/> |
| 40 | + |
| 41 | +### 3. Query entry point |
| 42 | +**if (method === "query")** |
| 43 | + |
| 44 | +This if statement captures the args passed viar JsonRPC 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 result is an array, you can also specify a single or multiple results. |
| 45 | + |
| 46 | +### 4. Assigning an action to your results |
| 47 | +**JsonRPCAction** |
| 48 | + |
| 49 | +This is where you specify the method that will be executed when the user selects on the result. |
| 50 | +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. |
| 51 | + |
| 52 | +### 5. node.bat |
| 53 | +The [node.bat](https://github.com/Flow-Launcher/Flow.Launcher.Plugin.HelloWorldNodeJS/blob/main/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. |
| 54 | +``` |
| 55 | +@echo off |
| 56 | +SET plugin_dir=%~dp0% |
| 57 | +node %plugin_dir%/main.js %* |
| 58 | +``` |
| 59 | + |
| 60 | +### 6. Your plugin.json |
| 61 | +You will also need to if not yet already, create a plugin.json file that will instruct Flow on how to load your plugin. |
| 62 | + |
| 63 | +This file should be placed in the top level folder. |
| 64 | + |
| 65 | +To revisit what to include in your plugin.json, visit [here](https://flow-launcher.github.io/docs/#/plugin.json) |
0 commit comments