aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOmar Rizwan <omar@omar.website>2020-12-22 20:34:01 -0800
committerOmar Rizwan <omar@omar.website>2020-12-22 20:34:01 -0800
commit35214c9698e54e107ad1f28f9fce6da6b00ed39a (patch)
treefafd4bd7ef06be352448fe49a6380256b5ee8550
parente6f9ce7437d8f83076680391be0d260f80a018c3 (diff)
extensions/*/enabled is readable (+ test that works)
-rw-r--r--README.md8
-rw-r--r--extension/background.js8
-rwxr-xr-xtest.c10
3 files changed, 25 insertions, 1 deletions
diff --git a/README.md b/README.md
index 25d3a1f..b35404d 100644
--- a/README.md
+++ b/README.md
@@ -60,6 +60,14 @@ $ echo remove | tee -a mnt/tabs/by-title/*Stack_Overflow*/control
$ cat mnt/tabs/by-id/*/text > text.txt
```
+### TODO: Reload an extension when you edit its source code
+
+Making anohter extension?
+
+SO post.
+
+We can subsume that.
+
### TODO: Manage tabs in Emacs dired
I do this
diff --git a/extension/background.js b/extension/background.js
index 4fb5923..af8fb10 100644
--- a/extension/background.js
+++ b/extension/background.js
@@ -326,6 +326,14 @@ router["/extensions"] = {
return { entries: [".", "..", ...infos.map(info => `${sanitize(info.name)}_${info.id}`)] };
}
};
+router["/extensions/*/enabled"] = defineFile(async path => {
+ const parts = pathComponent(path, -2).split('_'); const extensionId = parts[parts.length - 1];
+ const info = await browser.management.get(extensionId);
+ return String(info.enabled);
+
+}, async (path, buf) => {
+ await browser.management.setEnabled();
+});
// Ensure that there are routes for all ancestors. This algorithm is
// probably not correct, but whatever. I also think it would be
diff --git a/test.c b/test.c
index 38644c1..c57f0b6 100755
--- a/test.c
+++ b/test.c
@@ -6,6 +6,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
+#include <wordexp.h>
int file_contents_equal(char* path, char* contents) {
// hehe: https://twitter.com/ianh_/status/1340450349065244675
@@ -14,12 +15,19 @@ int file_contents_equal(char* path, char* contents) {
return system("[ \"$contents\" == \"$(cat \"$path\")\" ]") == 0;
}
+char* expand(char* phrase) {
+ wordexp_t result; assert(wordexp(phrase, &result, 0) == 0);
+ return result.we_wordv[0];
+}
+
// integration tests
int main() {
assert(system("echo about:blank > fs/mnt/tabs/create") == 0);
assert(file_contents_equal("fs/mnt/tabs/last-focused/url", "about:blank"));
- assert(system("file fs/mnt/tabs/last-focused/screenshot.png") == 0);
+ /* assert(system("file fs/mnt/tabs/last-focused/screenshot.png") == 0); */
assert(system("echo remove > fs/mnt/tabs/last-focused/control") == 0);
+ assert(file_contents_equal(expand("fs/mnt/extensions/TabFS*/enabled"), "true"));
+
assert(1); printf("Done!\n");
}