aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOmar Rizwan <omar@omar.website>2020-12-24 13:49:38 -0800
committerOmar Rizwan <omar@omar.website>2020-12-24 13:49:38 -0800
commit2a67a62e2167f60138dc875552634ae549a5c7f9 (patch)
tree742a23095e8722852321b88fcc74924b3eda1779
parent760de1ac770329591f00e07a9537448bd6caf136 (diff)
better router infill logic; start work on /runtime/reload
-rw-r--r--README.md3
-rw-r--r--extension/background.js15
2 files changed, 13 insertions, 5 deletions
diff --git a/README.md b/README.md
index b35404d..0aefbcc 100644
--- a/README.md
+++ b/README.md
@@ -62,7 +62,7 @@ $ cat mnt/tabs/by-id/*/text > text.txt
### TODO: Reload an extension when you edit its source code
-Making anohter extension?
+Making another extension?
SO post.
@@ -236,3 +236,4 @@ Screenotate
rmdir a non-empty directory
+do you like setting up sockets? I don't
diff --git a/extension/background.js b/extension/background.js
index 5e40aab..700d0ad 100644
--- a/extension/background.js
+++ b/extension/background.js
@@ -343,14 +343,21 @@ router["/extensions/*/enabled"] = defineFile(async path => {
await browser.management.setEnabled(extensionId, buf.trim() === "true");
});
+router["/runtime/reload"] = {
+ async write({path, buf}) {
+ await browser.runtime.reload();
+ return {size: stringToUtf8Array(buf).length};
+ },
+ async truncate({path, size}) { return {}; }
+};
+
// Ensure that there are routes for all ancestors. This algorithm is
// probably not correct, but whatever. I also think it would be
// better to compute this stuff on the fly, so you could patch more
// routes in at runtime, but I need to think a bit about how to make
// that work with wildcards.
-for (let key in router) {
- let path = key;
- while (path !== "/") { // walk upward through the path
+for (let i = 10; i >= 0; i--) {
+ for (let path of Object.keys(router).filter(key => key.split("/").length === i)) {
path = path.substr(0, path.lastIndexOf("/"));
if (path == '') path = '/';
@@ -371,7 +378,7 @@ if (TESTING) { // I wish I could color this section with... a pink background, o
const assert = require('assert');
(async () => {
assert.deepEqual(await router['/tabs/by-id/*'].readdir(), { entries: ['.', '..', 'url', 'title', 'text', 'screenshot.png', 'resources', 'scripts', 'control'] });
- assert.deepEqual(await router['/'].readdir(), { entries: ['.', '..', 'extensions', 'tabs'] });
+ assert.deepEqual(await router['/'].readdir(), { entries: ['.', '..', 'extensions', 'tabs', 'runtime'] });
assert.deepEqual(await router['/tabs'].readdir(), { entries: ['.', '..', 'create', 'by-id', 'by-title', 'last-focused'] });
assert.deepEqual(findRoute('/tabs/by-id/TABID/url'), router['/tabs/by-id/*/url']);