From 1eadc08098b314306c0d35d5af6b9e84f3b940c8 Mon Sep 17 00:00:00 2001 From: j433866 Date: Wed, 3 Apr 2019 16:05:10 +0100 Subject: [PATCH] Fix some weirdness with tabs. Adjust worker logic to avoid closing and reopening a worker as often --- src/web/InputWaiter.mjs | 12 ++++++++---- src/web/Manager.mjs | 2 +- src/web/OutputWaiter.mjs | 4 ++-- src/web/WorkerWaiter.mjs | 14 +++++++++----- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/web/InputWaiter.mjs b/src/web/InputWaiter.mjs index 10021583..f8028bc4 100644 --- a/src/web/InputWaiter.mjs +++ b/src/web/InputWaiter.mjs @@ -170,7 +170,6 @@ class InputWaiter { */ closeFile(inputNum) { this.removeLoaderWorker(this.getLoaderWorker(inputNum)); - this.removeInput(inputNum); if (inputNum === this.getActiveTab()) { const fileOverlay = document.getElementById("input-file"), @@ -670,7 +669,9 @@ class InputWaiter { */ displayTabInfo(inputNum) { const tabItem = this.getTabItem(inputNum); - const input = this.inputs[this.getInputIndex(inputNum)]; + const index = this.getInputIndex(inputNum); + if (index === -1) return; + const input = this.inputs[index]; if (!tabItem) { return; } @@ -756,7 +757,6 @@ class InputWaiter { } else { inputNum = this.getLargestInputNum() + 1; } - this.inputs.push({ inputNum: inputNum, data: "", @@ -764,6 +764,7 @@ class InputWaiter { progress: 100 }); + this.manager.output.addOutput(inputNum, changeTab); const tabsWrapper = document.getElementById("input-tabs"); @@ -917,6 +918,7 @@ class InputWaiter { inputs.sort(function(a, b) { return b - a; }); + break; } if (reachedEnd) { newNum = this.getPreviousInputNum(inputs[i-1]); @@ -940,6 +942,7 @@ class InputWaiter { inputs.sort(function(a, b) { return b - a; }); + break; } if (reachedEnd) { newNum = this.getNextInputNum(inputs[i-1]); @@ -998,7 +1001,7 @@ class InputWaiter { const input = this.getInput(inputNum); if (typeof input === "string") { - this.set(this.getInput(inputNum)); + this.set(this.getInput(inputNum), true); } else { this.setFile(inputNum); } @@ -1157,6 +1160,7 @@ class InputWaiter { * Resets the input, output and info areas */ clearAllIoClick() { + this.manager.worker.cancelBake(); for (let i = this.inputs.length - 1; i >= 0; i--) { this.removeTab(this.inputs[i].inputNum); } diff --git a/src/web/Manager.mjs b/src/web/Manager.mjs index 02fdcfa3..8b0925fb 100755 --- a/src/web/Manager.mjs +++ b/src/web/Manager.mjs @@ -82,7 +82,7 @@ class Manager { * Sets up the various components and listeners. */ setup() { - this.input.addTab(); + this.input.addTab(true); this.input.setupLoaderWorker(); this.worker.setupChefWorker(); this.recipe.initialiseOperationDragNDrop(); diff --git a/src/web/OutputWaiter.mjs b/src/web/OutputWaiter.mjs index aadb7971..ca0ebd4b 100755 --- a/src/web/OutputWaiter.mjs +++ b/src/web/OutputWaiter.mjs @@ -408,13 +408,11 @@ class OutputWaiter { const zip = new Zlib.Zip(); for (let i = 0; i < this.outputs.length; i++) { const name = Utils.strToByteArray(this.outputs[i].inputNum + fileExt); - log.error(this.getOutput(this.outputs[i].inputNum)); let out = this.getOutput(this.outputs[i].inputNum); if (typeof out === "string") { out = Utils.strToUtf8ByteArray(out); } out = new Uint8Array(out); - log.error(out); // options.filename = Utils.strToByteArray(this.outputs[i].inputNum + ".dat"); zip.addFile(out, {filename: name}); } @@ -569,6 +567,7 @@ class OutputWaiter { nums.sort(function(a, b) { return b - a; }); + break; } if (reachedEnd) { newNum = this.getPreviousInputNum(nums[i-1]); @@ -592,6 +591,7 @@ class OutputWaiter { nums.sort(function(a, b) { return b - a; }); + break; } if (reachedEnd) { newNum = this.getNextInputNum(nums[i-1]); diff --git a/src/web/WorkerWaiter.mjs b/src/web/WorkerWaiter.mjs index 67209eae..f3a288a9 100644 --- a/src/web/WorkerWaiter.mjs +++ b/src/web/WorkerWaiter.mjs @@ -93,8 +93,10 @@ class WorkerWaiter { return; } - this.chefWorkers[index].worker.terminate(); - this.chefWorkers.splice(index, 1); + if (this.chefWorkers.length > 1 || this.chefWorkers[index].active) { + this.chefWorkers[index].worker.terminate(); + this.chefWorkers.splice(index, 1); + } // There should always be a ChefWorker loaded if (this.chefWorkers.length === 0) { @@ -158,6 +160,7 @@ class WorkerWaiter { } else { // The ChefWorker is no longer needed log.debug("No more inputs to bake. Closing ChefWorker."); + currentWorker.active = false; this.removeChefWorker(currentWorker); this.displayProgress(); @@ -216,7 +219,7 @@ class WorkerWaiter { this.manager.output.updateOutputValue(data, inputNum); this.manager.output.updateOutputStatus("baked", inputNum); - this.manager.recipe.updateBreakpointIndicator(this.app.progress); + // this.manager.recipe.updateBreakpointIndicator(this.app.progress); } /** @@ -280,11 +283,12 @@ class WorkerWaiter { // } // } - // What are these for? // Should be a value for each input, not just one + // Get store the progress for every output + // When we run set(), update the breakpoint indicator then // this.app.progress = this.outputs[0].data.progress; // this.app.dish = this.outputs[0].data.dish; - this.manager.recipe.updateBreakpointIndicator(this.app.progress); + // this.manager.recipe.updateBreakpointIndicator(this.app.progress); // Don't need to update the output here as updateOutput() will take care of that document.getElementById("bake").style.background = ""; this.totalOutputs = 0; // Reset for next time