From 3c8570ac52848544b33c805a764fbd00f244958e Mon Sep 17 00:00:00 2001
From: human <human@neet.fi>
Date: Sun, 3 Jan 2021 12:23:20 +0200
Subject: multi-threaded tabfs.c

---
 extension/background.js | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

(limited to 'extension')

diff --git a/extension/background.js b/extension/background.js
index 1b1cad0..370e106 100644
--- a/extension/background.js
+++ b/extension/background.js
@@ -632,7 +632,7 @@ async function onMessage(req) {
     // timeout is very useful because some operations just hang
     // (like trying to take a screenshot, until the tab is focused)
     didTimeout = true; console.error('timeout');
-    port.postMessage({ op: req.op, error: unix.ETIMEDOUT });
+    port.postMessage({ id: req.id, op: req.op, error: unix.ETIMEDOUT });
   }, 1000);
 
   /* console.time(req.op + ':' + req.path);*/
@@ -654,6 +654,7 @@ async function onMessage(req) {
     clearTimeout(timeout);
 
     console.log('resp', response);
+    response.id = req.id;
     port.postMessage(response);
   }
 };
-- 
cgit v1.2.3


From 8946ca34b872fe46b8abe2afd87e03b6be5bf6a0 Mon Sep 17 00:00:00 2001
From: tv <tv@krebsco.de>
Date: Sun, 3 Jan 2021 17:20:27 +0100
Subject: background.js: add /tabs/by-id/*/active

---
 extension/background.js | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

(limited to 'extension')

diff --git a/extension/background.js b/extension/background.js
index 1b1cad0..7851b22 100644
--- a/extension/background.js
+++ b/extension/background.js
@@ -344,6 +344,24 @@ router["/tabs/by-id/*/control"] = {
   },
   async truncate({path, size}) { return {}; }
 };
+router["/tabs/by-id/*/active"] = {
+  // echo true > mnt/tabs/by-id/1644/active
+  // cat mnt/tabs/by-id/1644/active
+  async read({path, fh, offset, size}) {
+    const tabId = parseInt(pathComponent(path, -2));
+    const tab = await browser.tabs.get(tabId);
+    const buf = (JSON.stringify(tab.active) + '\n').slice(offset, offset + size);
+    return { buf };
+  },
+  async write({path, buf}) {
+    if (buf.trim() === "true") {
+      const tabId = parseInt(pathComponent(path, -2));
+      await browser.tabs.update(tabId, { active: true });
+    }
+    return {size: stringToUtf8Array(buf).length};
+  },
+  async truncate({path, size}) { return {}; }
+};
 
 // debugger/ : debugger-API-dependent (Chrome-only)
 (function() {
-- 
cgit v1.2.3