1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-20 08:27: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:
Kris Maglione
2011-08-21 03:48:53 -04:00
parent 9a378d467c
commit fd364645db
3 changed files with 40 additions and 31 deletions

34
common/bootstrap.js vendored
View File

@@ -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,14 +215,20 @@ 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)
@@ -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,7 +263,9 @@ function init() {
Services.obs.notifyObservers(null, "dactyl-rehash", null); Services.obs.notifyObservers(null, "dactyl-rehash", null);
updateVersion(); updateVersion();
require(global, "overlay");
if (addon !== addonData)
require(global, "overlay");
} }
function shutdown(data, reason) { function shutdown(data, reason) {

View File

@@ -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);
}, },
/** /**

View File

@@ -102,7 +102,7 @@ ProtocolBase.prototype = {
case "data": case "data":
try { try {
var channel = services.io.newChannel(uri.path.replace(/^\/(.*)(?:#.*)?/, "data:$1"), var channel = services.io.newChannel(uri.path.replace(/^\/(.*)(?:#.*)?/, "data:$1"),
null, null); null, null);
} }
catch (e) { catch (e) {
var error = e; var error = e;