Triggering Plugin methods
Flow Launcher can call custom methods created by your plugin as well. To do so simply register the method with your plugin.
You can register any Function by using the on_method
decorator or by using the add_method
method from Plugin
.
Example 1
from pyflowlauncher import Plugin, Result, send_results
from pyflowlauncher.result import ResultResponse
plugin = Plugin()
@plugin.on_method
def query(query: str) -> ResultResponse:
r = Result(
Title="This is a title!",
SubTitle="This is the subtitle!",
JsonRPCAction={"method": "action", "parameters": []}
)
return send_results([r])
@plugin.on_method
def action(params: list[str]):
pass
# Do stuff here
# ...
plugin.run()
Alternativley you can register and add the Method to a Result in one line by using action
method.
Example 2
from pyflowlauncher import Plugin, Result, send_results
from pyflowlauncher.result import ResultResponse
plugin = Plugin()
@plugin.on_method
def query(query: str) -> ResultResponse:
r = Result(
Title="This is a title!",
SubTitle="This is the subtitle!",
JsonRPCAction=plugin.action(action, ["stuff"])
)
return send_results([r])
def action(params: list[str]):
pass
# Do stuff here
# ...
plugin.run()