mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-20 08:07:59 +01:00
Minor cleanup:
• Add some docs. • Don't close over the bootstrap global in the persistent storage singleton. • Don't load overlay until we have the addon object for util.addon (experimental). • Other minor cleanup.
This commit is contained in:
32
common/bootstrap.js
vendored
32
common/bootstrap.js
vendored
@@ -65,6 +65,9 @@ let components = {};
|
|||||||
let resources = [];
|
let resources = [];
|
||||||
let getURI = null;
|
let getURI = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Performs necessary migrations after a version change.
|
||||||
|
*/
|
||||||
function updateVersion() {
|
function updateVersion() {
|
||||||
try {
|
try {
|
||||||
function isDev(ver) /^hg|pre$/.test(ver);
|
function isDev(ver) /^hg|pre$/.test(ver);
|
||||||
@@ -77,6 +80,11 @@ function updateVersion() {
|
|||||||
|
|
||||||
localPrefs.set("lastVersion", addon.version);
|
localPrefs.set("lastVersion", addon.version);
|
||||||
|
|
||||||
|
// We're switching from a nightly version to a stable or
|
||||||
|
// semi-stable version or vice versa.
|
||||||
|
//
|
||||||
|
// Disable automatic updates when switching to nightlies,
|
||||||
|
// restore the default action when switching to stable.
|
||||||
if (!config.lastVersion || isDev(config.lastVersion) != isDev(addon.version))
|
if (!config.lastVersion || isDev(config.lastVersion) != isDev(addon.version))
|
||||||
addon.applyBackgroundUpdates = AddonManager[isDev(addon.version) ? "AUTOUPDATE_DISABLE" : "AUTOUPDATE_DEFAULT"];
|
addon.applyBackgroundUpdates = AddonManager[isDev(addon.version) ? "AUTOUPDATE_DISABLE" : "AUTOUPDATE_DEFAULT"];
|
||||||
}
|
}
|
||||||
@@ -99,6 +107,8 @@ function startup(data, reason) {
|
|||||||
AddonManager.getAddonByID(addon.id, function (a) {
|
AddonManager.getAddonByID(addon.id, function (a) {
|
||||||
addon = a;
|
addon = a;
|
||||||
updateVersion();
|
updateVersion();
|
||||||
|
if (typeof require !== "undefined")
|
||||||
|
require(global, "overlay");
|
||||||
});
|
});
|
||||||
|
|
||||||
if (basePath.isDirectory())
|
if (basePath.isDirectory())
|
||||||
@@ -120,6 +130,14 @@ function startup(data, reason) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An XPCOM class factory proxy. Loads the JavaScript module at *url*
|
||||||
|
* when an instance is to be created and calls its NSGetFactory method
|
||||||
|
* to obtain the actual factory.
|
||||||
|
*
|
||||||
|
* @param {string} url The URL of the module housing the real factory.
|
||||||
|
* @param {string} classID The CID of the class this factory represents.
|
||||||
|
*/
|
||||||
function FactoryProxy(url, classID) {
|
function FactoryProxy(url, classID) {
|
||||||
this.url = url;
|
this.url = url;
|
||||||
this.classID = Components.ID(classID);
|
this.classID = Components.ID(classID);
|
||||||
@@ -197,15 +215,21 @@ function init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (JSMLoader) {
|
if (JSMLoader) {
|
||||||
|
// Temporary hacks until platforms and dactyl releases that don't
|
||||||
|
// support Cu.unload are phased out.
|
||||||
if (Cu.unload) {
|
if (Cu.unload) {
|
||||||
|
// Upgrading from dactyl release without Cu.unload support.
|
||||||
Cu.unload(BOOTSTRAP_JSM);
|
Cu.unload(BOOTSTRAP_JSM);
|
||||||
for (let [name] in Iterator(JSMLoader.globals))
|
for (let [name] in Iterator(JSMLoader.globals))
|
||||||
Cu.unload(~name.indexOf(":") ? name : "resource://dactyl" + JSMLoader.suffix + "/" + name);
|
Cu.unload(~name.indexOf(":") ? name : "resource://dactyl" + JSMLoader.suffix + "/" + name);
|
||||||
}
|
}
|
||||||
else if (JSMLoader.bump != 6) // Temporary hack
|
else if (JSMLoader.bump != 6) {
|
||||||
|
// We're in a version without Cu.unload support and the
|
||||||
|
// JSMLoader interface has changed. Bump off the old one.
|
||||||
Services.scriptloader.loadSubScript("resource://dactyl" + suffix + "/bootstrap.jsm",
|
Services.scriptloader.loadSubScript("resource://dactyl" + suffix + "/bootstrap.jsm",
|
||||||
Cu.import(BOOTSTRAP_JSM, global));
|
Cu.import(BOOTSTRAP_JSM, global));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!JSMLoader || JSMLoader.bump !== 6 || Cu.unload)
|
if (!JSMLoader || JSMLoader.bump !== 6 || Cu.unload)
|
||||||
Cu.import(BOOTSTRAP_JSM, global);
|
Cu.import(BOOTSTRAP_JSM, global);
|
||||||
@@ -227,7 +251,9 @@ function init() {
|
|||||||
contractID: BOOTSTRAP_CONTRACT,
|
contractID: BOOTSTRAP_CONTRACT,
|
||||||
wrappedJSObject: {}
|
wrappedJSObject: {}
|
||||||
},
|
},
|
||||||
createInstance: function () this.instance
|
// Use Sandbox to prevent closure over this scope
|
||||||
|
createInstance: Cu.evalInSandbox("(function () this.instance)",
|
||||||
|
Cu.Sandbox(Cc["@mozilla.org/systemprincipal;1"].getService()))
|
||||||
});
|
});
|
||||||
|
|
||||||
Cc[BOOTSTRAP_CONTRACT].getService().wrappedJSObject.loader = !Cu.unload && JSMLoader;
|
Cc[BOOTSTRAP_CONTRACT].getService().wrappedJSObject.loader = !Cu.unload && JSMLoader;
|
||||||
@@ -237,6 +263,8 @@ function init() {
|
|||||||
|
|
||||||
Services.obs.notifyObservers(null, "dactyl-rehash", null);
|
Services.obs.notifyObservers(null, "dactyl-rehash", null);
|
||||||
updateVersion();
|
updateVersion();
|
||||||
|
|
||||||
|
if (addon !== addonData)
|
||||||
require(global, "overlay");
|
require(global, "overlay");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -140,21 +140,11 @@ var ConfigBase = Class("ConfigBase", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
get addonID() this.name + "@dactyl.googlecode.com",
|
get addonID() this.name + "@dactyl.googlecode.com",
|
||||||
addon: Class.memoize(function () {
|
|
||||||
let addon;
|
|
||||||
do {
|
|
||||||
addon = (JSMLoader.bootstrap || {}).addon;
|
|
||||||
if (addon && !addon.getResourceURI) {
|
|
||||||
util.reportError(Error(_("addon.unavailable")));
|
|
||||||
yield 10;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
while (addon && !addon.getResourceURI);
|
|
||||||
|
|
||||||
if (!addon)
|
addon: Class.memoize(function () {
|
||||||
addon = require("addons").AddonManager.getAddonByID(this.addonID);
|
return (JSMLoader.bootstrap || {}).addon ||
|
||||||
yield addon;
|
require("addons").AddonManager.getAddonByID(this.addonID);
|
||||||
}, true),
|
}),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The current application locale.
|
* The current application locale.
|
||||||
@@ -187,18 +177,10 @@ var ConfigBase = Class("ConfigBase", {
|
|||||||
if (f.isDirectory())).array;
|
if (f.isDirectory())).array;
|
||||||
}
|
}
|
||||||
|
|
||||||
function exists(pkg) {
|
function exists(pkg) services["resource:"].hasSubstitution("dactyl-locale-" + pkg);
|
||||||
try {
|
|
||||||
services["resource:"].getSubstitution(pkg);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
catch (e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return array.uniq([this.appLocale, this.appLocale.replace(/-.*/, "")]
|
return array.uniq([this.appLocale, this.appLocale.replace(/-.*/, "")]
|
||||||
.filter(function (locale) exists("dactyl-locale-" + locale))
|
.filter(exists)
|
||||||
.concat(res));
|
.concat(res));
|
||||||
}),
|
}),
|
||||||
|
|
||||||
@@ -210,10 +192,9 @@ var ConfigBase = Class("ConfigBase", {
|
|||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
bestLocale: function (list) {
|
bestLocale: function (list) {
|
||||||
let langs = Set(list);
|
|
||||||
return values([this.appLocale, this.appLocale.replace(/-.*/, ""),
|
return values([this.appLocale, this.appLocale.replace(/-.*/, ""),
|
||||||
"en", "en-US", iter(langs).next()])
|
"en", "en-US", list[0]])
|
||||||
.nth(function (l) Set.has(langs, l), 0);
|
.nth(Set.has(Set(list)), 0);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user