From 9d7f658fc0b0d4a2b3af61a259323de75df55a09 Mon Sep 17 00:00:00 2001 From: pavel Date: Sat, 28 Feb 2026 15:15:42 +0100 Subject: [PATCH] periodic update check --- main.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/main.js b/main.js index f759b3f..030c413 100644 --- a/main.js +++ b/main.js @@ -2,6 +2,7 @@ const { app, BrowserWindow, session, desktopCapturer, ipcMain, clipboard } = req const { autoUpdater } = require('electron-updater'); const path = require('path'); const packageJson = require('./package.json'); +const PERIODIC_UPDATE_CHECK_INTERVAL_MS = 1 * 60 * 1000; const updateState = { status: 'idle', // idle | checking | available | downloading | downloaded | installing | not-available | error @@ -25,6 +26,7 @@ function isNewerVersionAvailable(info) { let updateCheckInProgress = false; let installInProgress = false; +let periodicUpdateTimer = null; function resolveBackendUrl() { const configuredUrl = (process.env.CHATTZ_URL || process.env.APP_BASE_URL || '').trim(); @@ -124,6 +126,16 @@ function installDownloadedUpdate() { }, 15000); } +function startPeriodicUpdateChecks() { + if (periodicUpdateTimer || !app.isPackaged) { + return; + } + + periodicUpdateTimer = setInterval(() => { + void runUpdateCheck('periodic'); + }, PERIODIC_UPDATE_CHECK_INTERVAL_MS); +} + function createWindow() { const sess = session.fromPartition('persist:chattz'); const backendUrl = resolveBackendUrl(); @@ -270,6 +282,7 @@ app.whenReady().then(() => { setTimeout(() => { void runUpdateCheck('startup'); }, 5000); + startPeriodicUpdateChecks(); app.on('activate', () => { if (BrowserWindow.getAllWindows().length === 0) { @@ -284,6 +297,13 @@ app.on('window-all-closed', () => { } }); +app.on('before-quit', () => { + if (periodicUpdateTimer) { + clearInterval(periodicUpdateTimer); + periodicUpdateTimer = null; + } +}); + function safeOrigin(value) { try { return new URL(value).origin;