我有以下代码来监听firefox quit-application事件
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("myextension@extension.com", function(addon)
{
if (addon.userDisabled)
addon.userDisabled = false;
});
} catch (ex) {
}
}
这段代码应该在firefox重启后重新启用禁用的插件,但这根本不起作用。我无法在firefox退出后调试代码,因为错误控制台正在清除其log.So,我可以不能断定退出应用程序是否被触发或我的“setAddonEnableListener”是否有问题以启用插件。
请给我任何建议我做错了什么。
答案 0 :(得分:1)
我发现问题出在setAddonEnableListener()方法上,试试我已经替换了
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("myextension@extension.com", function(addon)
{
if (addon.userDisabled)
addon.userDisabled = false;
});
} catch (ex) {
}
}
有了这个,我可以重新启用我的插件。