Bug 1355481 - Avoid initializing Sync on window unload if Sync is not configured. r?markh
MozReview-Commit-ID: J0xUODSMzhe
--- a/browser/base/content/browser-syncui.js
+++ b/browser/base/content/browser-syncui.js
@@ -54,28 +54,27 @@ var gSyncUI = {
// ready to start sending notifications.
this.updateUI();
Services.obs.addObserver(this, "weave:service:ready", true);
Services.obs.addObserver(this, "quit-application", true);
// Remove the observer if the window is closed before the observer
// was triggered.
- window.addEventListener("unload", function onUnload() {
- gSyncUI._unloaded = true;
- window.removeEventListener("unload", onUnload);
- Services.obs.removeObserver(gSyncUI, "weave:service:ready");
- Services.obs.removeObserver(gSyncUI, "quit-application");
+ window.addEventListener("unload", () => {
+ this._unloaded = true;
+ Services.obs.removeObserver(this, "weave:service:ready");
+ Services.obs.removeObserver(this, "quit-application");
- if (Weave.Status.ready) {
- gSyncUI._obs.forEach(function(topic) {
- Services.obs.removeObserver(gSyncUI, topic);
+ if (this.weaveService.ready) {
+ this._obs.forEach(topic => {
+ Services.obs.removeObserver(this, topic);
});
}
- });
+ }, { once: true });
},
initUI: function SUI_initUI() {
// If this is a browser window?
if (gBrowser) {
this._obs.push("weave:notification:added");
}