Browse Source

working pwa?

Karl Hudgell 3 tuần trước cách đây
mục cha
commit
0270f3862a

BIN
static/apple-touch-icon.png


BIN
static/favicon-96x96.png


BIN
static/favicon.ico


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 0 - 0
static/favicon.svg


BIN
static/icons/android-launchericon-144-144.png


BIN
static/icons/android-launchericon-192-192.png


BIN
static/icons/android-launchericon-512-512.png


+ 12 - 19
static/service-worker.js

@@ -1,22 +1,15 @@
-self.addEventListener('install', function (event) {
-    event.waitUntil(
-        caches.open('my-cache').then(function (cache) {
-            return cache.addAll([
-                '/',
-                '/index.html',
-                '/static/styles.css',
-                '/static/script.js',
-                '/static/icons/icon-192x192.png',
-                '/static/icons/icon-512x512.png'
-            ]);
-        })
-    );
+self.addEventListener('install', e => {
+	// console.log('[Service Worker] Installed');
 });
 
-self.addEventListener('fetch', function (event) {
-    event.respondWith(
-        caches.match(event.request).then(function (response) {
-            return response || fetch(event.request);
-        })
-    );
+self.addEventListener('activate', e => {
+	// console.log('[Service Worker] Activated');
 });
+
+self.addEventListener('fetch', e => {
+	// e.respondWith(
+	// 	caches.match(e.request).then(res => {
+	// 		return res || fetch(e.request);
+	// 	})
+	// );
+});

+ 21 - 0
static/site.webmanifest

@@ -0,0 +1,21 @@
+{
+  "name": "kTvManager",
+  "short_name": "kTv",
+  "icons": [
+    {
+      "src": "/web-app-manifest-192x192.png",
+      "sizes": "192x192",
+      "type": "image/png",
+      "purpose": "maskable"
+    },
+    {
+      "src": "/web-app-manifest-512x512.png",
+      "sizes": "512x512",
+      "type": "image/png",
+      "purpose": "maskable"
+    }
+  ],
+  "theme_color": "#ffffff",
+  "background_color": "#ffffff",
+  "display": "standalone"
+}

BIN
static/web-app-manifest-192x192.png


BIN
static/web-app-manifest-512x512.png


+ 13 - 12
templates/index.html

@@ -6,7 +6,12 @@
     <meta name="viewport" content="width=device-width, initial-scale=1.0">
     <title>KTV Manager</title>
     <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
-    <link rel="manifest" href="{{ url_for('static', filename='manifest.json') }}">
+    <link rel="icon" type="image/png" href="{{ url_for('static', filename='favicon-96x96.png') }}" sizes="96x96" />
+    <link rel="icon" type="image/svg+xml" href="{{ url_for('static', filename='favicon.svg') }}" />
+    <link rel="shortcut icon" href="{{ url_for('static', filename='favicon.ico') }}" />
+    <link rel="apple-touch-icon" sizes="180x180" href="{{ url_for('static', filename='apple-touch-icon.png') }}" />
+    <meta name="apple-mobile-web-app-title" content="kTvManager" />
+    <link rel="manifest" href="{{ url_for('static', filename='site.webmanifest') }}" />    
 </head>
 <body>
 
@@ -61,17 +66,13 @@
     <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
     <script>
         if ('serviceWorker' in navigator) {
-          window.addEventListener('load', function() {
-            navigator.serviceWorker.register("{{ url_for('static', filename='service-worker.js') }}")
-              .then(function(registration) {
-                console.log('Service Worker registered with scope: ', registration.scope);
-              })
-              .catch(function(error) {
-                console.log('Service Worker registration failed: ', error);
-              });
-          });
+            navigator.serviceWorker.register('{{ url_for("static", filename="service-worker.js") }}')
+            // .then(reg => {
+            // 		console.log('Service worker:', reg);
+            // .catch(err => {
+            // 	console.log('Service worker:', err);
+            // });
         }
-      </script>
-      
+    </script>
 </body>
 </html>

Một số tệp đã không được hiển thị bởi vì quá nhiều tập tin thay đổi trong này khác