Skip to content

Instantly share code, notes, and snippets.

@rpl
Last active March 31, 2016 13:10
Show Gist options
  • Save rpl/7e009f3a504128605ae2feef13c95a29 to your computer and use it in GitHub Desktop.
Save rpl/7e009f3a504128605ae2feef13c95a29 to your computer and use it in GitHub Desktop.
Small Firefox for Android addon which use 'rpl/fennec-addon-preferences-workaround' as a dependency to workaround the preferences issue.
// do your stuff or import your modules
const { on } = require("sdk/system/events");
const { id } = require("sdk/self");
console.log("ADDON ID: ", id);
on(`${id}-cmdPressed`, function ({data}) {
console.log("CMD PRESSED", data);
if (data == "readmeButton") {
addTab("http://developer.mozilla.org/");
}
}, true);
const isFennec = require("sdk/system/xul-app").is("Fennec");
// Handle "add a tab" on Mobile and Desktop
function addTab() {
if (isFennec) {
getBrowserApp().addTab("https://hacks.mozilla.org/");
} else {
require("sdk/tabs").open("https://hacks.mozilla.org/");
}
}
// Fennec specific code
require("fennec-addon-preferences-workaround");
const { Cu } = require("chrome");
Cu.import("resource://gre/modules/Services.jsm");
function getBrowserApp() {
let window = Services.wm.getMostRecentWindow("navigator:browser");
return window.BrowserApp;
}
{
"name": "test-fennec-prefs-addon",
"title": "test-fennec-prefs-addon",
"id": "jid1-g36rlQ3AKV2zow@jetpack",
"description": "a basic add-on to test addon preferences on Firefox for Android",
"author": "",
"license": "MPL-2.0",
"version": "1.1.0",
"engines": {
"firefox": ">=44.0",
"fennec": ">=44.0"
},
"preferences": [
{
"name": "somePreference",
"title": "Some preference title",
"description": "Some short description for the preference",
"type": "string",
"value": "this is the default string value"
},
{
"description": "How many of them we have.",
"name": "myInteger",
"type": "integer",
"value": 8,
"title": "How Many?"
},
{
"name": "readmeButton",
"label": "ReadMe",
"title": "ReadMe",
"description": "What it does, preferences, caveats",
"type": "control"
}
],
"dependencies": {
"fennec-addon-preferences-workaround": "github:rpl/fennec-addon-preferences-workaround"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment