Fixed 'Clear All IO' button

This commit is contained in:
n1474335 2023-02-03 15:54:45 +00:00
parent 0b2cb7e68c
commit 7a2517fd61
3 changed files with 31 additions and 19 deletions

View File

@ -262,6 +262,10 @@ class InputWaiter {
log.debug("Adding new InputWorker"); log.debug("Adding new InputWorker");
this.inputWorker = new InputWorker(); this.inputWorker = new InputWorker();
this.inputWorker.postMessage({
action: "setLogLevel",
data: log.getLevel()
});
this.inputWorker.postMessage({ this.inputWorker.postMessage({
action: "updateMaxWorkers", action: "updateMaxWorkers",
data: this.maxWorkers data: this.maxWorkers
@ -273,10 +277,7 @@ class InputWaiter {
activeTab: this.manager.tabs.getActiveTab("input") activeTab: this.manager.tabs.getActiveTab("input")
} }
}); });
this.inputWorker.postMessage({
action: "setLogLevel",
data: log.getLevel()
});
this.inputWorker.addEventListener("message", this.handleInputWorkerMessage.bind(this)); this.inputWorker.addEventListener("message", this.handleInputWorkerMessage.bind(this));
} }
@ -1103,8 +1104,11 @@ class InputWaiter {
this.manager.worker.setupChefWorker(); this.manager.worker.setupChefWorker();
this.addInput(true); this.addInput(true);
// Fire the statechange event as the input has been modified // Fire the statechange event as the input has been modified,
window.dispatchEvent(this.manager.statechange); // leaving enough time for workers to be initialised
setTimeout(function() {
window.dispatchEvent(this.manager.statechange);
}.bind(this), 100);
} }
/** /**

View File

@ -639,6 +639,7 @@ class OutputWaiter {
async bufferToStr(buffer) { async bufferToStr(buffer) {
const encoding = this.getChrEnc(); const encoding = this.getChrEnc();
if (buffer.byteLength === 0) return "";
return await new Promise(resolve => { return await new Promise(resolve => {
this.manager.worker.bufferToStr(buffer, encoding, r => { this.manager.worker.bufferToStr(buffer, encoding, r => {
resolve(r.value); resolve(r.value);

View File

@ -326,30 +326,36 @@ class WorkerWaiter {
* Cancels the current bake by terminating and removing all ChefWorkers * Cancels the current bake by terminating and removing all ChefWorkers
* *
* @param {boolean} [silent=false] - If true, don't set the output * @param {boolean} [silent=false] - If true, don't set the output
* @param {boolean} killAll - If true, kills all chefWorkers regardless of status * @param {boolean} [killAll=false] - If true, kills all chefWorkers regardless of status
*/ */
cancelBake(silent, killAll) { cancelBake(silent=false, killAll=false) {
const deactiveOutputs = new Set();
for (let i = this.chefWorkers.length - 1; i >= 0; i--) { for (let i = this.chefWorkers.length - 1; i >= 0; i--) {
if (this.chefWorkers[i].active || killAll) { if (this.chefWorkers[i].active || killAll) {
const inputNum = this.chefWorkers[i].inputNum; const inputNum = this.chefWorkers[i].inputNum;
this.removeChefWorker(this.chefWorkers[i]); this.removeChefWorker(this.chefWorkers[i]);
this.manager.output.updateOutputStatus("inactive", inputNum); deactiveOutputs.add(inputNum);
} }
} }
this.setBakingStatus(false); this.setBakingStatus(false);
for (let i = 0; i < this.inputs.length; i++) { this.inputs.forEach(input => {
this.manager.output.updateOutputStatus("inactive", this.inputs[i].inputNum); deactiveOutputs.add(input.inputNum);
} });
for (let i = 0; i < this.inputNums.length; i++) { this.inputNums.forEach(inputNum => {
this.manager.output.updateOutputStatus("inactive", this.inputNums[i]); deactiveOutputs.add(inputNum);
} });
deactiveOutputs.forEach(num => {
this.manager.output.updateOutputStatus("inactive", num);
});
const tabList = this.manager.tabs.getTabList("output"); const tabList = this.manager.tabs.getTabList("output");
for (let i = 0; i < tabList.length; i++) { tabList.forEach(tab => {
this.manager.tabs.getTabItem(tabList[i], "output").style.background = ""; this.manager.tabs.getTabItem(tab, "output").style.background = "";
} });
this.inputs = []; this.inputs = [];
this.inputNums = []; this.inputNums = [];
@ -567,7 +573,7 @@ class WorkerWaiter {
return await new Promise(resolve => { return await new Promise(resolve => {
if (this.app.baking) return; if (this.app.baking) return;
const inputNums = inputData.nums; const inputNums = inputData.nums.filter(n => n > 0);
const step = inputData.step; const step = inputData.step;
// Use cancelBake to clear out the inputs // Use cancelBake to clear out the inputs
@ -610,6 +616,7 @@ class WorkerWaiter {
}); });
this.loadingOutputs++; this.loadingOutputs++;
} }
if (numBakes === 0) this.bakingComplete();
}); });
} }