@@ -2,10 +2,22 @@ import { triggerServerUpdate } from './server-api';
22
33import packageMetadata from '../../package.json' ;
44import { desktopVersion , serverVersion , versionSatisfies } from './service-versions' ;
5+ import { logError } from '../errors' ;
56
67export const attemptServerUpdate = ( ) =>
78 triggerServerUpdate ( ) . catch ( console . warn ) ;
89
10+ let swFailureAlerted = false ;
11+ const alertFailedSWStartup = ( e : any ) => {
12+ if ( swFailureAlerted ) return ; // Only alert once
13+ swFailureAlerted = true ;
14+
15+ const msg = "Initialization failed - background updates & cached/offline startup will be unavailable" ;
16+
17+ logError ( msg , { cause : e } ) ;
18+ alert ( msg ) ;
19+ } ;
20+
921// Set up a SW in the background, to add offline support & instant startup.
1022// This also checks for new UI & server versions at intervals.
1123export async function runBackgroundUpdates ( ) {
@@ -19,14 +31,19 @@ export async function runBackgroundUpdates() {
1931
2032 try {
2133 if ( ! navigator ?. serviceWorker ?. register ) {
22- console . warn ( 'Service worker not supported - cached & offline startup will not be available' ) ;
34+ console . warn ( 'Service worker not supported' ) ;
35+ alertFailedSWStartup ( "Not supported" ) ;
2336 return ;
2437 }
2538
2639 const registration = await navigator . serviceWorker . register (
2740 '/ui-update-worker.js' ,
2841 { scope : '/' }
29- ) ;
42+ ) . catch ( ( e ) => {
43+ console . warn ( 'Service worker registration failed' ) ;
44+ alertFailedSWStartup ( e ) ;
45+ throw e ;
46+ } ) ;
3047
3148 console . log ( 'Service worker loaded' ) ;
3249 registration . update ( ) . catch ( console . log ) ;
0 commit comments