Reputation: 1499
I have the following code to listen firefox quit-application event
observe: function(subject, topic, data)
{
if (topic == "profile-after-change" || topic == "app-startup") {
var os = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService);
// add observer for https response tracking
os.addObserver(this, "http-on-modify-request", false);
os.addObserver(this, "http-on-examine-response", false);
os.addObserver(this, "http-on-examine-cached-response", false);
os.addObserver(this, "quit-application", false);
}
else if (topic == "quit-application")
{
LOG("inside quit-application Testing ");
var os = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService);
os.removeObserver(this, "quit-application");
var appInfo = Components.classes["@mozilla.org/xre/app-info;1"]
.getService(Components.interfaces.nsIXULAppInfo);
var tempappVersion = appInfo.version;
var appVersion = tempappVersion.split(".");
if(appVersion[0] >= 4)
{
setAddonEnableListener();
}
return;
}
}
function setAddonEnableListener()
{
try {
LOG("inside setAddonEnableListener method ");
Components.utils.import("resource://gre/modules/AddonManager.jsm");
AddonManager.getAddonByID("[email protected]", function(addon)
{
if (addon.userDisabled)
addon.userDisabled = false;
});
} catch (ex) {
}
}
This code is supposed to re enable the disabled addon after firefox restart happens,but this is not at all working.I am not able to debug the code after firefox quits as the error console is clearing its log.So,I could not conclude whether the quit-application is fired or problem with my "setAddonEnableListener" to enable the addon.
Please give me any suggestions what I am doing wrong.
Upvotes: 1
Views: 189
Reputation: 1499
I have found the problem is with setAddonEnableListener() method,just as a try I have replaced
if (topic == "quit-application")
{
LOG("inside quit-application Testing ");
var os = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService);
os.removeObserver(this, "quit-application");
var appInfo = Components.classes["@mozilla.org/xre/app-info;1"]
.getService(Components.interfaces.nsIXULAppInfo);
var tempappVersion = appInfo.version;
var appVersion = tempappVersion.split(".");
if(appVersion[0] >= 4)
{
Components.utils.import("resource://gre/modules/AddonManager.jsm");
AddonManager.getAddonByID("[email protected]", function(addon)
{
if (addon.userDisabled)
addon.userDisabled = false;
});
} catch (ex) {
}
}
With this I am able to reenable my addon.
Upvotes: 1