44 * Component for showing update notifications in the user interface
55 */
66
7- import { updateManager } from '../managers/update-manager.js' ;
7+ // Usa l'updateManager globale invece dell'import per essere sincronizzato con main.js
8+ const getUpdateManager = ( ) => window . updateManager || window . updateManagerInstance ;
89
910export class UpdateNotification {
1011 constructor ( ) {
@@ -14,7 +15,32 @@ export class UpdateNotification {
1415 this . currentVersion = null ;
1516
1617 this . createNotificationContainer ( ) ;
17- this . bindEvents ( ) ;
18+ // Aspetta che l'updateManager sia disponibile prima di bind degli eventi
19+ this . waitForUpdateManager ( ) ;
20+ }
21+
22+ /**
23+ * Aspetta che l'updateManager sia disponibile e poi bind gli eventi
24+ */
25+ async waitForUpdateManager ( ) {
26+ // Aspetta che l'updateManager sia disponibile (max 10 secondi)
27+ let attempts = 0 ;
28+ const maxAttempts = 100 ; // 10 secondi con 100ms di intervallo
29+
30+ while ( attempts < maxAttempts && ! getUpdateManager ( ) ) {
31+ await new Promise ( resolve => setTimeout ( resolve , 100 ) ) ;
32+ attempts ++ ;
33+ }
34+
35+ if ( getUpdateManager ( ) ) {
36+ console . log ( '✅ [UpdateNotification] UpdateManager trovato, bind eventi notifica' ) ;
37+ this . bindEvents ( ) ;
38+
39+ // RIMOSSO: Il controllo dello stato iniziale può causare problemi
40+ // L'updateManager dovrebbe emettere gli eventi corretti al momento giusto
41+ } else {
42+ console . warn ( '⚠️ [UpdateNotification] UpdateManager non trovato dopo 10 secondi' ) ;
43+ }
1844 }
1945
2046 /**
@@ -87,7 +113,7 @@ export class UpdateNotification {
87113 styles . textContent = `
88114 .update-notification-container {
89115 position: fixed;
90- top: 40px ;
116+ top: 0 ;
91117 left: 0;
92118 right: 0;
93119 z-index: 10000;
@@ -447,10 +473,38 @@ export class UpdateNotification {
447473 * Binds update manager events
448474 */
449475 bindEvents ( ) {
476+ const updateManager = getUpdateManager ( ) ;
477+
478+ if ( ! updateManager ) {
479+ console . error ( '❌ [UpdateNotification] UpdateManager non disponibile per bind eventi notifica' ) ;
480+ return ;
481+ }
482+
483+ console . log ( '🔔 [UpdateNotification] Bind eventi notifica aggiornamenti...' ) ;
484+ console . log ( '🔍 [UpdateNotification] UpdateManager state:' , {
485+ updateAvailable : updateManager . updateAvailable ,
486+ currentUpdate : updateManager . currentUpdate ,
487+ isDevelopmentMode : updateManager . isDevelopmentMode ? updateManager . isDevelopmentMode ( ) : 'N/A' ,
488+ testMode : localStorage . getItem ( 'presto_force_update_test' )
489+ } ) ;
490+
450491 updateManager . on ( 'updateAvailable' , ( event ) => {
492+ console . log ( '🔔 [UpdateNotification] Evento updateAvailable ricevuto:' , event . detail ) ;
451493 this . showUpdateAvailable ( event . detail ) ;
452494 } ) ;
453495
496+ // Ascolta anche quando NON ci sono aggiornamenti per nascondere la notifica
497+ updateManager . on ( 'updateNotAvailable' , ( ) => {
498+ console . log ( '👍 [UpdateNotification] Nessun aggiornamento disponibile - nascondo notifica' ) ;
499+ this . hide ( ) ;
500+ } ) ;
501+
502+ // Nasconde la notifica anche quando il controllo fallisce
503+ updateManager . on ( 'checkError' , ( ) => {
504+ console . log ( '❌ [UpdateNotification] Errore controllo aggiornamenti - nascondo notifica' ) ;
505+ this . hide ( ) ;
506+ } ) ;
507+
454508 updateManager . on ( 'downloadProgress' , ( event ) => {
455509 const { progress } = event . detail ;
456510 this . updateProgress ( progress ) ;
@@ -469,16 +523,37 @@ export class UpdateNotification {
469523 * Shows update available notification
470524 */
471525 showUpdateAvailable ( updateInfo ) {
526+ console . log ( '🔔 [UpdateNotification] Richiesta mostra notifica aggiornamento:' , updateInfo ) ;
527+
472528 if ( ! updateInfo || ! updateInfo . version ) {
529+ console . log ( '❌ [UpdateNotification] Informazioni aggiornamento non valide - non mostro notifica' ) ;
473530 return ;
474531 }
475532
533+ // Verifica esplicita che l'aggiornamento sia davvero disponibile
534+ if ( updateInfo . available === false ) {
535+ console . log ( '❌ [UpdateNotification] Aggiornamento esplicitamente non disponibile - non mostro notifica' ) ;
536+ return ;
537+ }
538+
539+ // Verifica se siamo in modalità sviluppo senza test mode
540+ const updateManager = getUpdateManager ( ) ;
541+ if ( updateManager && updateManager . isDevelopmentMode && updateManager . isDevelopmentMode ( ) ) {
542+ const hasTestMode = localStorage . getItem ( 'presto_force_update_test' ) === 'true' ;
543+ if ( ! hasTestMode ) {
544+ console . log ( '🔍 [UpdateNotification] Modalità sviluppo senza test mode - non mostro notifica' ) ;
545+ return ;
546+ }
547+ }
548+
476549 // Don't show if this version has been skipped
477550 if ( this . isVersionSkipped ( updateInfo . version ) ) {
478- console . log ( `Version ${ updateInfo . version } was skipped, not showing notification ` ) ;
551+ console . log ( `⏭️ [UpdateNotification] Versione ${ updateInfo . version } è stata saltata - non mostro notifica ` ) ;
479552 return ;
480553 }
481554
555+ console . log ( `✅ [UpdateNotification] Mostro notifica per aggiornamento ${ updateInfo . version } ` ) ;
556+
482557 this . currentVersion = updateInfo . version ;
483558
484559 const versionElement = this . container . querySelector ( '.update-version' ) ;
@@ -518,7 +593,12 @@ export class UpdateNotification {
518593 * Shows the notification
519594 */
520595 show ( ) {
521- if ( this . isVisible ) return ;
596+ if ( this . isVisible ) {
597+ console . log ( '🔔 [UpdateNotification] Notifica già visibile - skip' ) ;
598+ return ;
599+ }
600+
601+ console . log ( '🔔 [UpdateNotification] Mostro notifica aggiornamento' ) ;
522602
523603 this . container . style . display = 'block' ;
524604
@@ -536,7 +616,12 @@ export class UpdateNotification {
536616 * Hides the notification
537617 */
538618 hide ( ) {
539- if ( ! this . isVisible ) return ;
619+ if ( ! this . isVisible ) {
620+ console . log ( '🔔 [UpdateNotification] Notifica già nascosta - skip' ) ;
621+ return ;
622+ }
623+
624+ console . log ( '🔔 [UpdateNotification] Nascondo notifica aggiornamento' ) ;
540625
541626 this . container . classList . remove ( 'visible' ) ;
542627
0 commit comments