瀏覽代碼

Fix switchClick not always being fired.
Run detectFileType on switched output

j433866 6 年之前
父節點
當前提交
c529a406cd
共有 2 個文件被更改,包括 21 次插入14 次删除
  1. 9 12
      src/web/waiters/OutputWaiter.mjs
  2. 12 2
      src/web/workers/InputWorker.mjs

+ 9 - 12
src/web/waiters/OutputWaiter.mjs

@@ -1229,18 +1229,15 @@ class OutputWaiter {
      * Handler for switch click events.
      * Moves the current output into the input textarea.
      */
-    switchClick() {
-        const active = this.getActive(true);
-        const transferable = (typeof active === "string" ? undefined : [active]);
-        if (typeof active === "string") {
-            this.manager.input.inputWorker.postMessage({
-                action: "inputSwitch",
-                data: {
-                    inputNum: this.manager.tabs.getActiveInputTab(),
-                    outputData: active
-                }
-            }, transferable);
-        }
+    async switchClick() {
+        const active = await this.getDishBuffer(this.getOutputDish(this.manager.tabs.getActiveOutputTab()));
+        this.manager.input.inputWorker.postMessage({
+            action: "inputSwitch",
+            data: {
+                inputNum: this.manager.tabs.getActiveInputTab(),
+                outputData: active
+            }
+        }, [active]);
     }
 
     /**

+ 12 - 2
src/web/workers/InputWorker.mjs

@@ -7,6 +7,7 @@
  */
 
 import Utils from "../../core/Utils";
+import {detectFileType} from "../../core/lib/FileType";
 
 self.maxWorkers = 4;
 self.maxTabs = 1;
@@ -1023,12 +1024,21 @@ self.inputSwitch = function(switchData) {
     if (currentInput === undefined || currentInput === null) return;
 
     if (typeof switchData.outputData === "object") {
+        const output = new Uint8Array(switchData.outputData),
+            types = detectFileType(output);
+        let type = "unknown",
+            ext = "dat";
+        if (types.length) {
+            type = types[0].mime;
+            ext = types[0].extension.split(",", 1)[0];
+        }
+
         // ArrayBuffer
         currentInput.data = {
             fileBuffer: switchData.outputData,
-            name: "output.dat",
+            name: `output.${ext}`,
             size: switchData.outputData.byteLength.toLocaleString(),
-            type: "unknown" // Could run detect file type here
+            type: type
         };
     } else {
         // String