Search code examples
firefox-addonmozillaadd-on

Mozilla Browser exit Observer


I have implement "quit-application" Observer,

TestApp.ns(function() {
with (TestApp.Lib) {

    //Ci = Components.interfaces;

    theApp.ExitObserver = function() {},

    // Called on uninstall
    theApp.ExitObserver.prototype.observe = function(subject, topic, data){
        if (topic == "quit-application"){
            alert(" exit ");
        }

    };
    }
});

Im My Main.js file i called this ExitObserver as bellow.

theApp.exitObserver = new theApp.ExitObserver();
observerService.addObserver(theApp.exitObserver, "quit-application", false);

When user exit from browser my alert not working. Is there any issue in this implementation?


Solution

  • I would suggest simplifying your code first. Try this:

    var observerService = Components.classes["@mozilla.org/observer-service;1"]
                          .getService(Components.interfaces.nsIObserverService);
    observerService.addObserver(
        {
            observe: function(subject, topic, data) {
                alert(topic);
            }
        }, "quit-application", false);
    

    I'm afraid I can't test this on my platform, so forgive me for any typos. Please let me know what you run into!

    See also this thread.