X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=common%2Fmodules%2Faddons.jsm;h=6f43950c46b44649bcb836869c4ecddb1ce5335b;hb=70740024f9c028c1fd63e1a1850ab062ff956054;hp=03c4e0fb9bf18ff2a4920dac0cdd5706b69fd975;hpb=eeed0be1a8abf7e3c97f43b63c1d595e940fef21;p=dactyl.git diff --git a/common/modules/addons.jsm b/common/modules/addons.jsm index 03c4e0f..6f43950 100644 --- a/common/modules/addons.jsm +++ b/common/modules/addons.jsm @@ -22,8 +22,8 @@ var callResult = function callResult(method) { var listener = function listener(action, event) function addonListener(install) { this.dactyl[install.error ? "echoerr" : "echomsg"]( - "Add-on " + action + " " + event + ": " + (install.name || install.sourceURI.spec) + - (install.error ? ": " + addonErrors[install.error] : "")); + _("addon.error", action, event, (install.name || install.sourceURI.spec) + + (install.error ? ": " + addons.errors[install.error] : ""))); } var AddonListener = Class("AddonListener", { @@ -59,17 +59,18 @@ var updateAddons = Class("UpgradeListener", AddonListener, { }, onUpdateAvailable: function (addon, install) { + util.dump("onUpdateAvailable"); this.upgrade.push(addon); install.addListener(this); install.install(); }, onUpdateFinished: function (addon, error) { - this.remaining = this.remaining.filter(function (a) a != addon); + this.remaining = this.remaining.filter(function (a) a.type != addon.type || a.id != addon.id); if (!this.remaining.length) this.dactyl.echomsg( this.upgrade.length - ? "Installing updates for addons: " + this.upgrade.map(function (i) i.name).join(", ") - : "No addon updates found"); + ? _("addon.installingUpdates", this.upgrade.map(function (i) i.name).join(", ")) + : _("addon.noUpdates")); } }); @@ -110,15 +111,15 @@ var actions = { name: "extr[ehash]", description: "Reload an extension", action: function (addon) { - util.assert(util.haveGecko("2b"), _("error.notUseful", config.host)); + util.assert(util.haveGecko("2b"), _("command.notUseful", config.host)); util.timeout(function () { addon.userDisabled = true; addon.userDisabled = false; }); }, get filter() { - let ids = set(keys(JSON.parse(prefs.get("extensions.bootstrappedAddons", "{}")))); - return function ({ item }) !item.userDisabled && set.has(ids, item.id); + let ids = Set(keys(JSON.parse(prefs.get("extensions.bootstrappedAddons", "{}")))); + return function ({ item }) !item.userDisabled && Set.has(ids, item.id); }, perm: "disable" }, @@ -151,11 +152,11 @@ var Addon = Class("Addon", { - On  - Off - Del - Upd - Opt + {_("addon.action.On")} + {_("addon.action.Off")} + {_("addon.action.Delete")} + {_("addon.action.Update")} + {_("addon.action.Options")} , @@ -165,7 +166,7 @@ var Addon = Class("Addon", { }, commandAllowed: function commandAllowed(cmd) { - util.assert(set.has(actions, cmd), "Unknown command"); + util.assert(Set.has(actions, cmd), _("addon.unknownCommand")); let action = actions[cmd]; if ("perm" in action && !(this.permissions & AddonManager["PERM_CAN_" + action.perm.toUpperCase()])) @@ -176,7 +177,7 @@ var Addon = Class("Addon", { }, command: function command(cmd) { - util.assert(this.commandAllowed(cmd), "Command not allowed"); + util.assert(this.commandAllowed(cmd), _("addon.commandNotAllowed")); let action = actions[cmd]; if (action.action) @@ -282,11 +283,11 @@ var AddonList = Class("AddonList", { XML.ignoreWhitespace = true; util.xmlToDom( - - - + + + +
NameVersionStatus{_("title.Name")}{_("title.Version")}{_("title.Status")} - Description{_("title.Description")}
, this.document, this.nodes); @@ -347,6 +348,11 @@ var AddonList = Class("AddonList", { }); var Addons = Module("addons", { + errors: Class.memoize(function () + array(["ERROR_NETWORK_FAILURE", "ERROR_INCORRECT_HASH", + "ERROR_CORRUPT_FILE", "ERROR_FILE_ACCESS"]) + .map(function (e) [AddonManager[e], _("AddonManager." + e)]) + .toObject()) }, { }, { commands: function (dactyl, modules, window) { @@ -393,7 +399,7 @@ var Addons = Module("addons", { else if (file.isDirectory()) dactyl.echoerr(_("addon.cantInstallDir", file.path.quote())); else - dactyl.echoerr(_("io.notReadable-1", file.path)); + dactyl.echoerr(_("io.notReadable", file.path)); }, { argCount: "1", completer: function (context) { @@ -413,11 +419,11 @@ var Addons = Module("addons", { function (args) { let name = args[0]; if (args.bang && !command.bang) - dactyl.assert(!name, _("error.trailing")); + dactyl.assert(!name, _("error.trailingCharacters")); else dactyl.assert(name, _("error.argumentRequired")); - AddonManager.getAddonsByTypes(["extension"], dactyl.wrapCallback(function (list) { + AddonManager.getAddonsByTypes(args["-types"], dactyl.wrapCallback(function (list) { if (!args.bang || command.bang) { list = list.filter(function (extension) extension.name == name); if (list.length == 0) @@ -433,13 +439,22 @@ var Addons = Module("addons", { }, { argCount: "?", // FIXME: should be "1" bang: true, - completer: function (context) { - completion.extension(context); + completer: function (context, args) { + completion.extension(context, args["-types"]); context.filters.push(function ({ item }) ok(item)); if (command.filter) context.filters.push(command.filter); }, - literal: 0 + literal: 0, + options: [ + { + names: ["-types", "-type", "-t"], + description: "The add-on types to operate on", + default: ["extension"], + completer: function (context, args) completion.addonType(context), + type: CommandOption.LIST + } + ] }); }); }, @@ -460,8 +475,8 @@ var Addons = Module("addons", { true)); }); } - } - } + }; + }; completion.extension = function extension(context, types) { context.title = ["Extension"]; @@ -494,27 +509,14 @@ else addon = this.wrapAddon(addon); return callback(addon); }, + wrapAddon: function wrapAddon(addon) { addon = Object.create(addon.QueryInterface(Ci.nsIUpdateItem)); - function getRdfProperty(item, property) { - let resource = services.rdf.GetResource("urn:mozilla:item:" + item.id); - let value = ""; - - if (resource) { - let target = services.extensionManager.datasource.GetTarget(resource, - services.rdf.GetResource("http://www.mozilla.org/2004/em-rdf#" + property), true); - if (target && target instanceof Ci.nsIRDFLiteral) - value = target.Value; - } - - return value; - } - ["aboutURL", "creator", "description", "developers", "homepageURL", "installDate", "optionsURL", "releaseNotesURI", "updateDate"].forEach(function (item) { - memoize(addon, item, function (item) getRdfProperty(this, item)); + memoize(addon, item, function (item) this.getProperty(item)); }); update(addon, { @@ -523,19 +525,33 @@ else appDisabled: false, + getProperty: function getProperty(property) { + let resource = services.rdf.GetResource("urn:mozilla:item:" + this.id); + + if (resource) { + let target = services.extensionManager.datasource.GetTarget(resource, + services.rdf.GetResource("http://www.mozilla.org/2004/em-rdf#" + property), true); + + if (target && target instanceof Ci.nsIRDFLiteral) + return target.Value; + } + + return ""; + }, + installLocation: Class.memoize(function () services.extensionManager.getInstallLocation(this.id)), getResourceURI: function getResourceURI(path) { let file = this.installLocation.getItemFile(this.id, path); return services.io.newFileURI(file); }, - isActive: getRdfProperty(addon, "isDisabled") != "true", + get isActive() this.getProperty("isDisabled") != "true", uninstall: function uninstall() { services.extensionManager.uninstallItem(this.id); }, - get userDisabled() getRdfProperty(addon, "userDisabled") === "true", + get userDisabled() this.getProperty("userDisabled") === "true", set userDisabled(val) { services.extensionManager[val ? "disableItem" : "enableItem"](this.id); } @@ -543,6 +559,7 @@ else return addon; }, + getAddonsByTypes: function (types, callback) { let res = []; for (let [, type] in Iterator(types)) @@ -554,6 +571,7 @@ else util.timeout(function () { callback(res); }); return res; }, + getInstallForFile: function (file, callback, mimetype) { callback({ addListener: function () {}, @@ -562,9 +580,11 @@ else } }); }, + getInstallForURL: function (url, callback, mimetype) { util.assert(false, _("error.unavailable", config.host, services.runtime.version)); }, + observers: [], addAddonListener: function (listener) { observer.listener = listener; @@ -595,12 +615,6 @@ else } }; -var addonErrors = array.toObject([ - [AddonManager.ERROR_NETWORK_FAILURE, "A network error occurred"], - [AddonManager.ERROR_INCORRECT_HASH, "The downloaded file did not match the expected hash"], - [AddonManager.ERROR_CORRUPT_FILE, "The file appears to be corrupt"], - [AddonManager.ERROR_FILE_ACCESS, "There was an error accessing the filesystem"]]); - endModule(); } catch(e){ if (isString(e)) e = Error(e); dump(e.fileName+":"+e.lineNumber+": "+e+"\n" + e.stack); }