diff options
author | Omar Rizwan <omar@omar.website> | 2021-04-22 18:31:43 -0700 |
---|---|---|
committer | Omar Rizwan <omar@omar.website> | 2021-04-22 18:31:43 -0700 |
commit | 1cd220febb4a6132897a1734d0d0414c04b3ea69 (patch) | |
tree | dc20c75b068459deab65c78122817e09d0b1d954 /extension/background.js | |
parent | 4ed3736a6123133c745bc85e6ba77720fc48f3fc (diff) | |
download | TabFS-1cd220febb4a6132897a1734d0d0414c04b3ea69.tar.gz TabFS-1cd220febb4a6132897a1734d0d0414c04b3ea69.zip |
extension: fix Chrome
Diffstat (limited to 'extension/background.js')
-rw-r--r-- | extension/background.js | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/extension/background.js b/extension/background.js index d2e2ac8..223cff2 100644 --- a/extension/background.js +++ b/extension/background.js @@ -1,3 +1,10 @@ +// This file is the heart of TabFS. Each route (synthetic file) is +// defined by an entry in the Routes object. You can live-edit this +// file by editing `runtime/background.js` in the mounted TabFS. I +// recommend editing the real `extension/background.js` on disk, but +// setting a hook to copy the file on top of runtime/background.js +// every time you Save. + const unix = { EPERM: 1, ENOENT: 2, @@ -614,14 +621,23 @@ Routes["/runtime/background.js"] = { }; Routes["/runtime/routes.html"] = routeWithContents(async () => { + const jsLines = (await window.backgroundJS).split('\n'); + function findRouteLineNumber(path) { + for (let i = 0; i < jsLines.length; i++) { + if (jsLines[i].includes(path)) { return i + 1; } + } + } return ` <html> <body> <dl> ${Object.entries(Routes).map(([path, {usage}]) => { - const usages = usage ? (Array.isArray(usage) ? usage : [usage]) : []; + path = path.substring(1); // drop leading / + let usages = usage ? (Array.isArray(usage) ? usage : [usage]) : []; + usages = usages.map(u => u.replace('\$0', path)); + const href = `https://github.com/osnr/TabFS/blob/master/extension/background.js#L${findRouteLineNumber(path)}`; return ` - <dt>${path}</dt> + <dt>${path} (<a href="${href}">source</a>)</dt> <dd>Usage: <ul> ${usages.map(u => `<li>${u}</li>`).join('\n')} @@ -889,7 +905,7 @@ function tryConnect() { } port = chrome.runtime.connectNative('com.rsnous.tabfs'); - port.onConnect.addListener(() => { window.isConnected = true; }); + window.isConnected = true; port.onMessage.addListener(onMessage); port.onDisconnect.addListener(p => { window.isConnected = false; |