diff options
author | EuAndreh <eu@euandre.org> | 2024-11-01 07:06:35 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2024-11-01 07:06:35 -0300 |
commit | 6aab6760eec06bd789adf3cecc8678f28311c6a9 (patch) | |
tree | e560b09b0a491f6f0a2d68bc52e53f2bc5c52bb2 | |
parent | WIP: Init work on HTML (diff) | |
download | chat.papo.im-6aab6760eec06bd789adf3cecc8678f28311c6a9.tar.gz chat.papo.im-6aab6760eec06bd789adf3cecc8678f28311c6a9.tar.xz |
Use importScripts() instead of generating the service-worker.js file
-rw-r--r-- | .gitignore | 3 | ||||
-rw-r--r-- | Makefile | 20 | ||||
-rw-r--r-- | src/content/service-worker.js | 8 | ||||
-rw-r--r-- | src/content/sw.js | 8 | ||||
-rw-r--r-- | src/sw-main.js | 5 |
5 files changed, 18 insertions, 26 deletions
@@ -1,4 +1,3 @@ -/src/sw-pre.js +/src/content/images.js /src/content/papo.exported.js /src/content/sw.exported.js -/src/content/service-worker.js @@ -42,15 +42,16 @@ contents = \ src/content/papo.js \ src/content/style.css \ src/content/index.html \ + src/content/sw.js \ + src/content/images.js \ src/content/service-worker.js \ $(img.svg) \ derived-assets = \ - src/sw-pre.js \ + src/content/images.js \ src/content/papo.exported.js \ src/content/sw.exported.js \ - src/content/service-worker.js \ side-assets = \ @@ -60,17 +61,10 @@ side-assets = \ ## and installation. all: $(derived-assets) -src/sw-pre.js: Makefile deps.mk +src/content/images.js: Makefile deps.mk printf 'const IMG_PATHS = [\n' > $@ printf '\t"%s",\n' $(img.svg) >> $@ - printf '];\n\n' >> $@ - -## The use of static `import` statements inside service workers -## isn't supported. So in order to have tests for the code in -## it, a "main()" function is included in the generated file -## so that is can be ran as a standalone file. -src/content/service-worker.js: src/sw-pre.js src/content/sw.js src/sw-main.js - tail -n+2 src/content/sw.js | cat src/sw-pre.js - src/sw-main.js > $@ + printf '];\n' >> $@ src/content/papo.exported.js src/content/sw.exported.js: \ Makefile src/exported.sh @@ -88,11 +82,7 @@ tests/sw.js-check: src/content/sw.exported.js tests/papo.js-check tests/sw.js-check: node tests/node-driver.js $*.js -src/content/service-worker.js-check: src/content/service-worker.js - test "`grep -c '^const IMG_PATHS ' $*.js`" = 1 - check-unit: tests/papo.js-check tests/sw.js-check -check-unit: src/content/service-worker.js-check integration-tests = \ diff --git a/src/content/service-worker.js b/src/content/service-worker.js new file mode 100644 index 0000000..1afe76c --- /dev/null +++ b/src/content/service-worker.js @@ -0,0 +1,8 @@ +importScripts("sw.js", "images.js"); + +main({ + self, + caches, + clients, + IMG_PATHS, +}); diff --git a/src/content/sw.js b/src/content/sw.js index 51089f2..c86cb43 100644 --- a/src/content/sw.js +++ b/src/content/sw.js @@ -1,5 +1,3 @@ -const IMG_PATHS = []; - const CACHE_NAME = "static-shared-assets"; const leafValues = tree => @@ -114,7 +112,7 @@ const STRATEGIES = [ "index.html", "style.css", "papo.js", - ...IMG_PATHS, + // ...IMG_PATHS, ]), }, { @@ -211,7 +209,8 @@ const main = ({ clients, out = console.log, err = console.warn, -} = {}) => +} = {}) => { + return; // FIXME registerListeners({ self, caches, @@ -220,6 +219,7 @@ const main = ({ out, err, }); +}; // handy resources for pushes: // https://web.dev/articles/offline-cookbook diff --git a/src/sw-main.js b/src/sw-main.js deleted file mode 100644 index be45ba4..0000000 --- a/src/sw-main.js +++ /dev/null @@ -1,5 +0,0 @@ -main({ - self, - caches, - clients, -}); |