Flow-Launcher / docs

Flow Launcher documentation. How to develop, contribute, write new plugins and more!
https://flowlauncher.com/docs
14 stars 22 forks source link

For Python plugins, what is the data argument passing in the 'context_menu' function? #49

Open falldeaf opened 2 years ago

falldeaf commented 2 years ago

For some reason all of the plugin references (https://www.flowlauncher.com/docs/#/py-plugin-references) seem to implement a different API than the hello world plugin. It looks like because they're porting from Wox using the flox library, maybe?

So if I am opening a context menu, I need to pass through some kind of unique ID for whichever query result was selected. In the Steam plugin (https://github.com/Garulf/Steam-Search/blob/main/plugin/main.py) they're passing a 'context' variable through the 'add_item' method and getting that data in the data array, first index (data[0]).

In the Hello World example though, how can I get a UID for whichever query item was selected when entering the context menu?

Garulf commented 2 years ago

Sorry I some how missed this issue.

I think it's easiest to provide an example:

def query(self, query):
    results = []
    for i in range(10):
        results.append(
            {
                'Title': i,
                'SubTitle': 'Subtitle',
                'ContextData': ['context1', 'context2']
            }
        )
    print(json.dumps(results))

def context_menu(self, data):
    context1, context2 = data
    results = [
        {
            'Title': context1,
            'SubTitle': context2,
        }
    ]
    print(json.dumps(results))

When the context menu is invoked the ContextData field is passed to the context_menu method as a list.