From: Elijah Cohen Date: Wed, 1 Jan 2025 18:39:02 +0000 (-0600) Subject: minimal functional example X-Git-Url: https://git.eli173.com/?a=commitdiff_plain;h=c6a1c8f07a0f48421b0af52cb2e4288fa1476fb0;p=pwa-c minimal functional example --- c6a1c8f07a0f48421b0af52cb2e4288fa1476fb0 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bdb90ee --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/outdir/ diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..1b460f3 --- /dev/null +++ b/Makefile @@ -0,0 +1,8 @@ + + +all: main.c shell.html + mkdir -p outdir + emcc main.c --shell-file shell.html -o outdir/index.html -s NO_EXIT_RUNTIME=1 -s "EXPORTED_RUNTIME_METHODS=['ccall']" + cp manifest.json outdir + cp sw.js outdir + cp icon.png outdir diff --git a/icon.png b/icon.png new file mode 100644 index 0000000..6dfd1bd Binary files /dev/null and b/icon.png differ diff --git a/main.c b/main.c new file mode 100644 index 0000000..f6a6a50 --- /dev/null +++ b/main.c @@ -0,0 +1,33 @@ +#ifdef __EMSCRIPTEN__ + +#include +#include +#include +#include + +int main() { + printf("hello, world!\ntell me something\n"); + return 0; +} + +void reverse(char* s) { + char* start = s; + char* end = s - 1+ strlen(s); + char tmp; + while(start < end) { + tmp = *start; + *start = *end; + *end = tmp; + start++; + end--; + } +} + +EMSCRIPTEN_KEEPALIVE char* do_this(char* in) { + char* out = strdup(in); + reverse(out); + return out; +} + + +#endif diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..f84a778 --- /dev/null +++ b/manifest.json @@ -0,0 +1,16 @@ +{ + "background_color": "#8E5DCE", + "description": "minimal example", + "display": "fullscreen", + "icons": [ + { + "src": "icon.png", + "sizes": "512x512", + "type": "image/png" + } + ], + "name": "min-ex", + "short_name": "min-ex", + "start_url": "." +} + diff --git a/shell.html b/shell.html new file mode 100644 index 0000000..39613a7 --- /dev/null +++ b/shell.html @@ -0,0 +1,59 @@ + + + + + + + + minmal example + + +
+
+ +
+ + {{{ SCRIPT }}} + + diff --git a/sw.js b/sw.js new file mode 100644 index 0000000..b00b84b --- /dev/null +++ b/sw.js @@ -0,0 +1,17 @@ +self.addEventListener('install', (event) => { + event.waitUntil( + caches.open('minex').then((cache) => cache.addAll([ + './', + './index.html', + './icon.png', + './index.js', + './index.wasm', + ])) + )}); + +self.addEventListener('fetch', (event) => { + event.respondWith( + caches.match(event.request).then((response) => response || fetch(event.request)) + ); +}); +