diff --git a/src/core/ChefWorker.js b/src/core/ChefWorker.js index 5e45bd61..ac5d922a 100644 --- a/src/core/ChefWorker.js +++ b/src/core/ChefWorker.js @@ -12,6 +12,12 @@ import Chef from "./Chef.js"; // Set up Chef instance self.chef = new Chef(); +// Tell the app that the worker has loaded and is ready to operate +self.postMessage({ + action: "workerLoaded", + data: {} +}); + /** * Respond to message from parent thread. * diff --git a/src/web/App.js b/src/web/App.js index 946889f7..6bbb5e0b 100755 --- a/src/web/App.js +++ b/src/web/App.js @@ -54,6 +54,8 @@ App.prototype.setup = function() { this.resetLayout(); this.setCompileMessage(); this.loadURIParams(); + + this.appLoaded = true; this.loaded(); }; @@ -62,6 +64,10 @@ App.prototype.setup = function() { * Fires once all setup activities have completed. */ App.prototype.loaded = function() { + // Check that both the app and the worker have loaded successfully before + // removing the loading screen. + if (!this.worderLoaded || !this.appLoaded) return; + // Trigger CSS animations to remove preloader document.body.classList.add("loaded"); @@ -97,25 +103,20 @@ App.prototype.handleError = function(err) { App.prototype.setBakingStatus = function(bakingStatus) { this.baking = bakingStatus; - let inputLoadingIcon = document.querySelector("#input .title .loading-icon"), - outputLoadingIcon = document.querySelector("#output .title .loading-icon"), - inputElement = document.querySelector("#input-text"), - outputElement = document.querySelector("#output-text"); + let outputLoader = document.getElementById("output-loader"), + outputElement = document.getElementById("output-text"); if (bakingStatus) { - inputLoadingIcon.style.display = "inline-block"; - outputLoadingIcon.style.display = "inline-block"; - inputElement.classList.add("disabled"); - inputElement.disabled = true; - outputElement.classList.add("disabled"); - outputElement.disabled = true; + this.bakingStatusTimeout = setTimeout(function() { + outputElement.disabled = true; + outputLoader.style.visibility = "visible"; + outputLoader.style.opacity = 1; + }, 200); } else { - inputLoadingIcon.style.display = "none"; - outputLoadingIcon.style.display = "none"; - inputElement.classList.remove("disabled"); - inputElement.disabled = false; - outputElement.classList.remove("disabled"); + clearTimeout(this.bakingStatusTimeout); outputElement.disabled = false; + outputLoader.style.opacity = 0; + outputLoader.style.visibility = "hidden"; } }; @@ -160,6 +161,10 @@ App.prototype.handleChefMessage = function(e) { break; case "silentBakeComplete": break; + case "workerLoaded": + this.worderLoaded = true; + this.loaded(); + break; default: console.error("Unrecognised message from ChefWorker", e); break; diff --git a/src/web/ControlsWaiter.js b/src/web/ControlsWaiter.js index b419f95b..886cb46c 100755 --- a/src/web/ControlsWaiter.js +++ b/src/web/ControlsWaiter.js @@ -79,9 +79,6 @@ ControlsWaiter.prototype.setAutoBake = function(value) { */ ControlsWaiter.prototype.bakeClick = function() { this.app.bake(); - const outputText = document.getElementById("output-text"); - outputText.focus(); - outputText.setSelectionRange(0, 0); }; @@ -90,9 +87,6 @@ ControlsWaiter.prototype.bakeClick = function() { */ ControlsWaiter.prototype.stepClick = function() { this.app.bake(true); - const outputText = document.getElementById("output-text"); - outputText.focus(); - outputText.setSelectionRange(0, 0); }; diff --git a/src/web/html/index.html b/src/web/html/index.html index 69ea7139..a1fef8fb 100755 --- a/src/web/html/index.html +++ b/src/web/html/index.html @@ -76,7 +76,7 @@