PluginDevelopmentGettingStarted » History » Version 13

« Previous - Version 13/14 (diff) - Next » - Current version
Leonid Protasov, 06/29/2015 08:45 AM

Getting Started

To develop a plugin for Movian it's easiest to load the plugin from shell (where command line arguments mean: -d debug, -p points to folder with plugin.json):


./build.linux/showtime -d -p testplugin

This will output something like:

plugins         [ERROR]: Unable to load development plugin: testplugin
                         Unable to load testplugin/plugin.json -- File not found

Go ahead and create the directory:

mkdir testplugin

Edit the JSON file with your favorite text editor:

emacs testplugin/plugin.json

And put the required fields in there:

  "type": "ecmascript",
  "file": "testplugin.js",
  "id": "testplugin" 

You can reload the development plugin at any time by pressing Shift+F5 in Movian (assuming you have not mapped that key/action to something else in the keymapper setup). This works fine even if the plugin failed to load for whatever reason. All hooks and resources that are registered by the plugin is automatically removed when the plugin is reloaded. The same procedure happens when a plugin is uninstalled from the plugin repository browser. Pressing Shift+F5 will also reload the data model for the current loaded page. If you have a page opened that links to your plugin in development mode Movian will first reload the plugin and then reload the page itself. This makes it very easy to do rapid development of plugins.

Now go ahead and edit the javascript file

emacs testplugin/testplugin.js

Put one single line in that file:

showtime.print('hello world');

Press Shift+F5 and the console window from where you started Movian
should say:

hello world
plugins [INFO]: Reloaded dev plugin testplugin/

Movian will just execute the plugin which only outputs 'Hello world' on the console and then exits. So, how to create something more interesting? First the javascript code needs to create a scope where its local variables will live and also need to remember 'this' which is, when the script is invoked, a plugin object created by Movian. Change the code to:

(function(plugin) {
  showtime.print("Hello! I'm a plugin running inside Movian " + showtime.currentVersionString);

Routing an URI to the plugin

Almost everything in Movian has an URI. This is used for crossplugin communications and interaction with user via unified search edit box at the top of the home screen. Each plugin registers URI starting with plugin's ID. URI routes registered by plugins override URI routes that Movian itself handle so it is possible to add routes for certain well known domains on the Internet (like .. )

Back to our test code:

(function(plugin) {
  plugin.addURI("testplugin:hello", function(page) {
    showtime.print("I was called");

Now, reload the plugin (Shift+F5) and type "testplugin:hello" in the search input field on Movian's home page. (Maybe you didn't know, but the search field can be used to open any valid Movian URI). Movian will open a new page with nothing but a spinning throbber and just print the console message. Not very exciting but it's a good start.