Skip to content
This repository has been archived by the owner on Apr 3, 2020. It is now read-only.

Package an App with Extension hooks

Donna Wu edited this page Feb 22, 2016 · 2 revisions

What's an Crosswalk Extension Hooks?

Basicly, Crosswalk-app-tools will package web staff into an excutable intaller for a specified platform. In these web staff, we can including Crosswalk extensions, by specify the "xwalk_extensions:[]" array in the App's manifest.json file. These extensions will be included into the packaged installer and be installed in the end users' machine.

In some cases, these Crosswalk extensions may have some dependencies or need some customized actions during the package process. For example, for Crosswalk RealSense extensions, we'd like to including the RealSense runtime into our packaged installer. So, we provide a mechanism in Crosswalk-app-tools to take customized actions pre&post the "build" step. At these two packaging points, customized actions which are implemented in extensions hooks, will be triggered. These hooks will be customized nodejs script released together with extensions, and be triggerred during the packaging process.

How to write an Extension Hooks?

Conventions and rules about writing hooks.

  • Only Nodejs script hooks can be supported currently
  • Hooks module must have "prePackage" and "postPackage" interfaces, these interfaces will be called before and after the "build" step of Crosswalk-app-tools.
  • There are some resources from Crosswalk-app-tools hooks can leverage, these objects are be passed to the hooks, showed as the sample code below.

A sample skeleton hook script.

function XWalkExtensionHooks(app, configId, extraArgs, sharedState) {
    
    this._app = app;

    // The sharedState object is empty, but in can be used to
    // pass information from the prePackage() to postPackage()
    // because those hooks will run on a separate instance of
    // XWalkExtensionHooks.
    this._sharedState = sharedState;
}

XWalkExtensionHooks.prototype.prePackage =
function(platform, callback) {

    this._app.output.info("prePackage " + platform);

    // Store random message in sharedState
    this._sharedState.message = "prePackage finished";
    
    callback(0);
};

XWalkExtensionHooks.prototype.postPackage =
function(platform, callback) {
    
    this._app.output.info("postPackage " + platform);

    // Print message from sharedState
    this._app.output.info("postPackage " + this._sharedState.message);

    callback(0);
};

module.exports = XWalkExtensionHooks;

Conventions and rules about packaging an extension hooks.

  • Each extension folder item specified in the "xwalk_extensions" key of the manifest.json file, can have no more than one hooks script.
  • The name of the hooks script must be "XWalkExtensionHooks.js"

A sample Web App using extension hooks.

  • The content of the sample app
sample-app
├── index.html
├── manifest.json
└── realsense_extensions
    ├── enhanced_photography
    │   ├── enhanced_photography.dll
    │   └── XWalkExtensionHooks.js
    ├── face
    │   ├── face.dll
    │   └── XWalkExtensionHooks.js
    └── scene_perception
        ├── scene_perception.dll
        └── XWalkExtensionHooks.js
  • The manifest.json file will look like this:
{
  "name": "Crosswalk RealSense Sample App",
  "start_url": "index.html",
  "xwalk_package_id": "org.xwalk.rs_sample",
  "xwalk_extensions": [
    "realsense_extensions/enhanced_photography",
    "realsense_extensions/face",
    "realsense_extensions/scene_perception"]
}