diff options
author | David Buckley <david@davidbuckley.ca> | 2021-01-04 13:19:04 -0500 |
---|---|---|
committer | David Buckley <david@davidbuckley.ca> | 2021-01-04 13:19:04 -0500 |
commit | daa3785d7cf3fe67c9ef518a3e4feeb51c888351 (patch) | |
tree | 9fe51ae8bdb2100f0b3bda2e4e5c194b64b06259 /extension | |
parent | 901d4c98109c6c7572983d2d69ccb82d0b679d8c (diff) | |
parent | 5905852cef957c4e0aa2f40721824f1d063a0d51 (diff) |
Merge branch 'master' of github.com:osnr/TabFS
Diffstat (limited to 'extension')
-rw-r--r-- | extension/background.js | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/extension/background.js b/extension/background.js index 1b1cad0..179a2b8 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() { @@ -632,7 +650,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 +672,7 @@ async function onMessage(req) { clearTimeout(timeout); console.log('resp', response); + response.id = req.id; port.postMessage(response); } }; |