Skip to content

Commit

Permalink
Create embedded webextension to support settings migration
Browse files Browse the repository at this point in the history
  • Loading branch information
mnoorenberghe committed Nov 10, 2017
1 parent fd6560c commit 485a925
Show file tree
Hide file tree
Showing 20 changed files with 73 additions and 1 deletion.
14 changes: 14 additions & 0 deletions .jpmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Ignore .DS_Store files created by mac
.*
\#*
*~

# Ignore any zip or xpi files
*.zip
*.xpi

/Makefile
/build.json
/demo/
/legacy/
/output/
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
build:
mkdir -p output
zip -r -FS output/bugzillajs.xpi js css icon.png icon64.png manifest.json
jpm xpi --dest-dir output/

lint:
jshint .
16 changes: 16 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"title": "BugzillaJS",
"description": "Add features to Bugzilla.",
"author": "Gregory Koberger / Matthew Noorenberghe",
"version": "4.0.0",
"main": "./sdk.js",
"id": "jid0-NgMDcEu2B88AbzZ6ulHodW9sJzA@jetpack",
"engines": {
"firefox": ">= 52.0a1",
"fennec": ">= 52.0a1"
},
"permissions": {
"multiprocess": true
},
"hasEmbeddedWebExtension": true
}
17 changes: 17 additions & 0 deletions sdk.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const webext = require("sdk/webextension");
const ss = require("sdk/simple-storage");

function setSyncLegacyDataPort(port) {
// Send the initial data dump.
port.postMessage({
storage: ss.storage,
});
};

webext.startup().then(({browser}) => {
browser.runtime.onConnect.addListener(port => {
if (port.name === "sync-legacy-addon-data") {
setSyncLegacyDataPort(port);
}
});
});
File renamed without changes.
Binary file added webextension/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added webextension/icon64.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions webextension/js/background.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"use strict";


function getSDKData() {
// Ask to the legacy part to dump the needed data and send it back
// to the background page...
var port = browser.runtime.connect({name: "sync-legacy-addon-data"});
port.onMessage.addListener((msg) => {
if (msg) {
// Where it can be saved using the WebExtensions storage API.
browser.storage.sync.set(msg.storage);
}
});
}

browser.storage.sync.get(null).then(stored => {
// If we don't have any data stored then import from the SDK.
if (Object.keys(stored).length === 0) {
getSDKData();
}
});
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 4 additions & 0 deletions manifest.json → webextension/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
}
},

"background": {
"scripts": ["js/background.js"]
},

"content_scripts": [
{
"matches": [
Expand Down

0 comments on commit 485a925

Please sign in to comment.