Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: lib/ui.js

Issue 29345630: Issue 4131 - Simplify UI initialization logic (Closed)
Patch Set: Created June 7, 2016, 4:21 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/ui.js
===================================================================
--- a/lib/ui.js
+++ b/lib/ui.js
@@ -272,75 +272,60 @@ let notificationTimer = null;
let UI = exports.UI =
{
/**
* Gets called on startup, initializes UI integration.
*/
init: function()
{
- // We should call initDone once both overlay and filters are loaded
- let overlayLoaded = false;
- let filtersLoaded = false;
- let sessionRestored = false;
+ // We have to wait for multiple events before running start-up actions
+ let promises = [];
Thomas Greiner 2016/06/08 15:47:32 Detail: That variable name is not very descriptive
Wladimir Palant 2016/06/08 20:51:30 Done.
// Start loading overlay
- let request = new XMLHttpRequest();
- request.mozBackgroundRequest = true;
- request.open("GET", "chrome://adblockplus/content/ui/overlay.xul");
- request.channel.owner = Utils.systemPrincipal;
- request.addEventListener("load", function(event)
+ promises.push(new Promise((resolve, reject) =>
{
- if (onShutdown.done)
- return;
+ let request = new XMLHttpRequest();
+ request.mozBackgroundRequest = true;
+ request.open("GET", "chrome://adblockplus/content/ui/overlay.xul");
+ request.channel.owner = Utils.systemPrincipal;
+ request.addEventListener("load", event =>
+ {
+ if (onShutdown.done)
+ return;
Thomas Greiner 2016/06/08 15:47:32 Instead of returning I'd suggest to resolve or rej
Wladimir Palant 2016/06/08 20:51:30 We don't really want to do anything with that prom
- this.processOverlay(request.responseXML.documentElement);
+ this.processOverlay(request.responseXML.documentElement);
- // Don't wait for the rest of the startup sequence, add icon already
- this.addToolbarButton();
+ // Don't wait for the rest of the startup sequence, add icon already
+ this.addToolbarButton();
- overlayLoaded = true;
- if (overlayLoaded && filtersLoaded && sessionRestored)
- this.initDone();
- }.bind(this), false);
- request.send(null);
+ resolve();
+ }, false);
+ request.send(null);
+ }));
// Wait for filters to load
if (FilterStorage._loading)
+ promises.push(FilterNotifier.once("load"));
+
+ // Wait for session to be restored
+ promises.push(new Promise((resolve, reject) =>
{
- let listener = function(action)
+ let window = this.currentWindow;
+ if (!window && "nsISessionStore" in Ci)
{
- if (action != "load")
- return;
+ // No application windows yet, the application must be starting up. Wait
+ // for session to be restored before initializing our UI.
+ new SessionRestoreObserver(resolve);
+ }
+ else
+ resolve();
+ }));
- FilterNotifier.removeListener(listener);
- filtersLoaded = true;
- if (overlayLoaded && filtersLoaded && sessionRestored)
- this.initDone();
- }.bind(this);
- FilterNotifier.addListener(listener);
- }
- else
- filtersLoaded = true;
-
- // Initialize UI after the session is restored
- let window = this.currentWindow;
- if (!window && "nsISessionStore" in Ci)
- {
- // No application windows yet, the application must be starting up. Wait
- // for session to be restored before initializing our UI.
- new SessionRestoreObserver(function()
- {
- sessionRestored = true;
- if (overlayLoaded && filtersLoaded && sessionRestored)
- this.initDone();
- }.bind(this));
- }
- else
- sessionRestored = true;
+ Promise.all(promises).then(() => this.initDone());
},
/**
* Provesses overlay document data and initializes overlay property.
*/
processOverlay: function(/**Element*/ root)
{
Utils.splitAllLabels(root);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld