Register shutdown handler to call Scholar.shutdown() on exit

This commit is contained in:
Dan Stillman 2006-08-01 18:01:56 +00:00
parent 635d2e48b9
commit 9a0457b43e

View file

@ -14,10 +14,12 @@ const SCHOLAR_CONFIG = {
*/
var Scholar = new function(){
var _initialized = false;
var _shutdown = false;
var _localizedStringBundle;
// Privileged (public) methods
this.init = init;
this.shutdown = shutdown;
this.getProfileDirectory = getProfileDirectory;
this.getScholarDirectory = getScholarDirectory;
this.getStorageDirectory = getStorageDirectory;
@ -42,6 +44,15 @@ var Scholar = new function(){
return false;
}
// Register shutdown handler to call Scholar.shutdown()
var observerService = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService);
observerService.addObserver({
observe: function(subject, topic, data){
Scholar.shutdown(subject, topic, data)
}
}, "xpcom-shutdown", false);
// Load in the preferences branch for the extension
Scholar.Prefs.init();
@ -75,6 +86,16 @@ var Scholar = new function(){
}
function shutdown(subject, topic, data){
// Called twice otherwise, for some reason
if (_shutdown){
return false;
}
_shutdown = true;
}
function getProfileDirectory(){
return Components.classes["@mozilla.org/file/directory_service;1"]
.getService(Components.interfaces.nsIProperties)