diff options
author | Omar Rizwan <omar.rizwan@gmail.com> | 2019-03-02 12:16:08 -0800 |
---|---|---|
committer | Omar Rizwan <omar.rizwan@gmail.com> | 2019-03-02 12:16:08 -0800 |
commit | 53de6736feb5ab5d5a3039190ea770bfddc67ccf (patch) | |
tree | dd49243ebb0d6248fe6f73d986f45eb1c76c5d04 /extension | |
parent | a81c021204bcc46241ba9f1c2290f392d8bf8df2 (diff) |
write works to close tabs!
Diffstat (limited to 'extension')
-rw-r--r-- | extension/background.js | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/extension/background.js b/extension/background.js index 73bb579..b204876 100644 --- a/extension/background.js +++ b/extension/background.js @@ -198,6 +198,17 @@ const router = { throw new UnixError(unix.ENOENT); } } + }, + + "control": { + async write(path, buf) { + const tabId = parseInt(pathComponent(path, -2)); + if (buf.trim() === 'close') { + await new Promise(resolve => chrome.tabs.remove(tabId, resolve)); + } else { + throw new UnixError(unix.EIO); + } + } } } } @@ -223,10 +234,10 @@ async function getattr(path) { let route = findRoute(path); if (route.getattr) { return route.getattr(path); - } else if (route.read) { + } else if (route.read || route.write) { // default file attrs return { - st_mode: unix.S_IFREG | 0444, + st_mode: unix.S_IFREG | ((route.read && 0444) || (route.write && 0222)), st_nlink: 1, st_size: 100 // FIXME }; @@ -249,16 +260,20 @@ async function read(path, fh, size, offset) { let route = findRoute(path); if (route.read) return route.read(path, fh, size, offset); } -async function readlink(path) { +async function write(path, buf, offset) { let route = findRoute(path); - if (route.readlink) return route.readlink(path); + if (route.write) return route.write(path, buf, offset); } - async function release(path, fh) { let route = findRoute(path); if (route.release) return route.release(path, fh); } +async function readlink(path) { + let route = findRoute(path); + if (route.readlink) return route.readlink(path); +} + async function opendir(path) { let route = findRoute(path); if (route.opendir) return route.opendir(path); @@ -305,6 +320,14 @@ async function onmessage(event) { }; if (ret.base64Encoded) response.base64Encoded = ret.base64Encoded; + } else if (req.op === 'write') { + // FIXME: decide whether base64 should be handled here + // or in a higher layer? + const ret = await write(req.path, atob(req.buf), req.offset) + response = { + op: 'write' + }; + } else if (req.op === 'release') { await release(req.path, req.fh); response = { |