javascript - Access Add-On SDK 'main' from XUL -


in add-on, i'm using xul display dialog windows because can customize appearance suit add-on's general style (like custom titlebar).

using migration guide, i'm able easily. thing is, call functions in add-on's main module xul dialog.

after bit of searching found loader module, seems able want. but, i'm experiencing trouble in using access main module.

first, tried obvious approach mentioned in documentation;

xul_dialog.js:

let {loader} = components.utils.import('resource://gre/modules/commonjs/toolkit/loader.js'); let loader = loader.loader({     paths: {         'toolkit/': 'resource://gre/modules/commonjs/toolkit/',         '': 'resource:///modules/',         './': 'resource://<my-addon-name>/root/'     } });  let main = loader.main(loader, './main'); 

i got error './main' not found @ resource://<my-addon-name>/root/. figuring using incorrect paths, experimented bit until remove path associated errors.

xul_dialog.js:

let {loader} = components.utils.import('resource://gre/modules/commonjs/toolkit/loader.js'); let loader = loader.loader({     paths: {         'toolkit/': 'resource://gre/modules/commonjs/toolkit/',         '': 'resource://gre/modules/commonjs/',         './': 'resource://<my-addon-id>-at-jetpack/<my-addon-name>/lib/'     } });  let main = loader.main(loader, './main'); 

this time got rather confusing error @ loader.js, line 279.

components not available in context. functionality provided components may available in sdk module: https://jetpack.mozillalabs.com/sdk/latest/docs/  however, if still need import components, may use `chrome` module's properties shortcuts component properties:  shortcuts:     cc = components.classes     ci = components.interfaces     cu = components.utils     cc = components.constructor example:     let { cc, ci } = require('chrome'); 

i same error when use loader.require(loader, {id: './main'}) instead of loader.main. tried passing components globals when instantiating loader, without luck.

i'm i'm doing lot of things wrong. don't understand why i'm getting error, after spending quite bit of time in loader.js. plus, think there better alternative having use add-on id path main.js; hard-coding doesn't seem right.

any appreciated.

what have find specific instance of loader, not create new one.

at main.js

const { id, name, prefixuri } = require("@loader/options"); //pass these xul dialog 

at xul.js (or whatever name of xul dialog script)

components.utils.import("resource://gre/modules/addons/xpiprovider.jsm"); var extensionscope = xpiprovider.bootstrapscopes[id]; var mainjssandbox = extensionscope.loader.sandboxes[prefixuri + name + "/lib/main.js"]; 

assuming there foo function @ main.js, can call like

 mainjssandbox.foo(); 

of course don't expect things work if xul , add-on sdk blended 1 thing.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -