|
| 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.py should look something like below: |
| 8 | +``` |
| 9 | +import sys,os |
| 10 | +parent_folder_path = os.path.abspath(os.path.dirname(__file__)) |
| 11 | +sys.path.append(parent_folder_path) |
| 12 | +sys.path.append(os.path.join(parent_folder_path, 'lib')) |
| 13 | +sys.path.append(os.path.join(parent_folder_path, 'plugin')) |
| 14 | +
|
| 15 | +from flowlauncher import FlowLauncher |
| 16 | +
|
| 17 | +
|
| 18 | +class HelloWorld(FlowLauncher): |
| 19 | +
|
| 20 | + def query(self, query): |
| 21 | + return [ |
| 22 | + { |
| 23 | + "Title": "Hello World, this is where title goes. {}".format(('Your query is: ' + query , query)[query == '']), |
| 24 | + "SubTitle": "This is where your subtitle goes", |
| 25 | + "IcoPath": "Images/app.png", |
| 26 | + "JsonRPCAction": { |
| 27 | + "method": "do_something_for_query", |
| 28 | + "parameters": [param1, param2] |
| 29 | + } |
| 30 | + "ContextData": "ctxData", |
| 31 | + } |
| 32 | + ] |
| 33 | +
|
| 34 | + def context_menu(self, data): |
| 35 | + return [ |
| 36 | + { |
| 37 | + "Title": "Context menu entry", |
| 38 | + "SubTitle": "Data: {}".format(data), |
| 39 | + "IcoPath": "Images/app.ico", |
| 40 | + } |
| 41 | + ] |
| 42 | +
|
| 43 | + def do_something_for_query(self, param1, param2): |
| 44 | + pass |
| 45 | +
|
| 46 | +if __name__ == "__main__": |
| 47 | + HelloWorld() |
| 48 | +
|
| 49 | +``` |
| 50 | + |
| 51 | +<br/> |
| 52 | + |
| 53 | +### 3. Query entry point |
| 54 | +**def query(self, query):** |
| 55 | + |
| 56 | +This is the main entry to your plugin and the return block will be a list of the results that your plugin returns, which could be a single or many results. |
| 57 | + |
| 58 | +### 4. Assigning an action to your results |
| 59 | +**JsonRPCAction** |
| 60 | + |
| 61 | +This is where you specify the method that will be executed when the user selects on the result. |
| 62 | +In this example, if the user selects the result, the `do_something_for_query` method will be called with the two parameters, it is then up to you to define what you want the method to do. |
| 63 | + |
| 64 | +### 5. Create an additional context menu |
| 65 | +**def context_menu(self, data):** |
| 66 | + |
| 67 | +This method creates a context menu for your results, where the user can carry out additional tasks when the go to the context menue via pressing `Shift + Enter`. A context menu could be helpful if you want some tasks specific to your returned results, for example the Explorer plugin would return a list of file results, and when going to the context menu of one of the result users can select to copy the file. |
| 68 | + |
| 69 | +To attach a method to your context menu result, do the same as for normal results where you define a JsonRPCAction item with the method and parameters you want to call and pass through. |
| 70 | + |
| 71 | +### 6. Your plugin.json |
| 72 | + |
| 73 | +You will also need to if not yet already, create a plugin.json file that will instruct Flow on how to load your plugin. |
| 74 | + |
| 75 | +This file should be placed in the top level folder. |
| 76 | + |
| 77 | +To revisit what to include in your plugin.json, visit [here](https://flow-launcher.github.io/docs/#/plugin.json) |
0 commit comments