Skip to content

Instantly share code, notes, and snippets.

@past
Created June 26, 2012 14:26
Show Gist options
  • Save past/2996093 to your computer and use it in GitHub Desktop.
Save past/2996093 to your computer and use it in GitHub Desktop.
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
Components.utils.import("resource:///modules/devtools/gcli.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "AddonManager", "resource://gre/modules/AddonManager.jsm");
var addonCommandSpec = {
name: 'addon',
description: 'Manipulate Add-ons'
}
gcli.addCommand(addonCommandSpec);
var addonListCommandSpec = {
name: 'addon list',
description: 'List the available Add-ons',
exec: function(args, context) {
let promise = context.createPromise();
AddonManager.getAddonsByTypes(["extension"], function (addons) {
let enabledMap = {};
let disabledMap = {};
addons.forEach(function(e) {
if (e.userDisabled) {
disabledMap[e.name] = e;
} else {
enabledMap[e.name] = e;
}
});
let reply = 'The following Add-ons are installed:';
reply += '<ol>';
let names = Object.keys(enabledMap).sort(String.localeCompare);
for (let i of names) {
reply += '<li><![CDATA[' + i + ']]></li>';
}
let names = Object.keys(disabledMap).sort(String.localeCompare);
for (let i of names) {
reply += '<li style="color: #888; text-decoration: line-through;"><![CDATA[' + i + ']]></li>';
}
reply += '</ol>';
promise.resolve(reply);
});
return promise;
}
}
gcli.addCommand(addonListCommandSpec);
var addonEnableCommandSpec = {
name: 'addon enable',
description: 'Enable the specified Add-on',
params: [
{
name: 'name',
type: 'string',
description: 'The name of the Add-on',
}
],
exec: function(args, context) {
let promise = context.createPromise();
AddonManager.getAddonsByTypes(["extension"], function (addons) {
let addon, result;
for (let i of addons) {
if (i.name == args.name) {
addon = i;
break;
}
}
if (addon) {
addon.userDisabled = false;
result = addon.name + ' was enabled';
} else {
result = addon.name + ' was not found';
}
promise.resolve(result);
});
return promise;
}
}
gcli.addCommand(addonEnableCommandSpec);
var addonDisableCommandSpec = {
name: 'addon disable',
description: 'Disable the specified Add-on',
params: [
{
name: 'name',
type: 'string',
description: 'The name of the Add-on',
}
],
exec: function(args, context) {
let promise = context.createPromise();
AddonManager.getAddonsByTypes(["extension"], function (addons) {
let addon, result;
for (let i of addons) {
if (i.name == args.name) {
addon = i;
break;
}
}
if (addon) {
addon.userDisabled = true;
result = addon.name + ' was disabled';
} else {
result = addon.name + ' was not found';
}
promise.resolve(result);
});
return promise;
}
}
gcli.addCommand(addonDisableCommandSpec);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment