浏览代码

Fixed 'Clear All IO' button

n1474335 2 年之前
父节点
当前提交
7a2517fd61
共有 3 个文件被更改,包括 31 次插入19 次删除
  1. 10 6
      src/web/waiters/InputWaiter.mjs
  2. 1 0
      src/web/waiters/OutputWaiter.mjs
  3. 20 13
      src/web/waiters/WorkerWaiter.mjs

+ 10 - 6
src/web/waiters/InputWaiter.mjs

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

+ 1 - 0
src/web/waiters/OutputWaiter.mjs

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

+ 20 - 13
src/web/waiters/WorkerWaiter.mjs

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