Browse Source

Merge pull request #1 from technocapeman/main

Added PWA Functionality, Improved Service Worker, Improved Documentation
main
Ravi Shah 5 years ago
committed by GitHub
parent
commit
6bac12dd18
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      garage_door_script.py
  2. 14
      static/app.js
  3. 0
      static/css/bootstrap.min.css
  4. 0
      static/css/bootstrap.min.css.map
  5. 0
      static/css/styles.css
  6. 0
      static/images/android-chrome-192x192.png
  7. 0
      static/images/android-chrome-512x512.png
  8. 0
      static/images/apple-touch-icon.png
  9. 0
      static/images/favicon-16x16.png
  10. 0
      static/images/favicon-32x32.png
  11. 0
      static/manifest.json
  12. 21
      static/service-worker.js
  13. 13
      templates/index.html
  14. 11
      templates/login.html

6
garage_door_script.py

@ -97,5 +97,11 @@ def favicon():
return send_from_directory(os.path.join(app.root_path, 'static'), return send_from_directory(os.path.join(app.root_path, 'static'),
'favicon.ico',mimetype='image/vnd.microsoft.icon') '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__': if __name__ == '__main__':
app.run(host='0.0.0.0', port=1235) #Run the webserver app.run(host='0.0.0.0', port=1235) #Run the webserver

14
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);
});
}

0
static/bootstrap.min.css → static/css/bootstrap.min.css

0
static/bootstrap.min.css.map → static/css/bootstrap.min.css.map

0
static/styles.css → static/css/styles.css

0
static/android-chrome-192x192.png → static/images/android-chrome-192x192.png

Before

Width: 192  |  Height: 192  |  Size: 19 KiB

After

Width: 192  |  Height: 192  |  Size: 19 KiB

0
static/android-chrome-512x512.png → static/images/android-chrome-512x512.png

Before

Width: 512  |  Height: 512  |  Size: 79 KiB

After

Width: 512  |  Height: 512  |  Size: 79 KiB

0
static/apple-touch-icon.png → static/images/apple-touch-icon.png

Before

Width: 180  |  Height: 180  |  Size: 17 KiB

After

Width: 180  |  Height: 180  |  Size: 17 KiB

0
static/favicon-16x16.png → static/images/favicon-16x16.png

Before

Width: 16  |  Height: 16  |  Size: 612 B

After

Width: 16  |  Height: 16  |  Size: 612 B

0
static/favicon-32x32.png → static/images/favicon-32x32.png

Before

Width: 32  |  Height: 32  |  Size: 1.5 KiB

After

Width: 32  |  Height: 32  |  Size: 1.5 KiB

0
static/site.webmanifest → static/manifest.json

21
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
})
);

13
templates/index.html

@ -2,12 +2,13 @@
<head> <head>
<title>Pi Garage Door Opener</title> <title>Pi Garage Door Opener</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="static/bootstrap.min.css" rel="stylesheet" media="screen">
<link href="static/styles.css" rel="stylesheet" media="screen">
<link rel="manifest" href="static/site.webmanifest">
<link rel="apple-touch-icon" sizes="180x180" href="static/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="static/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="static/favicon-16x16.png">
<link href="{{ url_for('static', filename='css/bootstrap.min.css') }}" rel="stylesheet" media="screen">
<link href="{{ url_for('static', filename='css/styles.css') }}" rel="stylesheet" media="screen">
<link rel="manifest" href="{{ url_for('static', filename='manifest.json') }}">
<link rel="apple-touch-icon" sizes="180x180" href="{{ url_for('static', filename='images/apple-touch-icon.png') }}">
<link rel="icon" type="image/png" sizes="32x32" href="{{ url_for('static', filename='images/favicon-32x32.png') }}">
<link rel="icon" type="image/png" sizes="16x16" href="{{ url_for('static', filename='images/favicon-16x16.png') }}">
<script src="{{ url_for('static', filename='js/app.js') }}"></script>
</head> </head>
<body> <body>
<div class="header"> <div class="header">

11
templates/login.html

@ -2,11 +2,12 @@
<head> <head>
<title>Log in to continue</title> <title>Log in to continue</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="static/bootstrap.min.css" rel="stylesheet" media="screen">
<link rel="manifest" href="static/site.webmanifest">
<link rel="apple-touch-icon" sizes="180x180" href="static/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="static/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="static/favicon-16x16.png">
<link href="{{ url_for('static', filename='css/bootstrap.min.css') }}" rel="stylesheet" media="screen">
<link rel="manifest" href="{{ url_for('static', filename='manifest.json') }}">
<link rel="apple-touch-icon" sizes="180x180" href="{{ url_for('static', filename='images/apple-touch-icon.png') }}">
<link rel="icon" type="image/png" sizes="32x32" href="{{ url_for('static', filename='images/favicon-32x32.png') }}">
<link rel="icon" type="image/png" sizes="16x16" href="{{ url_for('static', filename='images/favicon-16x16.png') }}">
<script src="{{ url_for('static', filename='js/app.js') }}"></script>
</head> </head>
<body> <body>
<div class="container"> <div class="container">

Loading…
Cancel
Save