From e51586a78cf3089c3aa4d10edb7e17be9deb74e5 Mon Sep 17 00:00:00 2001 From: Garret Alfert Date: Tue, 13 Jun 2017 13:13:59 +0200 Subject: [PATCH 1/2] Pause app boot until window load event fired Refs #17 Allows the user provided Web3 instance to be inserted before we try to use it. --- app/initializers/defer-loading.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 app/initializers/defer-loading.js diff --git a/app/initializers/defer-loading.js b/app/initializers/defer-loading.js new file mode 100644 index 0000000..c6e8c28 --- /dev/null +++ b/app/initializers/defer-loading.js @@ -0,0 +1,15 @@ +/** + * This pauses the app's boot process until the window load event is fired. + * It allows the user provided Web3 instance (e.g. Metamask, Mist Browser) + * to be inserted before we try to use it. + */ +export default { + name: 'defer-loading', + initialize: function(application) { + application.deferReadiness(); + + window.addEventListener('load', function() { + application.advanceReadiness(); + }); + } +}; From 993cd85e4a8a886d1f8a8f1c3c5149d9422c5569 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Tue, 13 Jun 2017 14:26:00 +0200 Subject: [PATCH 2/2] Improve waiting for window.onload In case the window load event was fired before getting to the Ember initializer, it would pause app loading indefinitely. This makes sure that app loading is only paused, if there's still an event to wait for. --- app/index.html | 6 ++++++ app/initializers/defer-loading.js | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/app/index.html b/app/index.html index 37dc05a..c2635b4 100644 --- a/app/index.html +++ b/app/index.html @@ -13,6 +13,12 @@ {{content-for "head-footer"}} + + {{content-for "body"}} diff --git a/app/initializers/defer-loading.js b/app/initializers/defer-loading.js index c6e8c28..6cd1b14 100644 --- a/app/initializers/defer-loading.js +++ b/app/initializers/defer-loading.js @@ -6,9 +6,14 @@ export default { name: 'defer-loading', initialize: function(application) { + // Load event already fired, so web3 should be loaded if available + if (window.windowLoadComplete) { return true; } + + // Pause app loading application.deferReadiness(); window.addEventListener('load', function() { + // Continue app loading application.advanceReadiness(); }); }