Reset prefs for new users on uninstall. Fixes #782
This commit is contained in:
parent
27b2a4b5f2
commit
10c4395efd
1 changed files with 40 additions and 20 deletions
48
bootstrap.js
vendored
48
bootstrap.js
vendored
|
@ -4,22 +4,26 @@ const PREFS = [
|
||||||
{
|
{
|
||||||
name: "privacy.userContext.enabled",
|
name: "privacy.userContext.enabled",
|
||||||
value: true,
|
value: true,
|
||||||
type: "bool"
|
type: "bool",
|
||||||
|
default: false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "privacy.userContext.longPressBehavior",
|
name: "privacy.userContext.longPressBehavior",
|
||||||
value: 2,
|
value: 2,
|
||||||
type: "int"
|
type: "int",
|
||||||
|
default: 0
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "privacy.userContext.ui.enabled",
|
name: "privacy.userContext.ui.enabled",
|
||||||
value: true, // Post web ext we will be setting this true
|
value: true, // Post web ext we will be setting this true
|
||||||
type: "bool"
|
type: "bool",
|
||||||
|
default: true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "privacy.usercontext.about_newtab_segregation.enabled",
|
name: "privacy.usercontext.about_newtab_segregation.enabled",
|
||||||
value: true,
|
value: true,
|
||||||
type: "bool"
|
type: "bool",
|
||||||
|
default: false
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
const Ci = Components.interfaces;
|
const Ci = Components.interfaces;
|
||||||
|
@ -66,14 +70,27 @@ function filename() {
|
||||||
return storeFile.path;
|
return storeFile.path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function makeFilepath() {
|
||||||
|
const storeFile = Services.dirsvc.get("ProfD", Ci.nsIFile);
|
||||||
|
storeFile.append(JETPACK_DIR_BASENAME);
|
||||||
|
await OS.File.makeDir(storeFile.path, { ignoreExisting: true });
|
||||||
|
storeFile.append(EXTENSION_ID);
|
||||||
|
await OS.File.makeDir(storeFile.path, { ignoreExisting: true });
|
||||||
|
storeFile.append("simple-storage");
|
||||||
|
await OS.File.makeDir(storeFile.path, { ignoreExisting: true });
|
||||||
|
}
|
||||||
|
|
||||||
async function getConfig() {
|
async function getConfig() {
|
||||||
|
let savedConfig = {savedConfiguration: {}};
|
||||||
|
try {
|
||||||
const bytes = await OS.File.read(filename());
|
const bytes = await OS.File.read(filename());
|
||||||
const raw = new TextDecoder().decode(bytes) || "";
|
const raw = new TextDecoder().decode(bytes) || "";
|
||||||
let savedConfig = {savedConfiguration: {}};
|
|
||||||
if (raw) {
|
if (raw) {
|
||||||
savedConfig = JSON.parse(raw);
|
savedConfig = JSON.parse(raw);
|
||||||
}
|
}
|
||||||
|
} catch (e) {
|
||||||
|
// ignore file read errors, sometimes they happen and I'm not sure if we can fix
|
||||||
|
}
|
||||||
return savedConfig;
|
return savedConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,14 +101,15 @@ async function initConfig() {
|
||||||
savedConfig.savedConfiguration.prefs = {};
|
savedConfig.savedConfiguration.prefs = {};
|
||||||
PREFS.forEach((pref) => {
|
PREFS.forEach((pref) => {
|
||||||
if ("int" === pref.type) {
|
if ("int" === pref.type) {
|
||||||
savedConfig.savedConfiguration.prefs[pref.name] = Services.prefs.getIntPref(pref.name, pref.name);
|
savedConfig.savedConfiguration.prefs[pref.name] = Services.prefs.getIntPref(pref.name);
|
||||||
} else {
|
} else {
|
||||||
savedConfig.savedConfiguration.prefs[pref.name] = Services.prefs.getBoolPref(pref.name, pref.value);
|
savedConfig.savedConfiguration.prefs[pref.name] = Services.prefs.getBoolPref(pref.name);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
const serialized = JSON.stringify(savedConfig);
|
const serialized = JSON.stringify(savedConfig);
|
||||||
const bytes = new TextEncoder().encode(serialized) || "";
|
const bytes = new TextEncoder().encode(serialized) || "";
|
||||||
|
await makeFilepath();
|
||||||
await OS.File.writeAtomic(filename(), bytes, { });
|
await OS.File.writeAtomic(filename(), bytes, { });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,14 +134,16 @@ async function uninstall(aData, aReason) {
|
||||||
if (aReason === ADDON_UNINSTALL
|
if (aReason === ADDON_UNINSTALL
|
||||||
|| aReason === ADDON_DISABLE) {
|
|| aReason === ADDON_DISABLE) {
|
||||||
const config = await getConfig();
|
const config = await getConfig();
|
||||||
const storedPrefs = config.savedConfiguration.prefs;
|
const storedPrefs = config.savedConfiguration.prefs || {};
|
||||||
PREFS.forEach((pref) => {
|
PREFS.forEach((pref) => {
|
||||||
|
let value = pref.default;
|
||||||
if (pref.name in storedPrefs) {
|
if (pref.name in storedPrefs) {
|
||||||
if ("int" === pref.type) {
|
value = storedPrefs[pref.name];
|
||||||
Services.prefs.setIntPref(pref.name, storedPrefs[pref.name]);
|
|
||||||
} else {
|
|
||||||
Services.prefs.setBoolPref(pref.name, storedPrefs[pref.name]);
|
|
||||||
}
|
}
|
||||||
|
if ("int" === pref.type) {
|
||||||
|
Services.prefs.setIntPref(pref.name, value);
|
||||||
|
} else {
|
||||||
|
Services.prefs.setBoolPref(pref.name, value);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -138,7 +158,7 @@ function startup({webExtension, resourceURI}) {
|
||||||
loadStyles(resourceURI);
|
loadStyles(resourceURI);
|
||||||
}
|
}
|
||||||
// Reset prefs that may have changed, or are legacy
|
// Reset prefs that may have changed, or are legacy
|
||||||
setPrefs();
|
install();
|
||||||
// Start the embedded webextension.
|
// Start the embedded webextension.
|
||||||
webExtension.startup();
|
webExtension.startup();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue