Skip to content

Commit

Permalink
Merge pull request mozilla#41 from Osmose/fix-preferences
Browse files Browse the repository at this point in the history
Bug 1325797: Do not fail if the dev-mode pref is missing on startup.
  • Loading branch information
Mike Cooper authored Jan 4, 2017
2 parents 1a15295 + 413919a commit 75d581a
Showing 1 changed file with 6 additions and 16 deletions.
22 changes: 6 additions & 16 deletions bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const REASONS = {
};

const PREF_BRANCH = "extensions.shield-recipe-client.";
const PREFS = {
const DEFAULT_PREFS = {
api_url: "https://self-repair.mozilla.org/api/v1",
dev_mode: false,
enabled: true,
Expand All @@ -35,7 +35,7 @@ this.install = function() {
// next startup to run, unless the dev_mode preference is set.
if (Preferences.get(PREF_SELF_SUPPORT_ENABLED, true)) {
Preferences.set(PREF_SELF_SUPPORT_ENABLED, false);
if (!Services.prefs.getBoolPref(PREF_DEV_MODE, false)) {
if (!Preferences.get(PREF_DEV_MODE, false)) {
shouldRun = false;
}
}
Expand Down Expand Up @@ -82,21 +82,11 @@ this.uninstall = function() {
};

function setDefaultPrefs() {
const branch = Services.prefs.getDefaultBranch(PREF_BRANCH);
for (const [key, val] of Object.entries(PREFS)) {
for (const [key, val] of Object.entries(DEFAULT_PREFS)) {
const fullKey = PREF_BRANCH + key;
// If someone beat us to setting a default, don't overwrite it.
if (branch.getPrefType(key) !== branch.PREF_INVALID)
continue;
switch (typeof val) {
case "boolean":
branch.setBoolPref(key, val);
break;
case "number":
branch.setIntPref(key, val);
break;
case "string":
branch.setCharPref(key, val);
break;
if (!Preferences.isSet(fullKey)) {
Preferences.set(fullKey, val);
}
}
}

0 comments on commit 75d581a

Please sign in to comment.