]> git.eli173.com Git - klapaucius/commitdiff
added proper offline pwa support to web repl
authorElijah Cohen <eli@eli173.com>
Fri, 20 Dec 2024 19:34:09 +0000 (13:34 -0600)
committerElijah Cohen <eli@eli173.com>
Fri, 20 Dec 2024 19:34:09 +0000 (13:34 -0600)
demos.kl
src/Makefile
web/shell.html
web/sw.js [new file with mode: 0644]

index dfe963519da2f10882cc1a606d9b66b2beac6401..54535cbb2ac8e12ea0f09b152b67a5d99bd81033 100644 (file)
--- 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))
+
index 9a798ce5633af14fe0ff6353734583773f116746..8042cca21c5bef28fd63ebc112b3d51ada9346be 100644 (file)
@@ -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
index c2d5282851d37d4440eb8ef97b8513bba403bd8d..45110793ad7d3d3dbbc6be22b6d7e66086afe2db 100644 (file)
                                        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>
                {{{ SCRIPT }}}
        </body>
diff --git a/web/sw.js b/web/sw.js
new file mode 100644 (file)
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))
+               );
+});