From: Elijah Cohen Date: Fri, 20 Dec 2024 19:34:09 +0000 (-0600) Subject: added proper offline pwa support to web repl X-Git-Tag: v-12.13.13~7 X-Git-Url: https://git.eli173.com/?a=commitdiff_plain;h=35bdde0c192dfdc396d0da12bdf4642e9a96efee;p=klapaucius added proper offline pwa support to web repl --- diff --git a/demos.kl b/demos.kl index dfe9635..54535cb 100644 --- a/demos.kl +++ b/demos.kl @@ -59,4 +59,7 @@ (def tr-fac (B (S (Phi (eq 0) cdr car)) (C B (Phi cons (Phi * car cdr) (B (C - 1) cdr))))) -(def abstract-rec (B (B (B (C B cons))) (B (B (B B)) (B (B (B Z)) (C (B B (B B (B B (B S (C (C Phi cdr) car))))) (B (B (C B)) (B (C B (C B cdr)) (B (Phi cons) (C (C Phi car) cdr))))))))) \ No newline at end of file +(def abstract-rec (B (B (B (C B cons))) (B (B (B B)) (B (B (B Z)) (C (B B (B B (B B (B S (C (C Phi cdr) car))))) (B (B (C B)) (B (C B (C B cdr)) (B (Phi cons) (C (C Phi car) cdr))))))))) + +(def append (B (C (abstract-rec not (B (C B car) (C cons)) cdr)) reverse)) + diff --git a/src/Makefile b/src/Makefile index 9a798ce..8042cca 100644 --- a/src/Makefile +++ b/src/Makefile @@ -48,6 +48,7 @@ web: $(WEB_OBJS) mkdir -p $(WEB_BUILD)/../static/repl cp $(WEB_BUILD)/../kl.png $(WEB_BUILD)/../static/repl cp $(WEB_BUILD)/../manifest.json $(WEB_BUILD)/../static/repl + cp $(WEB_BUILD)/../sw.js $(WEB_BUILD)/../static/repl cp $(WEB_BUILD)/klrepl.data $(WEB_BUILD)/../static/repl cp $(WEB_BUILD)/klrepl.js $(WEB_BUILD)/../static/repl cp $(WEB_BUILD)/klrepl.wasm $(WEB_BUILD)/../static/repl diff --git a/web/shell.html b/web/shell.html index c2d5282..4511079 100644 --- a/web/shell.html +++ b/web/shell.html @@ -50,6 +50,15 @@ outzone.appendChild(outelt); document.getElementById('replin').value = "" }); + + if('serviceWorker' in navigator) { + console.log('registering'); + navigator.serviceWorker.register('./sw.js') + .then(() => { console.log('sw reg'); }); + } + else { + console.log('no sw in nav'); + } {{{ SCRIPT }}} diff --git a/web/sw.js b/web/sw.js new file mode 100644 index 0000000..932b15c --- /dev/null +++ b/web/sw.js @@ -0,0 +1,18 @@ + +self.addEventListener('install', (event) => { + event.waitUntil( + caches.open('klrepl').then((cache) => cache.addAll([ + './', + './index.html', + './kl.png', + './klrepl.js', + './klrepl.wasm', + './klrepl.data', + ])) + )}); + +self.addEventListener('fetch', (event) => { + event.respondWith( + caches.match(event.request).then((response) => response || fetch(event.request)) + ); +});