Writing a plugin for Duck Launcher 0.69

the-duck edited this page Feb 8, 2015 · 5 revisions

#How to write plugins for Duck Launcher

For Duck Launcher version 0.69 and higher.

This wiki is aimed at explaining how to write plugins for Duck Launcher. We are going to create a very simple plugin, we'll prepare all the needed files, see how they work, install the plugin locally and finally we'll see how to upload it to Duck Launcher's plugin repository. ##What are plugins? #TODO ##Let's go! Let's start by creating a new folder. The name of the folder should be what will be used in the search query, for this example, we'll call it example-plugin. All the files that will be used for the plugin should be in that folder. Note that once a plugin is installed, it is stored in /usr/share/duck-launcher/plugins

Please make sure that the name of your plugin is not already taken.


The first, and the most important, file that we'll need is a python script, containing one main function and some additionnal ones.

Beware that Duck Launcher and its plugins are all written in python 2.7 and should not be in python 3.

The main one is the Search() function, which simply get arguments and returns some html code. Of course, it is recommended that you use a templating module (like Jinja2) to generate the html code you want. For our example plugin, we won't bother templating from a file.

def Search(query,**kwargs):
    #query=search query
    html="<html><body><h1>You've searched for: {}</h1></body></html>".format(query)
    return html 

If you need access to static files, the whole path of the file should be written in the html code (ie: "file:///usr/share/duck-launcher/plugins/example-plugin/logo.svg").

The next function is not required, but might be quite useful. Basically it's a function can be called by the javascript code within the html code. It allows you to send data from javascript to python, it has two arguments, one that should describe an object or an ID (a unique name letting you know what it is), the other should be its value.

def onDataSent(object,value):
    #ex: object="name", value="John"
    #do something with it...           


This is a json file, which gives basic information to Duck Launcher.
The first values are self-explanatory.
The modules value is a list containing all the python modules that should be installed, these are pip modules, so basically every module that you can install with sudo pip install <module> can be installed for your plugin.

Please make sure the modules you are adding are installable.

The background-color value defines the background color of the plugin, and the foreground-color value defines the font color. The combination of the two colors should be representative of the plugin itself. For example, if it uses a particular service, it should follow the service's brand colors. The recommended color combination is white for the foreground color and a colorul background color.

    "name":"Example Plugin",
    "author":"My Name <my@email.com>",

logo.svg When a plugin is activated, Duck Launcher looks for a logo, it should be an svg file and be named as such: logo.svg. It should represent either particular service's logo, an application's, or what the plugin is used for.
Its style should be flat and it should be the same colour as the foreground colour, however some exceptions can be made.

##Done..how can we install it? Duck Launcher comes with the duck-plugin binary, it allows you to install or remove plugins. Here's how to install a plugin locally:
duck-plugins install --local <path/to/plugin>
For our plugin, it would be :
duck-plugins install --local example-plugin/ ##Debugging Debugging is not super easy, you could run duck-launcher in a terminal, launch the plugin and watch for errors. Alternatively, the use of notifications, popup windows could help, or a better solution would be to write the errors(from the python script) to a log file.
##Uploading In order to get some plugins, Duck Launcher has a simple "Plugin Store"(feel free to offer another name for it) which lets users install the plugins that are hosted in Duck Launcher's dedicated repository. Currently there is no other way to upload a plugin than contacting us at theduck.dev@gmail.com

Clone this wiki locally
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.