diff options
author | Omar Rizwan <omar@omar.website> | 2021-02-19 10:32:28 -0800 |
---|---|---|
committer | Omar Rizwan <omar@omar.website> | 2021-02-19 10:32:28 -0800 |
commit | 07da85e36bd50eb5f328b7cf989e528e4b49e5d2 (patch) | |
tree | d587f030418791af72ed9cad24f593ad0566cdda /extension/background.js | |
parent | e24f0f8afaf21ec370339392fc0f94623222d8fe (diff) | |
download | TabFS-07da85e36bd50eb5f328b7cf989e528e4b49e5d2.tar.gz TabFS-07da85e36bd50eb5f328b7cf989e528e4b49e5d2.zip |
add WINDOW/focused
Diffstat (limited to 'extension/background.js')
-rw-r--r-- | extension/background.js | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/extension/background.js b/extension/background.js index 6898fe6..eef6939 100644 --- a/extension/background.js +++ b/extension/background.js @@ -242,7 +242,9 @@ router["/tabs/by-id"] = { // echo true > mnt/tabs/by-id/1644/active // cat mnt/tabs/by-id/1644/active router["/tabs/by-id/*/active"] = withTab(tab => JSON.stringify(tab.active) + '\n', - buf => ({ active: buf.trim() === "true" })); + // WEIRD: we do startsWith because you might end up with buf + // being "truee" (if it was "false", then someone wrote "true") + buf => ({ active: buf.startsWith("true") })); })(); (function() { let nextConsoleFh = 0; let consoleForFh = {}; @@ -494,6 +496,20 @@ router["/windows"] = { return { entries: [".", "..", ...windows.map(window => String(window.id))] }; } }; +(function() { + const withWindow = (readHandler, writeHandler) => defineFile(async path => { + const windowId = parseInt(pathComponent(path, -2)); + const window = await browser.windows.get(windowId); + return readHandler(window); + + }, writeHandler ? async (path, buf) => { + const windowId = parseInt(pathComponent(path, -2)); + await browser.windows.update(windowId, writeHandler(buf)); + } : undefined); + + router["/windows/*/focused"] = withWindow(window => JSON.stringify(window.focused) + '\n', + buf => ({ focused: buf.startsWith('true') })); +})(); router["/windows/last-focused"] = { // a symbolic link to /windows/[id for this window] async readlink({path}) { |