mirror of
https://github.com/osnr/TabFS.git
synced 2024-05-16 20:46:37 +02:00
better router infill logic; start work on /runtime/reload
This commit is contained in:
parent
760de1ac77
commit
2a67a62e21
|
@ -62,7 +62,7 @@ $ cat mnt/tabs/by-id/*/text > text.txt
|
||||||
|
|
||||||
### TODO: Reload an extension when you edit its source code
|
### TODO: Reload an extension when you edit its source code
|
||||||
|
|
||||||
Making anohter extension?
|
Making another extension?
|
||||||
|
|
||||||
SO post.
|
SO post.
|
||||||
|
|
||||||
|
@ -236,3 +236,4 @@ Screenotate
|
||||||
|
|
||||||
rmdir a non-empty directory
|
rmdir a non-empty directory
|
||||||
|
|
||||||
|
do you like setting up sockets? I don't
|
||||||
|
|
|
@ -343,14 +343,21 @@ router["/extensions/*/enabled"] = defineFile(async path => {
|
||||||
await browser.management.setEnabled(extensionId, buf.trim() === "true");
|
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
|
// Ensure that there are routes for all ancestors. This algorithm is
|
||||||
// probably not correct, but whatever. I also think it would be
|
// probably not correct, but whatever. I also think it would be
|
||||||
// better to compute this stuff on the fly, so you could patch more
|
// 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
|
// routes in at runtime, but I need to think a bit about how to make
|
||||||
// that work with wildcards.
|
// that work with wildcards.
|
||||||
for (let key in router) {
|
for (let i = 10; i >= 0; i--) {
|
||||||
let path = key;
|
for (let path of Object.keys(router).filter(key => key.split("/").length === i)) {
|
||||||
while (path !== "/") { // walk upward through the path
|
|
||||||
path = path.substr(0, path.lastIndexOf("/"));
|
path = path.substr(0, path.lastIndexOf("/"));
|
||||||
if (path == '') path = '/';
|
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');
|
const assert = require('assert');
|
||||||
(async () => {
|
(async () => {
|
||||||
assert.deepEqual(await router['/tabs/by-id/*'].readdir(), { entries: ['.', '..', 'url', 'title', 'text', 'screenshot.png', 'resources', 'scripts', 'control'] });
|
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(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']);
|
assert.deepEqual(findRoute('/tabs/by-id/TABID/url'), router['/tabs/by-id/*/url']);
|
||||||
|
|
Loading…
Reference in a new issue