-
Notifications
You must be signed in to change notification settings - Fork 16
Enable PWA mode for the assistant #150
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
dbce7a2
bbf541c
8c4af21
e6b8f8d
20df6c0
4b1f697
db83bed
5adb5d5
ddbc698
f3f805d
9b3689f
ec86546
b5d4315
b63bd59
3b8d483
e8f9eb6
6100053
6ab8afe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| { | ||
| "name": "Assistant", | ||
| "short_name": "Assistant", | ||
| "description": "Your new companion to use AI efficiently, intuitively, and securely.", | ||
| "start_url": "/", | ||
| "display": "standalone", | ||
| "background_color": "#ffffff", | ||
| "theme_color": "#1B2E5F", | ||
| "orientation": "portrait-primary", | ||
| "icons": [ | ||
| { | ||
| "src": "/assets/favicon.ico", | ||
| "sizes": "48x48", | ||
| "type": "image/x-icon" | ||
| }, | ||
| { | ||
| "src": "/assets/favicon-light.png", | ||
| "sizes": "192x192", | ||
| "type": "image/png", | ||
| "purpose": "any maskable" | ||
| }, | ||
| { | ||
| "src": "/assets/favicon-dark.png", | ||
| "sizes": "192x192", | ||
| "type": "image/png", | ||
| "purpose": "any maskable" | ||
| }, | ||
| { | ||
| "src": "/assets/icon-assistant.svg", | ||
| "sizes": "any", | ||
| "type": "image/svg+xml", | ||
| "purpose": "any maskable" | ||
| } | ||
| ], | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| "categories": ["productivity", "utilities"], | ||
| "screenshots": [], | ||
| "shortcuts": [] | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| // Service Worker for PWA offline functionality | ||
| // This file will be processed by workbox-webpack-plugin during build | ||
|
|
||
| // Import workbox modules | ||
| import { clientsClaim } from 'workbox-core'; | ||
| import { ExpirationPlugin } from 'workbox-expiration'; | ||
| import { precacheAndRoute, createHandlerBoundToURL } from 'workbox-precaching'; | ||
| import { registerRoute } from 'workbox-routing'; | ||
| import { StaleWhileRevalidate, CacheFirst, NetworkFirst } from 'workbox-strategies'; | ||
|
Check warning on line 9 in src/frontend/apps/conversations/public/sw.src.js
|
||
| import { CacheableResponsePlugin } from 'workbox-cacheable-response'; | ||
|
|
||
| // Take control of all clients as soon as the service worker is activated | ||
| clientsClaim(); | ||
|
|
||
| // Precache all of the assets generated by the build process | ||
| precacheAndRoute(self.__WB_MANIFEST); | ||
|
Check warning on line 16 in src/frontend/apps/conversations/public/sw.src.js
|
||
|
|
||
| // Set up App Shell-style routing, so that all navigation requests | ||
| // are fulfilled with the index.html shell. | ||
| const fileExtensionRegexp = new RegExp('/[^/?]+\\.[^/]+$'); | ||
|
Check warning on line 20 in src/frontend/apps/conversations/public/sw.src.js
|
||
| registerRoute( | ||
| // Return false to exempt requests from being fulfilled by index.html. | ||
| ({ request, url }) => { | ||
| // If this isn't a navigation, skip. | ||
| if (request.mode !== 'navigate') { | ||
| return false; | ||
| } // If this is a URL that starts with /_, skip. | ||
| if (url.pathname.startsWith('/_')) { | ||
| return false; | ||
| } // If this looks like a URL for a resource, because it contains // a file extension, skip. | ||
| if (url.pathname.match(fileExtensionRegexp)) { | ||
| return false; | ||
| } | ||
| return true; | ||
| }, | ||
| createHandlerBoundToURL('/index.html') | ||
| ); | ||
|
|
||
| // Cache static assets (JS, CSS, images) with CacheFirst strategy | ||
| registerRoute( | ||
| ({ request }) => | ||
| request.destination === 'script' || | ||
| request.destination === 'style' || | ||
| request.destination === 'image', | ||
| new CacheFirst({ | ||
| cacheName: 'static-resources', | ||
| plugins: [ | ||
| new CacheableResponsePlugin({ | ||
| statuses: [0, 200], | ||
| }), | ||
| new ExpirationPlugin({ | ||
| maxEntries: 60, | ||
| maxAgeSeconds: 30 * 24 * 60 * 60, // 30 days | ||
| }), | ||
| ], | ||
| }) | ||
| ); | ||
|
|
||
| // Cache API responses with NetworkFirst strategy | ||
| registerRoute( | ||
| ({ url }) => url.origin === self.location.origin && url.pathname.startsWith('/api/'), | ||
| new NetworkFirst({ | ||
| cacheName: 'api-cache', | ||
| plugins: [ | ||
| new CacheableResponsePlugin({ | ||
| statuses: [0, 200], | ||
| }), | ||
| new ExpirationPlugin({ | ||
| maxEntries: 50, | ||
| maxAgeSeconds: 5 * 60, // 5 minutes | ||
| }), | ||
| ], | ||
| }) | ||
| ); | ||
|
|
||
| // Cache fonts with CacheFirst strategy | ||
| registerRoute( | ||
| ({ request }) => request.destination === 'font', | ||
| new CacheFirst({ | ||
| cacheName: 'fonts', | ||
| plugins: [ | ||
| new CacheableResponsePlugin({ | ||
| statuses: [0, 200], | ||
| }), | ||
| new ExpirationPlugin({ | ||
| maxEntries: 30, | ||
| maxAgeSeconds: 365 * 24 * 60 * 60, // 1 year | ||
| }), | ||
| ], | ||
| }) | ||
| ); | ||
|
|
||
| // This allows the web app to trigger skipWaiting via | ||
| // registration.waiting.postMessage({type: 'SKIP_WAITING'}) | ||
| self.addEventListener('message', (event) => { | ||
| if (event.data && event.data.type === 'SKIP_WAITING') { | ||
| self.skipWaiting(); | ||
|
Check warning on line 97 in src/frontend/apps/conversations/public/sw.src.js
|
||
| } | ||
| }); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| /** | ||
| * Service Worker Registration | ||
| * Registers the service worker for PWA functionality | ||
| */ | ||
|
|
||
| export function registerServiceWorker() { | ||
| if ( | ||
| typeof window !== 'undefined' && | ||
|
Check warning on line 8 in src/frontend/apps/conversations/src/utils/registerServiceWorker.ts
|
||
| 'serviceWorker' in navigator && | ||
| process.env.NODE_ENV === 'production' | ||
| ) { | ||
| window.addEventListener('load', () => { | ||
| const swUrl = '/sw.js'; | ||
|
|
||
| navigator.serviceWorker | ||
| .register(swUrl) | ||
| .then((registration) => { | ||
| // Registration was successful | ||
| console.log( | ||
| 'ServiceWorker registration successful with scope: ', | ||
| registration.scope | ||
| ); | ||
|
|
||
| // Check for updates every hour | ||
| setInterval(() => { | ||
| registration.update(); | ||
| }, 60 * 60 * 1000); | ||
|
|
||
| // Handle updates | ||
| registration.addEventListener('updatefound', () => { | ||
| const newWorker = registration.installing; | ||
| if (newWorker) { | ||
| newWorker.addEventListener('statechange', () => { | ||
|
Check failure on line 33 in src/frontend/apps/conversations/src/utils/registerServiceWorker.ts
|
||
| if ( | ||
| newWorker.state === 'installed' && | ||
| navigator.serviceWorker.controller | ||
| ) { | ||
| // New service worker available, prompt user to refresh | ||
| if ( | ||
| window.confirm( | ||
|
Check warning on line 40 in src/frontend/apps/conversations/src/utils/registerServiceWorker.ts
|
||
| 'New version available! Would you like to update?' | ||
| ) | ||
| ) { | ||
| newWorker.postMessage({ type: 'SKIP_WAITING' }); | ||
| window.location.reload(); | ||
|
Check warning on line 45 in src/frontend/apps/conversations/src/utils/registerServiceWorker.ts
|
||
| } | ||
| } | ||
| }); | ||
| } | ||
| }); | ||
| }) | ||
| .catch((error) => { | ||
| console.error('ServiceWorker registration failed: ', error); | ||
| }); | ||
|
|
||
| // Handle service worker updates | ||
| let refreshing = false; | ||
| navigator.serviceWorker.addEventListener('controllerchange', () => { | ||
| if (!refreshing) { | ||
| refreshing = true; | ||
| window.location.reload(); | ||
|
Check warning on line 61 in src/frontend/apps/conversations/src/utils/registerServiceWorker.ts
|
||
| } | ||
| }); | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }); | ||
| } | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.