2011-12-19 77 views
1

我有以下代碼聽火狐退出的應用程序事件無法重新啓用擴展的Firefox重新啓動後,如果擴展被禁用

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) { 
    } 
} 

此代碼應該重新啓用已禁用的插件的Firefox重啓發生後,但是這根本不起作用。當錯誤控制檯正在清除它的日誌時,我無法在firefox退出後調試代碼。因此,我無法斷定退出應用程序是否被解僱或者是否存在與我的「setAddonEnableListener」有關的問題插件。

請給我任何建議,我做錯了什麼。

回答

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("[email protected]", function(addon) 
    { 
    if (addon.userDisabled) 
     addon.userDisabled = false; 
    }); 

    } catch (ex) { 
    } 

      } 

有了這個我能夠重新啓用我的插件。