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:
ryan
2026-03-17 20:16:27 -04:00
parent 6917f331d8
commit 0f88d211de
7 changed files with 76 additions and 1 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

View 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" }
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 91 KiB

View 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;
}
});

View File

@@ -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: '.' }],
}, },
}); });

View File

@@ -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);
});
}