1
0
mirror of synced 2024-11-17 03:27:13 +01:00

Fix some weirdness with tabs.

Adjust worker logic to avoid closing and reopening a worker as often
This commit is contained in:
j433866 2019-04-03 16:05:10 +01:00
parent 9df26b8c84
commit 1eadc08098
4 changed files with 20 additions and 12 deletions

View File

@ -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);
}

View File

@ -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();

View File

@ -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]);

View File

@ -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