Register shutdown handler to call Scholar.shutdown() on exit
This commit is contained in:
parent
635d2e48b9
commit
9a0457b43e
1 changed files with 21 additions and 0 deletions
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue