Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 28 additions & 13 deletions src/components/update-notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class UpdateNotification {
if (getUpdateManager()) {
console.log('✅ [UpdateNotification] UpdateManager trovato, bind eventi notifica');
this.bindEvents();

// RIMOSSO: Il controllo dello stato iniziale può causare problemi
// L'updateManager dovrebbe emettere gli eventi corretti al momento giusto
} else {
Expand Down Expand Up @@ -357,10 +357,23 @@ export class UpdateNotification {
*/
bindButtonEvents() {
const buttons = this.container.querySelectorAll('[data-action]');
console.log('🔔 [UpdateNotification] Trovati', buttons.length, 'pulsanti con data-action');
buttons.forEach(button => {
console.log('🔔 [UpdateNotification] Binding evento per pulsante:', button.dataset.action);
button.addEventListener('click', (e) => {
const action = e.target.dataset.action;
this.handleAction(action);
// Trova il pulsante con data-action, anche se si clicca su un elemento figlio (come l'icona SVG)
let target = e.target;
while (target && !target.dataset.action) {
target = target.parentElement;
}

const action = target ? target.dataset.action : null;
console.log('🔔 [UpdateNotification] Target trovato:', target, 'Action:', action);
if (action) {
this.handleAction(action);
} else {
console.warn('🔔 [UpdateNotification] Nessuna azione trovata per questo click');
}
});
});
}
Expand All @@ -369,6 +382,7 @@ export class UpdateNotification {
* Handles button actions
*/
handleAction(action) {
console.log('🔔 [UpdateNotification] Azione pulsante:', action);
switch (action) {
case 'download':
this.startDownload();
Expand Down Expand Up @@ -538,14 +552,15 @@ export class UpdateNotification {
}

// Verifica se siamo in modalità sviluppo senza test mode
const updateManager = getUpdateManager();
if (updateManager && updateManager.isDevelopmentMode && updateManager.isDevelopmentMode()) {
const hasTestMode = localStorage.getItem('presto_force_update_test') === 'true';
if (!hasTestMode) {
console.log('🔍 [UpdateNotification] Modalità sviluppo senza test mode - non mostro notifica');
return;
}
}
// RIMOSSO: Ora permettiamo la notifica anche in modalità sviluppo per GitHub releases
// const updateManager = getUpdateManager();
// if (updateManager && updateManager.isDevelopmentMode && updateManager.isDevelopmentMode()) {
// const hasTestMode = localStorage.getItem('presto_force_update_test') === 'true';
// if (!hasTestMode) {
// console.log('🔍 [UpdateNotification] Modalità sviluppo senza test mode - non mostro notifica');
// return;
// }
// }

// Don't show if this version has been skipped
if (this.isVersionSkipped(updateInfo.version)) {
Expand Down Expand Up @@ -659,5 +674,5 @@ export class UpdateNotification {
}
}

// Export singleton instance
export const updateNotification = new UpdateNotification();
// Export the class, not an instance - let main.js handle initialization
// export const updateNotification = new UpdateNotification();
52 changes: 29 additions & 23 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { TeamManager } from './managers/team-manager.js';
// Auth manager will be imported after Supabase is loaded
import { PomodoroTimer } from './core/pomodoro-timer.js';
import { NotificationUtils } from './utils/common-utils.js';
// Removed unused import: updateNotification
import { UpdateNotification } from './components/update-notification.js';

// Global application state
let timer = null;
Expand Down Expand Up @@ -299,42 +299,42 @@ async function initializeEarlyTheme() {

// Helper function to check if Tauri is available and ready
function isTauriReady() {
return typeof window !== 'undefined' &&
window.__TAURI__ &&
window.__TAURI__.core &&
typeof window.__TAURI__.core.invoke === 'function';
return typeof window !== 'undefined' &&
window.__TAURI__ &&
window.__TAURI__.core &&
typeof window.__TAURI__.core.invoke === 'function';
}

// Helper function to wait for Tauri to be ready (with timeout)
function waitForTauri(maxWaitTime = 2000) {
return new Promise((resolve) => {
const startTime = Date.now();

const checkTauri = () => {
if (isTauriReady()) {
resolve(true);
return;
}

if (Date.now() - startTime > maxWaitTime) {
resolve(false);
return;
}

setTimeout(checkTauri, 50);
};

checkTauri();
});
}

try {
// Wait for Tauri to be ready before trying to load settings
const tauriReady = await waitForTauri();

if (tauriReady) {
console.log('🎨 Tauri is ready, loading theme from settings...');

try {
const { invoke } = window.__TAURI__.core;
const savedSettings = await invoke('load_settings');
Expand Down Expand Up @@ -1467,19 +1467,19 @@ async function initializeApplication() {
console.log('🚀 Application already fully initialized, skipping...');
return;
}

// Prevent concurrent initialization attempts
if (window._appInitializing) {
console.log('🚀 Application initialization already in progress, skipping...');
return;
}

// Set initialization flag early to prevent race conditions
window._appInitializing = true;

try {
console.log('🚀 Initializing Presto application...');

// Show loading state
const loadingOverlay = document.createElement('div');
loadingOverlay.id = 'app-loading';
Expand Down Expand Up @@ -1512,7 +1512,7 @@ async function initializeApplication() {
if (stuckOverlay) {
console.error('⚠️ Initialization timeout - removing loading overlay');
stuckOverlay.remove();

// Show error message
NotificationUtils.showNotificationPing('Initialization timed out. Please refresh! 🔄', 'error');
}
Expand Down Expand Up @@ -1556,6 +1556,11 @@ async function initializeApplication() {
window.updateManager.loadPreferences(); // Carica le preferenze salvate se supportato
}

// Initialize Update Notification component
console.log('🔔 Initializing Update Notification...');
const updateNotification = new UpdateNotification();
window.updateNotification = updateNotification; // Make it globally available

// Skip first run authentication - proceed directly with guest mode
if (authManager.isFirstRun()) {
console.log('👋 First run detected, proceeding as guest...');
Expand Down Expand Up @@ -1613,7 +1618,7 @@ async function initializeApplication() {

// Clear safety timeout
clearTimeout(safetyTimeout);

// Mark as fully initialized
window._appFullyInitialized = true;
window._appInitializing = false;
Expand All @@ -1629,21 +1634,21 @@ async function initializeApplication() {

} catch (error) {
console.error('❌ Failed to initialize application:', error);

// Clear safety timeout and remove loading overlay even on error
clearTimeout(safetyTimeout);
const loadingOverlayError = document.getElementById('app-loading');
if (loadingOverlayError) {
loadingOverlayError.remove();
}

// Show error notification
NotificationUtils.showNotificationPing('Failed to initialize app. Please refresh! 🔄', 'error');

// Reset initialization flags on error so user can retry
window._appInitializing = false;
window._appFullyInitialized = false;

// Show error screen instead of leaving user with blank screen
const errorScreen = document.createElement('div');
errorScreen.id = 'app-error';
Expand Down Expand Up @@ -1891,9 +1896,10 @@ function setupUpdateManagement() {
}
});

updateManager.on('checkError', () => {
updateManager.on('checkError', (event) => {
if (updateStatus) {
updateStatus.innerHTML = '<span class="status-text error">Check failed</span>';
const errorMessage = event?.detail?.message || 'Check failed';
updateStatus.innerHTML = `<span class="status-text error">${errorMessage}</span>`;
}
});

Expand Down
Loading
Loading