From: Brendan Hansen Date: Mon, 18 Apr 2022 18:44:28 +0000 (+0000) Subject: made a PWA X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=29a693152b5705f5f6b29437858ccfe69a3f3a39;p=onyx-live.git made a PWA --- diff --git a/serve.py b/serve.py index d62a27b..7edf313 100644 --- a/serve.py +++ b/serve.py @@ -107,3 +107,6 @@ def get_permalinked(link): response.headers['Cross-Origin-Opener-Policy'] = "same-origin" return response +@app.route("/manifest.json") +def get_manifest(): + return send_file("static/manifest.json", mimetype="application/json") \ No newline at end of file diff --git a/static/favicon.ico b/static/favicon.ico new file mode 100644 index 0000000..cd2b089 Binary files /dev/null and b/static/favicon.ico differ diff --git a/static/logo_256.png b/static/logo_256.png new file mode 100644 index 0000000..e0d94be Binary files /dev/null and b/static/logo_256.png differ diff --git a/static/manifest.json b/static/manifest.json new file mode 100644 index 0000000..6efeb05 --- /dev/null +++ b/static/manifest.json @@ -0,0 +1,19 @@ +{ + "short_name": "Onyx Playground", + "name": "Onyx Playground - Try Onyx without Installing", + "icons": [ + { + "src": "/playground/static/logo_256.png", + "type": "image/png", + "sizes": "256x256" + } + ], + "start_url": "/playground/?source=pwa", + "background_color": "#111", + "display": "standalone", + "scope": "/playground", + "theme_color": "#111", + "shortcuts": [], + "description": "Onyx Playground", + "screenshots": [] +} \ No newline at end of file diff --git a/static/src/index.js b/static/src/index.js index a02789d..775b516 100644 --- a/static/src/index.js +++ b/static/src/index.js @@ -282,6 +282,12 @@ async function request_permalink() { } window.onload = () => { + if ('serviceWorker' in navigator) { + navigator.serviceWorker.register("/playground/static/src/service-worker.js", { + scope: "/playground" + }); + } + let editor = ace.edit('code-editor'); editor.setTheme('ace/theme/chrome'); diff --git a/static/src/service-worker.js b/static/src/service-worker.js new file mode 100644 index 0000000..56bbb8a --- /dev/null +++ b/static/src/service-worker.js @@ -0,0 +1,38 @@ +const cacheName = 'cache-v1'; +const precacheResources = [ + '/playground', + '/playground/static/css/index.css', + '/playground/static/vendor/fontawesome/css/all.min.css', + '/playground/static/vendor/fontawesome/css/v4-shims.min.css', + '/playground/static/vendor/jquery/jquery.modal.min.css', + '/playground/static/src/resizer.js', + '/playground/static/src/storage.js', + '/playground/static/src/canvas.js', + '/playground/static/src/index.js', + '/playground/static/vendor/ace/ace.js', + '/playground/static/vendor/jquery/jquery.min.js', + '/playground/static/vendor/jquery/jquery.modal.min.js', +]; + + +self.addEventListener('install', event => { + console.log("Service worker installed."); + event.waitUntil( + caches.open(cacheName) + .then(cache => { + return cache.addAll(precacheResources); + }) + ); +}); + +self.addEventListener("fetch", event => { + console.log('Fetch intercepted for:', event.request.url); + event.respondWith(caches.match(event.request) + .then(cachedResponse => { + if (cachedResponse) { + return cachedResponse; + } + return fetch(event.request); + }) + ); +}); \ No newline at end of file diff --git a/templates/index.html b/templates/index.html index e90fc57..fd55860 100644 --- a/templates/index.html +++ b/templates/index.html @@ -2,6 +2,9 @@ Onyx compiler + + +