initial pwa support
This commit is contained in:
		| @ -8,5 +8,7 @@ | ||||
|     "pyscript_py_url": "https://pyscript.net/alpha/pyscript.py", | ||||
|     "bootstrap_css_url": "https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css", | ||||
|     "bootstrap_js_url": "https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js", | ||||
|     "pyscript_bootstrap_templates_wheel_url": "../dist/pyscript_bootstrap_templates-0.1.0-py3-none-any.whl" | ||||
|     "pyscript_bootstrap_templates_wheel_url": "../dist/pyscript_bootstrap_templates-0.1.0-py3-none-any.whl", | ||||
|     "pwa_bg_color": "#000000", | ||||
|     "pwa_theme_color": "#ffffff" | ||||
| } | ||||
| @ -5,6 +5,8 @@ | ||||
|         <meta charset="UTF-8"> | ||||
|         <meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||||
|  | ||||
|         <link rel="manifest" href="manifest.json" /> | ||||
|  | ||||
|         <link rel="stylesheet" href="./resources/pyscript.css" /> | ||||
|         <script defer src="./resources/pyscript.js"></script> | ||||
|  | ||||
| @ -24,6 +26,7 @@ | ||||
|         <py-script src="./main.py"></py-script> | ||||
|  | ||||
|         <script src="./resources/bootstrap.js"></script> | ||||
|         <script src="./resources/pwa.js"></script> | ||||
|     </body> | ||||
| </html> | ||||
|      | ||||
							
								
								
									
										1
									
								
								examples/01_hello_world/manifest.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								examples/01_hello_world/manifest.json
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1 @@ | ||||
| {"name": "01_hello_world", "short_name": "01_hello_world", "start_url": "./index.html", "scope": ".", "display": "standalone", "background_color": "#000000", "theme_color": "#ffffff", "icons": [{"src": "resources/icon-512x512.png", "type": "image/png", "sizes": "512x512"}]} | ||||
							
								
								
									
										
											BIN
										
									
								
								examples/01_hello_world/resources/icon-256x256.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								examples/01_hello_world/resources/icon-256x256.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 18 KiB | 
							
								
								
									
										
											BIN
										
									
								
								examples/01_hello_world/resources/icon-512x512.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								examples/01_hello_world/resources/icon-512x512.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 18 KiB | 
							
								
								
									
										10
									
								
								examples/01_hello_world/resources/pwa.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								examples/01_hello_world/resources/pwa.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,10 @@ | ||||
|  | ||||
| if ("serviceWorker" in navigator) { | ||||
|     window.addEventListener("load", function () { | ||||
|         navigator.serviceWorker | ||||
|             .register("./serviceWorker.js") | ||||
|             .then(res => console.log("service worker registered", res)) | ||||
|             .catch(err => console.log("service worker not registered", err)) | ||||
|     }) | ||||
| } | ||||
|      | ||||
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										32
									
								
								examples/01_hello_world/resources/serviceWorker.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								examples/01_hello_world/resources/serviceWorker.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,32 @@ | ||||
|  | ||||
| const pwa_version = "202210160801" | ||||
| const assets = ["/index.html", | ||||
|     "/main.py", | ||||
|     "/resources/bootstrap.css", | ||||
|     "/resources/bootstrap.js", | ||||
|     "/resources/pyscript.css", | ||||
|     "/resources/pyscript.js", | ||||
|     "/resources/pyscript.py", | ||||
|     "/resources/pyscript_bootstrap_templates-0.1.0-py3-none-any.whl", | ||||
|     "/resources/pwa.js", | ||||
|     "/resourced/site.js", | ||||
| ] | ||||
| self.addEventListener("install", installEvent => { | ||||
|     installEvent.waitUntil( | ||||
|         caches.open(pwa_version).then(cache => { | ||||
|             cache.addAll(assets).then(r => { | ||||
|                 console.log("Cache assets downloaded"); | ||||
|             }).catch(err => console.log("Error caching item", err)) | ||||
|             console.log(`Cache ${pwa_version} opened.`); | ||||
|         }).catch(err => console.log("Error opening cache", err)) | ||||
|     ) | ||||
| }) | ||||
|  | ||||
| self.addEventListener("fetch", fetchEvent => { | ||||
|     fetchEvent.respondWith( | ||||
|         caches.match(fetchEvent.request).then(res => { | ||||
|             return res || fetch(fetchEvent.request) | ||||
|         }).catch(err => console.log("Cache fetch error: ", err)) | ||||
|     ) | ||||
| }) | ||||
|      | ||||
							
								
								
									
										2
									
								
								examples/01_hello_world/resources/site.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								examples/01_hello_world/resources/site.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,2 @@ | ||||
|  | ||||
|      | ||||
							
								
								
									
										32
									
								
								examples/01_hello_world/serviceWorker.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								examples/01_hello_world/serviceWorker.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,32 @@ | ||||
|  | ||||
| const pwa_version = "202210160804" | ||||
| const assets = ["./index.html", | ||||
|     "./main.py", | ||||
|     "./resources/bootstrap.css", | ||||
|     "./resources/bootstrap.js", | ||||
|     "./resources/pyscript.css", | ||||
|     "./resources/pyscript.js", | ||||
|     "./resources/pyscript.py", | ||||
|     "./resources/pyscript_bootstrap_templates-0.1.0-py3-none-any.whl", | ||||
|     "./resources/pwa.js", | ||||
|     "./site.js", | ||||
| ] | ||||
| self.addEventListener("install", installEvent => { | ||||
|     installEvent.waitUntil( | ||||
|         caches.open(pwa_version).then(cache => { | ||||
|             cache.addAll(assets).then(r => { | ||||
|                 console.log("Cache assets downloaded"); | ||||
|             }).catch(err => console.log("Error caching item", err)) | ||||
|             console.log(`Cache ${pwa_version} opened.`); | ||||
|         }).catch(err => console.log("Error opening cache", err)) | ||||
|     ) | ||||
| }) | ||||
|  | ||||
| self.addEventListener("fetch", fetchEvent => { | ||||
|     fetchEvent.respondWith( | ||||
|         caches.match(fetchEvent.request).then(res => { | ||||
|             return res || fetch(fetchEvent.request) | ||||
|         }).catch(err => console.log("Cache fetch error: ", err)) | ||||
|     ) | ||||
| }) | ||||
|      | ||||
							
								
								
									
										2
									
								
								examples/01_hello_world/site.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								examples/01_hello_world/site.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,2 @@ | ||||
|  | ||||
|      | ||||
		Reference in New Issue
	
	Block a user