Add PWA support for install-to-home-screen
Adds manifest.json, service worker with static asset caching, resized cat icons, and meta tags for iOS/Android installability. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
BIN
raggr-frontend/public/apple-touch-icon.png
Normal file
BIN
raggr-frontend/public/apple-touch-icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 17 KiB |
14
raggr-frontend/public/manifest.json
Normal file
14
raggr-frontend/public/manifest.json
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"name": "Ask Simba",
|
||||||
|
"short_name": "Simba",
|
||||||
|
"description": "Chat with Simba - your AI cat companion",
|
||||||
|
"start_url": "/",
|
||||||
|
"display": "standalone",
|
||||||
|
"background_color": "#FAF8F2",
|
||||||
|
"theme_color": "#2A4D38",
|
||||||
|
"icons": [
|
||||||
|
{ "src": "/pwa-icon-192.png", "sizes": "192x192", "type": "image/png" },
|
||||||
|
{ "src": "/pwa-icon-512.png", "sizes": "512x512", "type": "image/png" },
|
||||||
|
{ "src": "/pwa-icon-512.png", "sizes": "512x512", "type": "image/png", "purpose": "maskable" }
|
||||||
|
]
|
||||||
|
}
|
||||||
BIN
raggr-frontend/public/pwa-icon-192.png
Normal file
BIN
raggr-frontend/public/pwa-icon-192.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 19 KiB |
BIN
raggr-frontend/public/pwa-icon-512.png
Normal file
BIN
raggr-frontend/public/pwa-icon-512.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 91 KiB |
46
raggr-frontend/public/sw.js
Normal file
46
raggr-frontend/public/sw.js
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
const CACHE = 'simba-v1';
|
||||||
|
|
||||||
|
self.addEventListener('install', (e) => {
|
||||||
|
self.skipWaiting();
|
||||||
|
});
|
||||||
|
|
||||||
|
self.addEventListener('activate', (e) => {
|
||||||
|
e.waitUntil(
|
||||||
|
caches.keys().then((keys) =>
|
||||||
|
Promise.all(keys.filter((k) => k !== CACHE).map((k) => caches.delete(k)))
|
||||||
|
)
|
||||||
|
);
|
||||||
|
self.clients.claim();
|
||||||
|
});
|
||||||
|
|
||||||
|
self.addEventListener('fetch', (e) => {
|
||||||
|
const { request } = e;
|
||||||
|
const url = new URL(request.url);
|
||||||
|
|
||||||
|
// Network-only for API calls
|
||||||
|
if (url.pathname.startsWith('/api/')) return;
|
||||||
|
|
||||||
|
// Cache-first for fingerprinted static assets
|
||||||
|
if (url.pathname.startsWith('/static/')) {
|
||||||
|
e.respondWith(
|
||||||
|
caches.match(request).then(
|
||||||
|
(cached) =>
|
||||||
|
cached ||
|
||||||
|
fetch(request).then((res) => {
|
||||||
|
const clone = res.clone();
|
||||||
|
caches.open(CACHE).then((c) => c.put(request, clone));
|
||||||
|
return res;
|
||||||
|
})
|
||||||
|
)
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Network-first for navigation (offline fallback to cache)
|
||||||
|
if (request.mode === 'navigate') {
|
||||||
|
e.respondWith(
|
||||||
|
fetch(request).catch(() => caches.match(request))
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
});
|
||||||
@@ -4,7 +4,16 @@ import { pluginReact } from '@rsbuild/plugin-react';
|
|||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [pluginReact()],
|
plugins: [pluginReact()],
|
||||||
html: {
|
html: {
|
||||||
title: 'Raggr',
|
title: 'Ask Simba',
|
||||||
favicon: './src/assets/favicon.svg',
|
favicon: './src/assets/favicon.svg',
|
||||||
|
tags: [
|
||||||
|
{ tag: 'link', attrs: { rel: 'manifest', href: '/manifest.json' } },
|
||||||
|
{ tag: 'meta', attrs: { name: 'theme-color', content: '#2A4D38' } },
|
||||||
|
{ tag: 'link', attrs: { rel: 'apple-touch-icon', href: '/apple-touch-icon.png' } },
|
||||||
|
{ tag: 'meta', attrs: { name: 'apple-mobile-web-app-capable', content: 'yes' } },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
output: {
|
||||||
|
copy: [{ from: './public', to: '.' }],
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -11,3 +11,9 @@ if (rootEl) {
|
|||||||
</React.StrictMode>,
|
</React.StrictMode>,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ('serviceWorker' in navigator) {
|
||||||
|
window.addEventListener('load', () => {
|
||||||
|
navigator.serviceWorker.register('/sw.js').catch(console.warn);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user