diff --git a/jccm/src/Frontend/Main.js b/jccm/src/Frontend/Main.js index 515c106..0ec64a0 100644 --- a/jccm/src/Frontend/Main.js +++ b/jccm/src/Frontend/Main.js @@ -93,7 +93,7 @@ export const Main = () => { useEffect(() => { const generateEvents = async () => { - await delay(1000); + await delay(1000); // Delay for 1 second await eventBus.emit('user-session-check'); await eventBus.emit('local-inventory-refresh'); await eventBus.emit('device-facts-refresh'); diff --git a/jccm/src/Services/AutoUpdate.js b/jccm/src/Services/AutoUpdate.js index bb09458..ae0933c 100644 --- a/jccm/src/Services/AutoUpdate.js +++ b/jccm/src/Services/AutoUpdate.js @@ -28,33 +28,40 @@ export const setupAutoUpdate = () => { return false; } }); + let isFirstUpdateCheck = true; // Track if it's the first call + ipcMain.handle('check-for-updates', (event) => { console.log('Checking for updates...'); return new Promise((resolve, reject) => { - let isUpdateAvailable = false; - - autoUpdater.once('update-available', () => { - console.log('Update available.'); - isUpdateAvailable = true; - }); - - autoUpdater.once('update-not-available', () => { - console.log('No update available.'); - isUpdateAvailable = false; - }); - - // Set a timeout to reject the promise if no updates are found quickly - const timeout = setTimeout(() => { - console.log('Update check will complete in 3 seconds. Please wait...'); - autoUpdater.removeAllListeners('update-available'); - autoUpdater.removeAllListeners('update-not-available'); - console.log('Update check result:', isUpdateAvailable); - resolve(isUpdateAvailable); - }, 3000); - - // Initiate the update check - autoUpdater.checkForUpdates(); + const delay = isFirstUpdateCheck ? 10000 : 0; // 10-second delay for the first call only because of https://www.electronjs.org/docs/latest/api/auto-updater#windows + isFirstUpdateCheck = false; // Reset after first call + + setTimeout(() => { + let isUpdateAvailable = false; + + autoUpdater.once('update-available', () => { + console.log('Update available.'); + isUpdateAvailable = true; + }); + + autoUpdater.once('update-not-available', () => { + console.log('No update available.'); + isUpdateAvailable = false; + }); + + // Timeout to finalize the check if listeners do not resolve quickly + const timeout = setTimeout(() => { + console.log('Update check will complete in 3 seconds. Please wait...'); + autoUpdater.removeAllListeners('update-available'); + autoUpdater.removeAllListeners('update-not-available'); + console.log('Update check result:', isUpdateAvailable); + resolve(isUpdateAvailable); + }, 3000); + + // Initiate the update check + autoUpdater.checkForUpdates(); + }, delay); // Apply the delay if it's the first call }); });