made a PWA
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Mon, 18 Apr 2022 18:44:28 +0000 (18:44 +0000)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Mon, 18 Apr 2022 18:44:28 +0000 (18:44 +0000)
serve.py
static/favicon.ico [new file with mode: 0644]
static/logo_256.png [new file with mode: 0644]
static/manifest.json [new file with mode: 0644]
static/src/index.js
static/src/service-worker.js [new file with mode: 0644]
templates/index.html

index d62a27bc8f53e9b305e934b9586a08f6a54633b1..7edf313986d8a0d5ff0a1c10150ba332e58c8fef 100644 (file)
--- 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 (file)
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 (file)
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 (file)
index 0000000..6efeb05
--- /dev/null
@@ -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
index a02789dbaafe851e498bdc89df3b21a17f4b2fa0..775b516886153a7469b2825de74a8444850c53f2 100644 (file)
@@ -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 (file)
index 0000000..56bbb8a
--- /dev/null
@@ -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
index e90fc57bf29e51576cebea4372025d3077be098a..fd5586048e44a80cebe2090a139870ae7142bb1e 100644 (file)
@@ -2,6 +2,9 @@
 <html lang="en">
     <head>
         <title>Onyx compiler</title> 
+        <meta name="viewport" content="width=device-width, initial-scale=1.0">
+
+        <link rel="manifest" href="/playground/manifest.json">
 
         <link rel="stylesheet" href="{{ config['ENDPOINT'] + url_for('static', filename='css/index.css') }}" />
         <link rel="stylesheet" href="{{ config['ENDPOINT'] + url_for('static', filename='vendor/fontawesome/css/all.min.css') }}" />