@@ -20,21 +20,6 @@ notificationChannel.onmessage = (event) => {
2020 }
2121} ;
2222
23- // NEW: Listen for direct messages from the service worker
24- navigator . serviceWorker . addEventListener ( 'message' , event => {
25- if ( event . data && event . data . type === 'navigate-to-program' ) {
26- console . log ( '[NOTIF] Received navigate-to-program message from SW.' ) ;
27- const { channelId, programStart, programId } = event . data . data ;
28- if ( channelId && programStart ) {
29- // A short delay can help ensure the UI is ready, especially if the app was just opened.
30- setTimeout ( ( ) => {
31- navigateToProgramInGuide ( channelId , programStart , programId ) ;
32- } , 500 ) ;
33- }
34- }
35- } ) ;
36-
37-
3823function urlBase64ToUint8Array ( base64String ) {
3924 const padding = '=' . repeat ( ( 4 - base64String . length % 4 ) % 4 ) ;
4025 const base64 = ( base64String + padding ) . replace ( / - / g, '+' ) . replace ( / _ / g, '/' ) ;
@@ -386,23 +371,18 @@ const setupNotificationListEventListeners = () => {
386371
387372export const navigateToProgramInGuide = async ( channelId , programStart , programId ) => {
388373 console . log ( `[NOTIF_NAV] Navigating to program. Channel: ${ channelId } , Start: ${ programStart } ` ) ;
389-
390- // Fallback for potentially incomplete channelId from older notifications
391- const stableChannelIdSuffix = channelId . includes ( '_' ) ? channelId . split ( '_' ) . pop ( ) : channelId ;
374+ const stableChannelIdSuffix = channelId . includes ( '_' ) ? '_' + channelId . split ( '_' ) . pop ( ) : channelId ;
392375
393376 navigate ( '/tvguide' ) ;
394-
395- // Give the UI a moment to switch tabs and render the guide structure
396- await new Promise ( resolve => setTimeout ( resolve , 100 ) ) ;
377+ await new Promise ( resolve => setTimeout ( resolve , 50 ) ) ;
397378
398379 const targetProgramStart = new Date ( programStart ) ;
399380 const currentGuideDate = new Date ( guideState . currentDate ) ;
400381 currentGuideDate . setHours ( 0 , 0 , 0 , 0 ) ;
401382
402- // If the program is not on the currently displayed date, switch the date and reload the guide
403383 if ( targetProgramStart . toDateString ( ) !== currentGuideDate . toDateString ( ) ) {
404384 guideState . currentDate = targetProgramStart ;
405- await handleSearchAndFilter ( true ) ; // `true` forces a full reload and scroll reset
385+ await handleSearchAndFilter ( true ) ;
406386 }
407387
408388 const channelScrolledAndRendered = await scrollToChannel ( stableChannelIdSuffix ) ;
@@ -412,15 +392,13 @@ export const navigateToProgramInGuide = async (channelId, programStart, programI
412392 return ;
413393 }
414394
415- // Now that the channel is visible, find its full dynamic ID
416395 const currentChannelElement = UIElements . guideGrid . querySelector ( `.channel-info[data-id$="${ stableChannelIdSuffix } "]` ) ;
417396 if ( ! currentChannelElement ) {
418- showNotification ( "An unexpected error occurred while locating the channel element ." , true ) ;
397+ showNotification ( "An unexpected error occurred while locating the channel." , true ) ;
419398 return ;
420399 }
421400 const currentDynamicChannelId = currentChannelElement . dataset . id ;
422401
423- // Finally, find the specific program element
424402 const programElement = UIElements . guideGrid . querySelector (
425403 `.programme-item[data-prog-start="${ programStart } "][data-channel-id="${ currentDynamicChannelId } "]`
426404 ) ;
@@ -434,7 +412,6 @@ export const navigateToProgramInGuide = async (channelId, programStart, programI
434412 const programRect = programElement . getBoundingClientRect ( ) ;
435413 const containerRect = guideContainer . getBoundingClientRect ( ) ;
436414
437- // Calculate the desired scroll position to center the program both vertically and horizontally
438415 const desiredScrollTop = guideContainer . scrollTop + programRect . top - containerRect . top - ( containerRect . height / 2 ) + ( programRect . height / 2 ) ;
439416 const desiredScrollLeft = guideContainer . scrollLeft + programRect . left - containerRect . left - ( containerRect . width / 2 ) + ( programRect . width / 2 ) ;
440417
@@ -444,10 +421,9 @@ export const navigateToProgramInGuide = async (channelId, programStart, programI
444421 behavior : 'smooth'
445422 } ) ;
446423
447- // Use a timeout to ensure scrolling is complete before opening details and highlighting
448424 setTimeout ( ( ) => {
449425 openProgramDetails ( programElement ) ;
450426 programElement . classList . add ( 'highlighted-search' ) ;
451427 setTimeout ( ( ) => { programElement . classList . remove ( 'highlighted-search' ) ; } , 2500 ) ;
452- } , 350 ) ;
428+ } , 300 ) ;
453429} ;
0 commit comments