checking if extension is disabled

Talk about add-ons and extension development.
Post Reply
ake79
Posts: 1344
Joined: February 17th, 2007, 6:05 am

checking if extension is disabled

Post by ake79 »

I'm trying find out if an extension is disabled or not. The following seems to work if extension is disabled manually by user from extension manager.

Code: Select all

function isExtensionEnabled(extId)
{
    var extMgr = Cc["@mozilla.org/extensions/manager;1"].getService(Ci.nsIExtensionManager);
    var extMgrDs = extMgr.datasource;
    var ext = extMgr.getItemForID(extId);
    if (! ext)
      return false;
    var rdfSvc = Cc["@mozilla.org/rdf/rdf-service;1"].getService(Ci.nsIRDFService);
    var source = rdfSvc.GetResource("urn:mozilla:item:" + ext.id);
    var property = rdfSvc.GetResource("http://www.mozilla.org/2004/em-rdf#userDisabled");
    var target = rdfSvc.GetLiteral("true");
    var disabled = extMgrDs.HasAssertion(source, property, target, true);
    return (! disabled);
}



But is that 'userDisabled' enough? While googling, I found code that used other properties (appDisabled, disabled and isDisabled) but didn't find any documentation about any of them.

Or if there's a simpler way (non-RDF) to do this, let me know.
My extensions: Save File to | ThumbsDown
User avatar
Rod Whiteley
Posts: 11480
Joined: December 6th, 2004, 3:41 am
Location: UK

Post by Rod Whiteley »

For most purposes you probably need isDisabled, which means userDisabled or appDisabled. That is the property that the user interface uses. See: http://lxr.mozilla.org/seamonkey/source ... js.in#8309

But it depends what you are really trying to achieve...
Rod
ake79
Posts: 1344
Joined: February 17th, 2007, 6:05 am

Post by ake79 »

Thanks Rod.

And I guess that 'disabled' property was used in some older versions:
http://lxr.mozilla.org/seamonkey/source/toolkit/mozapps/extensions/src/nsExtensionManager.js.in#3773
My extensions: Save File to | ThumbsDown
Post Reply