-
Notifications
You must be signed in to change notification settings - Fork 190
Add Progressive Web App (PWA) support #90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
rohanod
wants to merge
3
commits into
CNCKitchen:main
Choose a base branch
from
rohanod:feat/pwa
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| # PWA updates | ||
|
|
||
| When you change files that the service worker caches (`index.html`, `style.css`, `js/*`, icons, manifest, etc.): | ||
|
|
||
| 1. Open `sw.js` | ||
| 2. Bump `CACHE_VERSION` (e.g. `bumpmesh-v1` → `bumpmesh-v2`) | ||
| 3. If you added or renamed cached files, update the `PRECACHE` list in `sw.js` | ||
| 4. Commit, push, and deploy | ||
|
|
||
| Users pick up the update on their next visit. The new service worker installs, replaces the old cache, and serves fresh files. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| { | ||
| "name": "BumpMesh by CNC Kitchen", | ||
| "short_name": "BumpMesh", | ||
| "description": "Add displacement textures to STL, OBJ, and 3MF models directly in your browser.", | ||
| "start_url": "./", | ||
| "scope": "./", | ||
| "display": "standalone", | ||
| "orientation": "any", | ||
| "background_color": "#111114", | ||
| "theme_color": "#111114", | ||
| "categories": ["utilities", "productivity"], | ||
| "icons": [ | ||
| { | ||
| "src": "icons/icon-192.png", | ||
| "sizes": "192x192", | ||
| "type": "image/png", | ||
| "purpose": "any" | ||
| }, | ||
| { | ||
| "src": "icons/icon-512.png", | ||
| "sizes": "512x512", | ||
| "type": "image/png", | ||
| "purpose": "any" | ||
| }, | ||
| { | ||
| "src": "icons/icon-512.png", | ||
| "sizes": "512x512", | ||
| "type": "image/png", | ||
| "purpose": "maskable" | ||
| } | ||
| ] | ||
| } | ||
|
rohanod marked this conversation as resolved.
Outdated
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| const CACHE_VERSION = 'bumpmesh-v2'; | ||
|
|
||
| const PRECACHE = [ | ||
| './', | ||
| './index.html', | ||
| './style.css', | ||
| './logo.png', | ||
| './manifest.webmanifest', | ||
| './icons/icon-192.png', | ||
| './icons/icon-512.png', | ||
| './js/main.js', | ||
| './js/viewer.js', | ||
| './js/stlLoader.js', | ||
| './js/smartResolution.js', | ||
| './js/presetTextures.js', | ||
| './js/previewMaterial.js', | ||
| './js/subdivision.js', | ||
| './js/regularize.js', | ||
| './js/exportPipeline.js', | ||
| './js/exporter.js', | ||
| './js/exclusion.js', | ||
| './js/meshValidation.js', | ||
| './js/i18n.js', | ||
| './js/meshIndex.js', | ||
| './js/mapping.js', | ||
| './js/displacement.js', | ||
| './js/decimation.js', | ||
| './js/meshRepair.js', | ||
| './js/textureAnalysis.js', | ||
| './js/threeCompat.js', | ||
| './js/exportWorker.js', | ||
| './js/i18n/en.js', | ||
| './js/i18n/de.js', | ||
| './js/i18n/es.js', | ||
| './js/i18n/fr.js', | ||
| './js/i18n/it.js', | ||
| './js/i18n/ja.js', | ||
| './js/i18n/ko.js', | ||
| './js/i18n/pt.js', | ||
| './js/i18n/tr.js', | ||
| './js/i18n/uk.js', | ||
| ]; | ||
|
|
||
| self.addEventListener('install', (event) => { | ||
| event.waitUntil( | ||
| caches.open(CACHE_VERSION) | ||
| .then((cache) => cache.addAll(PRECACHE)) | ||
| .then(() => self.skipWaiting()), | ||
| ); | ||
| }); | ||
|
|
||
| self.addEventListener('activate', (event) => { | ||
| event.waitUntil( | ||
| caches.keys() | ||
| .then((keys) => Promise.all( | ||
| keys.filter((key) => key !== CACHE_VERSION).map((key) => caches.delete(key)), | ||
| )) | ||
| .then(() => self.clients.claim()), | ||
| ); | ||
| }); | ||
|
|
||
| self.addEventListener('fetch', (event) => { | ||
| const { request } = event; | ||
| if (request.method !== 'GET') return; | ||
|
|
||
| const url = new URL(request.url); | ||
|
|
||
| if (url.origin !== self.location.origin) { | ||
| if (url.hostname === 'cdn.jsdelivr.net') { | ||
| event.respondWith(networkFirst(request)); | ||
| } | ||
| return; | ||
| } | ||
|
|
||
| if (request.mode === 'navigate') { | ||
| event.respondWith(networkFirst(request, './index.html')); | ||
| return; | ||
| } | ||
|
|
||
| event.respondWith(staleWhileRevalidate(request)); | ||
| }); | ||
|
|
||
| async function networkFirst(request, fallbackUrl) { | ||
| try { | ||
| const response = await fetch(request); | ||
| if (response.ok) { | ||
| const cache = await caches.open(CACHE_VERSION); | ||
| cache.put(request, response.clone()); | ||
| } | ||
| return response; | ||
| } catch { | ||
| const cached = await caches.match(request); | ||
| if (cached) return cached; | ||
| if (fallbackUrl) { | ||
| const fallback = await caches.match(fallbackUrl); | ||
| if (fallback) return fallback; | ||
| } | ||
| throw new Error('Network unavailable'); | ||
| } | ||
| } | ||
|
|
||
| async function staleWhileRevalidate(request) { | ||
| const cache = await caches.open(CACHE_VERSION); | ||
| const cached = await cache.match(request); | ||
|
|
||
| const networkPromise = fetch(request) | ||
| .then((response) => { | ||
| if (response.ok) cache.put(request, response.clone()); | ||
| return response; | ||
| }) | ||
| .catch(() => null); | ||
|
|
||
| return cached || networkPromise || fetch(request); | ||
| } | ||
|
rohanod marked this conversation as resolved.
Outdated
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.