mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2026-01-03 19:54:12 +01:00
Update :extensions with live update and buttons like :downloads. Rename to :addons.
--HG-- extra : transplant_source : %CD%8A%D4L%5D%DD%5E6A%1A%02Gm%22%28%0E3%A6%B4%85
This commit is contained in:
@@ -9,7 +9,7 @@ try {
|
||||
var global = this;
|
||||
Components.utils.import("resource://dactyl/bootstrap.jsm");
|
||||
defineModule("services", {
|
||||
exports: ["AddonManager", "services"],
|
||||
exports: ["services"],
|
||||
use: ["util"]
|
||||
}, this);
|
||||
|
||||
@@ -86,84 +86,6 @@ var Services = Module("Services", {
|
||||
this.addClass("Xmlhttp", "@mozilla.org/xmlextras/xmlhttprequest;1", Ci.nsIXMLHttpRequest);
|
||||
this.addClass("ZipReader", "@mozilla.org/libjar/zip-reader;1", Ci.nsIZipReader, "open");
|
||||
this.addClass("ZipWriter", "@mozilla.org/zipwriter;1", Ci.nsIZipWriter);
|
||||
|
||||
if (!Ci.nsIExtensionManager || !this.extensionManager)
|
||||
Components.utils.import("resource://gre/modules/AddonManager.jsm");
|
||||
else
|
||||
global.AddonManager = {
|
||||
getAddonByID: function (id, callback) {
|
||||
callback = callback || util.identity;
|
||||
let addon = id;
|
||||
if (!isObject(addon))
|
||||
addon = services.extensionManager.getItemForID(id);
|
||||
if (!addon)
|
||||
return callback(null);
|
||||
addon = Object.create(addon);
|
||||
|
||||
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));
|
||||
});
|
||||
|
||||
update(addon, {
|
||||
|
||||
appDisabled: false,
|
||||
|
||||
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",
|
||||
|
||||
uninstall: function uninstall() {
|
||||
services.extensionManager.uninstallItem(this.id);
|
||||
},
|
||||
|
||||
get userDisabled() getRdfProperty(addon, "userDisabled") === "true",
|
||||
set userDisabled(val) {
|
||||
services.extensionManager[val ? "disableItem" : "enableItem"](this.id);
|
||||
}
|
||||
});
|
||||
|
||||
return callback(addon);
|
||||
},
|
||||
getAddonsByTypes: function (types, callback) {
|
||||
let res = [];
|
||||
for (let [, type] in Iterator(types))
|
||||
for (let [, item] in Iterator(services.extensionManager
|
||||
.getItemList(Ci.nsIUpdateItem["TYPE_" + type.toUpperCase()], {})))
|
||||
res.push(this.getAddonByID(item));
|
||||
return (callback || util.identity)(res);
|
||||
},
|
||||
getInstallForFile: function (file, callback, mimetype) {
|
||||
callback({
|
||||
addListener: function () {},
|
||||
install: function () {
|
||||
services.extensionManager.installItemFromFile(file, "app-profile");
|
||||
}
|
||||
});
|
||||
},
|
||||
getInstallForURL: function (url, callback, mimetype) {
|
||||
dactyl.assert(false, "Install by URL not implemented");
|
||||
},
|
||||
};
|
||||
},
|
||||
reinit: function () {},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user