File tree Expand file tree Collapse file tree 2 files changed +22
-18
lines changed
Expand file tree Collapse file tree 2 files changed +22
-18
lines changed Original file line number Diff line number Diff line change @@ -56,12 +56,16 @@ let persistedClientStats: Record<string, ClientStats> | null = null;
5656// Error Handling
5757// ==========================
5858
59- const showJSError = ( message : string ) => {
59+ const showJSErrorDiv = ( doShow = true ) => {
6060 const errorDiv = document . getElementById ( 'js-error' ) as HTMLDivElement ;
61+ errorDiv . hidden = ! doShow ;
62+ }
63+
64+ const showJSError = ( message : string ) => {
6165 const messageEl = document . getElementById ( 'js-error-message' ) as HTMLParagraphElement ;
62- if ( errorDiv && messageEl ) {
66+ if ( messageEl ) {
6367 messageEl . textContent = message ;
64- errorDiv . hidden = false ;
68+ showJSErrorDiv ( true ) ;
6569 }
6670} ;
6771
@@ -118,6 +122,7 @@ const connectWebSocket = () => {
118122 // `ev` is typically an Event without much detail; still log to help
119123 // spot timing or repeated failures.
120124 console . error ( 'WebSocket error' , ev ) ;
125+ showJSError ( `A WebSocket error occurred, please check the console for details.` ) ;
121126 } ;
122127 socket . onclose = ( ev ) => {
123128 console . warn ( 'WebSocket closed' , { code : ev . code , reason : ev . reason , wasClean : ev . wasClean } ) ;
Original file line number Diff line number Diff line change @@ -77,20 +77,19 @@ self.addEventListener('notificationclick', (event) => {
7777 event . notification . close ( ) ;
7878
7979 // Focus existing window or open new one
80- event . waitUntil (
81- self . clients . matchAll ( { type : 'window' , includeUncontrolled : true } ) . then ( ( clientList : readonly WindowClient [ ] ) => {
82- const url = self . location . origin ;
83-
84- for ( const client of clientList ) {
85- if ( client . url === url && 'focus' in client ) {
86- return client . focus ( ) ;
87- }
88- }
89-
90- if ( self . clients . openWindow ) {
91- return self . clients . openWindow ( url ) ;
80+ event . waitUntil ( ( async ( ) => {
81+ const clientList = await self . clients . matchAll ( { type : 'window' , includeUncontrolled : true } ) ;
82+ const url = self . location . origin ;
83+
84+ for ( const client of clientList ) {
85+ if ( client . url === url && 'focus' in client ) {
86+ return client . focus ( ) ;
9287 }
93- return Promise . resolve ( null ) ;
94- } )
95- ) ;
88+ }
89+
90+ if ( self . clients . openWindow ) {
91+ return self . clients . openWindow ( url ) ;
92+ }
93+ return null ;
94+ } ) ( ) ) ;
9695} ) ;
You can’t perform that action at this time.
0 commit comments