Observer quit-application-granted not working?

Talk about add-ons and extension development.
Post Reply
dynamite-tom
Posts: 6
Joined: February 10th, 2009, 8:44 pm

Observer quit-application-granted not working?

Post by dynamite-tom »

Hello,

I've been searching all over the web for answers on this and I am not having any luck.

My question is this: My plugin has a cleanup-on-uninstall routine that I want to run. It is currently set to listen via observer-service for the topic "quit-application-granted". I am trying to get this to fire at the earliest opportunity that we know Firefox is quitting, as having the plugin uninstall itself and then another plugin aborting the shutdown would cause unpredictable behavior.

Here's the relevant code:

Code: Select all

////////////////////////////////////////////////////////////////////////////////
// extension uninstallation cleanup and quit notification
////////////////////////////////////////////////////////////////////////////////
const OBS_QUIT_REQUEST = "quit-application-requested";
const OBS_QUIT_GRANTED = "quit-application-granted";
const OBS_ACTION_REQUESTED = "em-action-requested";

function globalEventObserver() {
    this.register()
}

globalEventObserver.prototype = {

    observe: function(subject, topic, data) {

        dprint("globalEventObserver: Observed something (T=" + topic + ", S=" + subject.id + ", D=" + data + ")");

        if (topic == OBS_ACTION_REQUSTED) {

            subject.QueryInterface(Components.interfaces.nsIUpdateItem);

            if (subject.id == ddFirefoxID) {

                if (data == "item-uninstalled") {

                    nukePrefs = true;
                    dprint("globalEventObserver: User wants to uninstall me...");

                } else if (data == "item-cancel-action") {

                    nukePrefs = false;
                    dprint("globalEventObserver: User cancelled uninstall request.");

                }

            }
        } else if (topic == OBS_QUIT_REQUEST) {

            dprint("globalEventObserver: got program exit request!");

            abortSeti = true;

        } else if (topic == OBS_QUIT_GRANTED) {

            if (ddFirefoxUninstallOnExit) {

                var ourprefs = prefs.getBranch(prefprefix);

                var newpre = prefprefix.substring(0, prefprefix.length - 1);
                dprint("Removing all preferences under " & newpre);

                prefs.deleteBranch(newpre, "");

            }

        }
    },

    register: function() {
        var observerService = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
        observerService.addObserver(this, OBS_ACTION_REQUSTED, false);
        observerService.addObserver(this, OBS_QUIT_REQUEST, false);
        observerService.addObserver(this, OBS_QUIT_GRANTED, false);
    },

    unregister: function() {
        var observerService = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
        observerService.removeObserver(this, OBS_ACTION_REQEUST);
        observerService.removeObserver(this, OBS_QUIT_REQUEST);
        observerService.removeObserver(this, OBS_QUIT_GRANTED);
    }

}


The quit-application-requested code shuts down a background process that blocks FF from exiting, but as I said before it's abortable -- so I don't want this plugin uninstalling itself should the shutdown be aborted. Why is quit-application-granted not firing?

Thanks for your help. I spied one other thread here concerning this issue, but it didn't answer anything.

-Tom
ake79
Posts: 1344
Joined: February 17th, 2007, 6:05 am

Re: Observer quit-application-granted not working?

Post by ake79 »

You are listening in xpcom component? Or...?
My extensions: Save File to | ThumbsDown
dynamite-tom
Posts: 6
Joined: February 10th, 2009, 8:44 pm

Re: Observer quit-application-granted not working?

Post by dynamite-tom »

Sorry. The observer is registered in the plugin's startup code. em-action-requested works fine, as does quit-application-request. This code lives in a javascript shared code module.
ake79
Posts: 1344
Joined: February 17th, 2007, 6:05 am

Re: Observer quit-application-granted not working?

Post by ake79 »

Simplified version of the link below works just fine from browser.xul overlay. Dumps "quit-application-granted" as expected.

http://xulsolutions.blogspot.com/2006/0 ... t-for.html

Code: Select all

function initializeOverlay()
{
    UninstallObserver.register();
}

var UninstallObserver =
{
    observe: function(subject, topic, data)
    {
        dump(topic + "\n");
        if (topic == "quit-application-granted")
            this.unregister();
    },
   
    register: function()
    {
        var observerService = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
        observerService.addObserver(this, "quit-application-granted", false);
    },
   
    unregister: function()
    {
        var observerService = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
        observerService.removeObserver(this,"quit-application-granted");
    }
}

window.addEventListener("load", initializeOverlay, false);
My extensions: Save File to | ThumbsDown
Post Reply