From ab34a525dcafeb7e941748b67e05760839ffa4ff Mon Sep 17 00:00:00 2001 From: Omar Rizwan Date: Fri, 25 Dec 2020 15:54:53 -0800 Subject: [PATCH] add window symlink in tab folder --- extension/background.js | 17 ++++++++++++----- test.c | 2 +- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/extension/background.js b/extension/background.js index 4ef59e7..88e5996 100644 --- a/extension/background.js +++ b/extension/background.js @@ -242,6 +242,13 @@ router["/tabs/by-id"] = { router["/tabs/by-id/*/title.txt"] = withTab(tab => tab.title + "\n"); router["/tabs/by-id/*/text.txt"] = fromScript(`document.body.innerText`); })(); +router["/tabs/by-id/*/window"] = { + // a symbolic link to /windows/[id for this window] + async readlink({path}) { + const tabId = parseInt(pathComponent(path, -2)); const tab = await browser.tabs.get(tabId); + return { buf: "../../../windows/" + tab.windowId }; + } +}; router["/tabs/by-id/*/control"] = { // echo remove > mnt/tabs/by-id/1644/control async write({path, buf}) { @@ -318,9 +325,9 @@ router["/tabs/by-id/*/control"] = { })(); router["/tabs/by-title"] = { - getattr() { + getattr() { return { - st_mode: unix.S_IFDIR | 0777, // writable + st_mode: unix.S_IFDIR | 0777, // writable so you can delete tabs st_nlink: 3, st_size: 0, }; @@ -331,8 +338,8 @@ router["/tabs/by-title"] = { } }; router["/tabs/by-title/*"] = { - // a symbolic link to /tabs/by-id/[id for this tab] - async readlink({path}) { + // TODO: date + async readlink({path}) { // a symbolic link to /tabs/by-id/[id for this tab] const parts = path.split("_"); const tabId = parts[parts.length - 1]; return { buf: "../by-id/" + tabId }; }, @@ -434,7 +441,7 @@ for (let i = 10; i >= 0; i--) { if (TESTING) { // I wish I could color this section with... a pink background, or something. const assert = require('assert'); (async () => { - assert.deepEqual(await router['/tabs/by-id/*'].readdir(), { entries: ['.', '..', 'url.txt', 'title.txt', 'text.txt', 'control', 'debugger'] }); + assert.deepEqual(await router['/tabs/by-id/*'].readdir(), { entries: ['.', '..', 'url.txt', 'title.txt', 'text.txt', 'window', 'control', 'debugger'] }); assert.deepEqual(await router['/'].readdir(), { entries: ['.', '..', 'windows', 'extensions', 'tabs', 'runtime'] }); assert.deepEqual(await router['/tabs'].readdir(), { entries: ['.', '..', 'create', 'by-id', 'by-title', 'last-focused'] }); diff --git a/test.c b/test.c index 8164eb2..76b353d 100755 --- a/test.c +++ b/test.c @@ -24,7 +24,7 @@ char* expand(char* phrase) { // expand path with wildcard // integration tests int main() { - assert(system("node extension/background.js") == 0); // run quick local JS tests + assert(system("node extension/background.js --unhandled-rejections=strict") == 0); // run quick local JS tests // reload the extension so we know it's the latest code. system("echo reload > fs/mnt/runtime/reload"); // this may error, but it should still have effect