Hi there :-),
I am currently working with Gecko SDK/XULRunner 10.* and I am trying to
observe application on shutdown thanks to nsIObserverService. Well,
according to [1], it is possible to observe the topic
“quit-application*” but none of them seems to work with me (and it is a
little bit frustrating ;-)). Here is the code I use:
var applicationQuitObserver = {
get observerService ( ) {
return Cc['@
mozilla.org/observer-service;1'].getService(
Ci.nsIObserverService
);
},
observe: function ( subject, topic, data ) {
dump('Here?');
// Just as an example.
},
register: function ( ) {
dump('Register');
this.observerService.addObserver(this, 'quit-application-granted',
false);
},
unregister: function ( ) {
this.observerService.removeObserver(this,
'quit-application-granted', false);
}
};
applicationQuitObserver.register();
And when I close the window with the “close button” or with the
nsIAppStartup [2], the dump “Here?” does not appear in console whereas
the dump “Register” appears as expected. If you want to try, you can
start with the sample-app [3] proposed by Mark Finkle with the simple
following prefs.js:
pref("toolkit.defaultChromeURI", "chrome://myapp/content/main.xul");
pref("browser.dom.window.dump.enabled", true);
pref("javascript.options.showInConsole", true);
pref("javascript.options.strict", true);
pref("nglayout.debug.disable_xul_cache", true);
pref("nglayout.debug.disable_xul_fastload", true);
Immediatly, I thought the I/O was closed to early for me. So I have
tried to open a new file and writing in it. It works when I was
observing the topic “xul-window-visible” (for a test) but still not with
“quit-application*”.
So. Any thoughts?
Cheers.
[1] <
https://developer.mozilla.org/en/Observer_Notifications>
[2]
<
https://developer.mozilla.org/en/XPCOM_Interface_Reference/nsIAppStartup>
[3] <
https://developer.mozilla.org/en/Getting_started_with_XULRunner>
--
Ivan Enderlin
Developer of Hoa
http://hoa.42/ or
http://hoa-project.net/
PhD. student at DISC/Femto-ST (Vesontio) and INRIA (Cassis)
http://lifc.univ-fcomte.fr/ and
http://www.inria.fr/
Member of HTML and WebApps Working Group of W3C
http://w3.org/