diff --git a/src/core/ChefWorker.js b/src/core/ChefWorker.js index cf4c164d..8b871c94 100644 --- a/src/core/ChefWorker.js +++ b/src/core/ChefWorker.js @@ -111,25 +111,14 @@ async function bake(data) { }) }); } catch (err) { - if (err instanceof DOMException) { - self.postMessage({ - action: "bakeError", - data: { - error: err.message, - id: data.id, - inputNum: data.inputNum - } - }); - } else { - self.postMessage({ - action: "bakeError", - data: { - error: err, - id: data.id, - inputNum: data.inputNum - } - }); - } + self.postMessage({ + action: "bakeError", + data: { + error: err.message || err, + id: data.id, + inputNum: data.inputNum + } + }); } self.inputNum = -1; } diff --git a/src/web/ControlsWaiter.mjs b/src/web/ControlsWaiter.mjs index b00f9e21..e7143875 100755 --- a/src/web/ControlsWaiter.mjs +++ b/src/web/ControlsWaiter.mjs @@ -69,7 +69,22 @@ class ControlsWaiter { * Handler for the 'Step through' command. Executes the next step of the recipe. */ stepClick() { - this.app.bake(true); + if (this.manager.worker.step) { + // Step has already been clicked so get the data from the output + const activeTab = this.manager.input.getActiveTab(); + this.manager.worker.queueInput({ + input: this.manager.output.getOutput(activeTab, true), + inputNum: activeTab + }); + this.app.progress = this.manager.output.outputs[activeTab].progress; + this.app.bake(true); + } else { + // First click of step, so get the output from the inputWorker + this.manager.input.inputWorker.postMessage({ + action: "step", + data: this.manager.input.getActiveTab() + }); + } } diff --git a/src/web/InputWaiter.mjs b/src/web/InputWaiter.mjs index 14ac01df..76846650 100644 --- a/src/web/InputWaiter.mjs +++ b/src/web/InputWaiter.mjs @@ -267,7 +267,7 @@ class InputWaiter { this.manager.worker.queueInput(r.data); break; case "bake": - this.app.bake(false); + this.app.bake(r.data); break; case "displayTabSearchResults": this.displayTabSearchResults(r.data); diff --git a/src/web/InputWorker.mjs b/src/web/InputWorker.mjs index 2c177542..ab88f705 100644 --- a/src/web/InputWorker.mjs +++ b/src/web/InputWorker.mjs @@ -82,7 +82,7 @@ self.addEventListener("message", function(e) { self.changeTabLeft(r.data.activeTab, r.data.nums); break; case "autobake": - self.autoBake(r.data); + self.autoBake(r.data, false); break; case "filterTabs": self.filterTabs(r.data); @@ -96,6 +96,9 @@ self.addEventListener("message", function(e) { case "updateTabHeader": self.updateTabHeader(r.data); break; + case "step": + self.autoBake(r.data, true); + break; default: log.error(`Unknown action '${r.action}'.`); } @@ -133,8 +136,10 @@ self.getLoadProgress = function(inputNum) { * Queues the active input and sends a bake command. * * @param {number} inputNum - The input to be baked + * @param {boolean} [step=false] - Set to true if we should only execute one operation instead of the + * whole recipe */ -self.autoBake = function(inputNum) { +self.autoBake = function(inputNum, step=false) { const input = self.getInputObj(inputNum); if (input) { let inputData = input.data; @@ -150,7 +155,8 @@ self.autoBake = function(inputNum) { } }); self.postMessage({ - action: "bake" + action: "bake", + data: step }); } }; @@ -179,7 +185,8 @@ self.bakeAllInputs = function() { } } self.postMessage({ - action: "bake" + action: "bake", + data: false }); }; diff --git a/src/web/OutputWaiter.mjs b/src/web/OutputWaiter.mjs index 8e21c2d3..72caf5b8 100755 --- a/src/web/OutputWaiter.mjs +++ b/src/web/OutputWaiter.mjs @@ -114,7 +114,8 @@ class OutputWaiter { statusMessage: `Input ${inputNum} has not been baked yet.`, error: null, status: "inactive", - bakeId: -1 + bakeId: -1, + progress: 0 }; this.outputs[inputNum] = newOutput; @@ -1300,7 +1301,6 @@ class OutputWaiter { }); } else if (output.status === "baked" && showBaked) { let data = this.getOutput(iNum, false).slice(0, 4096); - log.error(output); if (typeof data !== "string") { data = Utils.arrayBufferToStr(data); } diff --git a/src/web/WorkerWaiter.mjs b/src/web/WorkerWaiter.mjs index c0bf8ac7..b7f852e7 100644 --- a/src/web/WorkerWaiter.mjs +++ b/src/web/WorkerWaiter.mjs @@ -146,11 +146,15 @@ class WorkerWaiter { if (r.data.error) { this.app.handleError(r.data.error); this.manager.output.updateOutputError(r.data.error, inputNum, r.data.progress); - } else if (r.data.progress !== this.manager.recipe.getConfig().length) { - this.manager.output.updateOutputError(r.data.result, inputNum, r.data.progress); } else { this.updateOutput(r.data, r.data.inputNum, r.data.bakeId, r.data.progress); } + this.app.progress = r.data.progress; + + if (r.data.progress === this.recipeConfig.length) { + this.step = false; + } + this.workerFinished(currentWorker); break; case "bakeError": @@ -328,7 +332,7 @@ class WorkerWaiter { this.chefWorkers[workerIdx].inputNum = nextInput.inputNum; this.chefWorkers[workerIdx].active = true; const input = nextInput.input; - if (typeof input === "string") { + if (input instanceof ArrayBuffer || ArrayBuffer.isView(input)) { this.chefWorkers[workerIdx].worker.postMessage({ action: "bake", data: { @@ -340,7 +344,7 @@ class WorkerWaiter { inputNum: nextInput.inputNum, bakeId: this.bakeId } - }); + }, [input]); } else { this.chefWorkers[workerIdx].worker.postMessage({ action: "bake", @@ -353,7 +357,7 @@ class WorkerWaiter { inputNum: nextInput.inputNum, bakeId: this.bakeId } - }, [nextInput.input]); + }); } }