Use Services.obs instead of getService for observer service

This commit is contained in:
Simon Kornblith 2013-06-05 17:54:40 -04:00
parent a7984916ad
commit 5bde5a106b

View file

@ -217,8 +217,6 @@ Components.utils.import("resource://gre/modules/Services.jsm");
return false;
}
var observerService = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService);
var versionComparator = Components.classes["@mozilla.org/xpcom/version-comparator;1"]
.getService(Components.interfaces.nsIVersionComparator);
@ -425,7 +423,7 @@ Components.utils.import("resource://gre/modules/Services.jsm");
// Register shutdown handler to call Zotero.shutdown()
var _shutdownObserver = {observe:Zotero.shutdown};
observerService.addObserver(_shutdownObserver, "quit-application", false);
Services.obs.addObserver(_shutdownObserver, "quit-application", false);
try {
Zotero.IPC.init();
@ -459,7 +457,7 @@ Components.utils.import("resource://gre/modules/Services.jsm");
// Add shutdown listener to remove quit-application observer and console listener
this.addShutdownListener(function() {
observerService.removeObserver(_shutdownObserver, "quit-application", false);
Services.obs.removeObserver(_shutdownObserver, "quit-application", false);
cs.unregisterListener(ConsoleListener);
});
@ -496,17 +494,14 @@ Components.utils.import("resource://gre/modules/Services.jsm");
Zotero.Repo.init();
}
var observerService = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService);
if(!Zotero.isFirstLoadThisSession) {
// trigger zotero-reloaded event
Zotero.debug('Triggering "zotero-reloaded" event');
observerService.notifyObservers(Zotero, "zotero-reloaded", null);
Services.obs.notifyObservers(Zotero, "zotero-reloaded", null);
}
Zotero.debug('Triggering "zotero-loaded" event');
observerService.notifyObservers(Zotero, "zotero-loaded", null);
Services.obs.notifyObservers(Zotero, "zotero-loaded", null);
}
/**
@ -2352,9 +2347,7 @@ Zotero.VersionHeader = {
// Called from this.init() and Zotero.Prefs.observe()
register: function () {
var observerService = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService);
observerService.addObserver(this, "http-on-modify-request", false);
Services.obs.addObserver(this, "http-on-modify-request", false);
},
observe: function (subject, topic, data) {
@ -2370,9 +2363,7 @@ Zotero.VersionHeader = {
},
unregister: function () {
var observerService = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService);
observerService.removeObserver(Zotero.VersionHeader, "http-on-modify-request");
Services.obs.removeObserver(Zotero.VersionHeader, "http-on-modify-request");
}
}