diff --git a/garage_door_script.py b/garage_door_script.py index cd59fa0..eff0357 100644 --- a/garage_door_script.py +++ b/garage_door_script.py @@ -97,5 +97,11 @@ def favicon(): return send_from_directory(os.path.join(app.root_path, 'static'), 'favicon.ico',mimetype='image/vnd.microsoft.icon') + +# Route for the Service Worker +@app.route('/service-worker.js', methods=['GET']) +def sw(): + return app.send_static_file('service-worker.js'), 200, {'Content-Type': 'text/javascript'} + if __name__ == '__main__': app.run(host='0.0.0.0', port=1235) #Run the webserver diff --git a/static/app.js b/static/app.js new file mode 100644 index 0000000..3e63af1 --- /dev/null +++ b/static/app.js @@ -0,0 +1,14 @@ +// Credits: https://flaskpwa.com/#_serviceWorkersRegistration +// File Created by [Check Commits for Name] + +if ('serviceWorker' in navigator) { + navigator.serviceWorker + .register('./service-worker.js') + .then(function(registration) { + console.log('Service Worker Registered!'); + return registration; + }) + .catch(function(err) { + console.error('Unable to register service worker.', err); + }); +} \ No newline at end of file diff --git a/static/bootstrap.min.css b/static/css/bootstrap.min.css similarity index 100% rename from static/bootstrap.min.css rename to static/css/bootstrap.min.css diff --git a/static/bootstrap.min.css.map b/static/css/bootstrap.min.css.map similarity index 100% rename from static/bootstrap.min.css.map rename to static/css/bootstrap.min.css.map diff --git a/static/styles.css b/static/css/styles.css similarity index 100% rename from static/styles.css rename to static/css/styles.css diff --git a/static/android-chrome-192x192.png b/static/images/android-chrome-192x192.png similarity index 100% rename from static/android-chrome-192x192.png rename to static/images/android-chrome-192x192.png diff --git a/static/android-chrome-512x512.png b/static/images/android-chrome-512x512.png similarity index 100% rename from static/android-chrome-512x512.png rename to static/images/android-chrome-512x512.png diff --git a/static/apple-touch-icon.png b/static/images/apple-touch-icon.png similarity index 100% rename from static/apple-touch-icon.png rename to static/images/apple-touch-icon.png diff --git a/static/favicon-16x16.png b/static/images/favicon-16x16.png similarity index 100% rename from static/favicon-16x16.png rename to static/images/favicon-16x16.png diff --git a/static/favicon-32x32.png b/static/images/favicon-32x32.png similarity index 100% rename from static/favicon-32x32.png rename to static/images/favicon-32x32.png diff --git a/static/site.webmanifest b/static/manifest.json similarity index 100% rename from static/site.webmanifest rename to static/manifest.json diff --git a/static/service-worker.js b/static/service-worker.js new file mode 100644 index 0000000..e22c1e7 --- /dev/null +++ b/static/service-worker.js @@ -0,0 +1,21 @@ +// CREDITS: https://www.pwabuilder.com/serviceworker +// File Created by [Check Commits for Name] + +// This is the service worker with the Cache-first network + +const CACHE = "pwabuilder-precache"; + +importScripts('https://storage.googleapis.com/workbox-cdn/releases/5.1.2/workbox-sw.js'); + +self.addEventListener("message", (event) => { + if (event.data && event.data.type === "SKIP_WAITING") { + self.skipWaiting(); + } +}); + +workbox.routing.registerRoute( + new RegExp('/'), + new workbox.strategies.CacheFirst({ + cacheName: CACHE + }) +); \ No newline at end of file diff --git a/templates/index.html b/templates/index.html index 7e73624..94154aa 100644 --- a/templates/index.html +++ b/templates/index.html @@ -2,12 +2,13 @@ Pi Garage Door Opener - - - - - - + + + + + + +
diff --git a/templates/login.html b/templates/login.html index b3214ad..7a7411d 100644 --- a/templates/login.html +++ b/templates/login.html @@ -2,11 +2,12 @@ Log in to continue - - - - - + + + + + +