Skip to content

Commit

Permalink
Merge pull request #726 from jonathanKingston/bootstrapify
Browse files Browse the repository at this point in the history
Bootstrapify
  • Loading branch information
groovecoder authored Aug 15, 2017
2 parents a44bf21 + 5704a21 commit 29f078d
Show file tree
Hide file tree
Showing 22 changed files with 171 additions and 2,105 deletions.
2 changes: 0 additions & 2 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
testpilot-metrics.js
lib/shield/*.js
lib/testpilot/*.js
7 changes: 6 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ module.exports = {
"CustomizableUI": true,
"CustomizableWidgets": true,
"SessionStore": true,
"Services": true
"Services": true,
"Components": true,
"XPCOMUtils": true,
"OS": true,
"ADDON_UNINSTALL": true,
"ADDON_DISABLE": true
},
"plugins": [
"promise",
Expand Down
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ Release & Beta channels do not allow un-signed add-ons, even with the DevPrefs.
5. Click the gear, and select "Install Add-on From File..."
6. Select the `.xpi` file

#### Correct prefs

Whilst this is still using legacy code to test you will need the following in your profile:


Change the following prefs in about:config:

- extensions.legacy.enabled = true
- xpinstall.signatures.required = false


#### Run the TxP experiment with `jpm`

1. `git clone git@github.com:mozilla/testpilot-containers.git`
Expand All @@ -49,23 +60,12 @@ Release & Beta channels do not allow un-signed add-ons, even with the DevPrefs.

Check out the [Browser Toolbox](https://developer.mozilla.org/en-US/docs/Tools/Browser_Toolbox) for more information about debugging add-on code.

#### Run the shield study with `shield`

1. `git clone git@github.com:mozilla/testpilot-containers.git`
2. `cd testpilot-containers`
3. `npm install`
4. `npm install -g shield-study-cli`
5. `shield run . -- --binary Nightly`

### Building .xpi

To build a local testpilot-containers.xpi, use the plain [`jpm
xpi`](https://developer.mozilla.org/en-US/Add-ons/SDK/Tools/jpm#jpm_xpi) command,
or run `npm run build`.

#### Building a shield .xpi
To build a local shield-study-containers.xpi, run `npm run build-shield`.

### Signing an .xpi

To sign an .xpi, use [`jpm
Expand Down
120 changes: 120 additions & 0 deletions bootstrap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
"use strict";

const PREFS = [
{
name: "privacy.userContext.enabled",
value: true,
type: "bool"
},
{
name: "privacy.userContext.longPressBehavior",
value: 2,
type: "int"
},
{
name: "privacy.userContext.ui.enabled",
value: true, // Post web ext we will be setting this true
type: "bool"
},
{
name: "privacy.usercontext.about_newtab_segregation.enabled",
value: true,
type: "bool"
},
];
const Ci = Components.interfaces;
const Cu = Components.utils;
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
const { TextDecoder, TextEncoder } = Cu.import("resource://gre/modules/commonjs/toolkit/loader.js", {});

XPCOMUtils.defineLazyModuleGetter(this, "OS",
"resource://gre/modules/osfile.jsm");

const JETPACK_DIR_BASENAME = "jetpack";
const EXTENSION_ID = "@testpilot-containers";

function filename() {
const storeFile = Services.dirsvc.get("ProfD", Ci.nsIFile);
storeFile.append(JETPACK_DIR_BASENAME);
storeFile.append(EXTENSION_ID);
storeFile.append("simple-storage");
storeFile.append("store.json");
return storeFile.path;
}

async function getConfig() {
const bytes = await OS.File.read(filename());
const raw = new TextDecoder().decode(bytes) || "";
let savedConfig = {savedConfiguration: {}};
if (raw) {
savedConfig = JSON.parse(raw);
}

return savedConfig;
}

async function initConfig() {
const savedConfig = await getConfig();
savedConfig.savedConfiguration.version = 2;
if (!("prefs" in savedConfig.savedConfiguration)) {
savedConfig.savedConfiguration.prefs = {};
PREFS.forEach((pref) => {
if ("int" === pref.type) {
savedConfig.savedConfiguration.prefs[pref.name] = Services.prefs.getIntPref(pref.name, pref.name);
} else {
savedConfig.savedConfiguration.prefs[pref.name] = Services.prefs.getBoolPref(pref.name, pref.value);
}
});
}
const serialized = JSON.stringify(savedConfig);
const bytes = new TextEncoder().encode(serialized) || "";
await OS.File.writeAtomic(filename(), bytes, { });
}

function setPrefs() {
PREFS.forEach((pref) => {
if ("int" === pref.type) {
Services.prefs.setIntPref(pref.name, pref.value);
} else {
Services.prefs.setBoolPref(pref.name, pref.value);
}
});
}

// eslint-disable-next-line no-unused-vars
async function install() {
await initConfig();
setPrefs();
}

// eslint-disable-next-line no-unused-vars
async function uninstall(aData, aReason) {
if (aReason === ADDON_UNINSTALL
|| aReason === ADDON_DISABLE) {
const config = await getConfig();
const storedPrefs = config.savedConfiguration.prefs;
PREFS.forEach((pref) => {
if (pref.name in storedPrefs) {
if ("int" === pref.type) {
Services.prefs.setIntPref(pref.name, storedPrefs[pref.name]);
} else {
Services.prefs.setBoolPref(pref.name, storedPrefs[pref.name]);
}
}
});
}
}

// eslint-disable-next-line no-unused-vars
function startup({webExtension}) {
// Reset prefs that may have changed, or are legacy
setPrefs();
// Start the embedded webextension.
webExtension.startup();
}

// eslint-disable-next-line no-unused-vars
function shutdown() {
}

Loading

0 comments on commit 29f078d

Please sign in to comment.