Make hk-planner installable as a PWA

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
jtricerolph 2026-07-11 11:27:00 +00:00
parent c0b1d2a62e
commit fbda399d21
7 changed files with 6325 additions and 2 deletions

View file

@ -1,4 +1,20 @@
server { server {
location = /hk-planner/manifest.webmanifest {
default_type application/manifest+json;
add_header Cache-Control "no-cache";
try_files $uri =404;
}
location = /hk-planner/sw.js {
add_header Cache-Control "no-cache";
try_files $uri =404;
}
location = /hk-planner/registerSW.js {
add_header Cache-Control "no-cache";
try_files $uri =404;
}
listen 80; listen 80;
server_name localhost; server_name localhost;
root /usr/share/nginx/html; root /usr/share/nginx/html;

6272
frontend/package-lock.json generated Normal file

File diff suppressed because it is too large Load diff

View file

@ -19,6 +19,7 @@
"@types/react-dom": "^18.3.1", "@types/react-dom": "^18.3.1",
"@vitejs/plugin-react": "^4.3.4", "@vitejs/plugin-react": "^4.3.4",
"typescript": "^5.7.2", "typescript": "^5.7.2",
"vite": "^6.0.5" "vite": "^6.0.5",
"vite-plugin-pwa": "^1.3.0"
} }
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

View file

@ -3,6 +3,16 @@ import { createRoot } from 'react-dom/client'
import './index.css' import './index.css'
import App from './App' import App from './App'
// When opened from the portal's install button (?install=1), trigger the
// PWA install prompt as soon as the browser offers it (Chrome/Edge only).
if (new URLSearchParams(window.location.search).has('install')) {
window.addEventListener('beforeinstallprompt', e => {
e.preventDefault()
;(e as Event & { prompt: () => Promise<void> }).prompt()
}, { once: true })
}
createRoot(document.getElementById('root')!).render( createRoot(document.getElementById('root')!).render(
<StrictMode> <StrictMode>
<App /> <App />

View file

@ -1,7 +1,31 @@
import { defineConfig } from 'vite' import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react' import react from '@vitejs/plugin-react'
import { VitePWA } from 'vite-plugin-pwa'
export default defineConfig({ export default defineConfig({
base: '/hk-planner/', base: '/hk-planner/',
plugins: [react()], plugins: [
react(),
VitePWA({
registerType: 'autoUpdate',
manifest: {
name: 'HK Planner',
short_name: 'HK Planner',
start_url: '/hk-planner/',
scope: '/hk-planner/',
display: 'standalone',
theme_color: '#2d6a4f',
background_color: '#2d6a4f',
icons: [
{ src: '/hk-planner/icons/icon-192.png', sizes: '192x192', type: 'image/png' },
{ src: '/hk-planner/icons/icon-512.png', sizes: '512x512', type: 'image/png' },
],
},
workbox: {
navigateFallback: '/hk-planner/index.html',
navigateFallbackDenylist: [/\/api\//],
globPatterns: ['**/*.{js,css,html,ico,png,svg}'],
},
}),
],
}) })