periodic update check
All checks were successful
/ upload (release) Successful in 3m39s

This commit is contained in:
pavel 2026-02-28 15:15:42 +01:00
commit 9d7f658fc0

20
main.js
View file

@ -2,6 +2,7 @@ const { app, BrowserWindow, session, desktopCapturer, ipcMain, clipboard } = req
const { autoUpdater } = require('electron-updater'); const { autoUpdater } = require('electron-updater');
const path = require('path'); const path = require('path');
const packageJson = require('./package.json'); const packageJson = require('./package.json');
const PERIODIC_UPDATE_CHECK_INTERVAL_MS = 1 * 60 * 1000;
const updateState = { const updateState = {
status: 'idle', // idle | checking | available | downloading | downloaded | installing | not-available | error status: 'idle', // idle | checking | available | downloading | downloaded | installing | not-available | error
@ -25,6 +26,7 @@ function isNewerVersionAvailable(info) {
let updateCheckInProgress = false; let updateCheckInProgress = false;
let installInProgress = false; let installInProgress = false;
let periodicUpdateTimer = null;
function resolveBackendUrl() { function resolveBackendUrl() {
const configuredUrl = (process.env.CHATTZ_URL || process.env.APP_BASE_URL || '').trim(); const configuredUrl = (process.env.CHATTZ_URL || process.env.APP_BASE_URL || '').trim();
@ -124,6 +126,16 @@ function installDownloadedUpdate() {
}, 15000); }, 15000);
} }
function startPeriodicUpdateChecks() {
if (periodicUpdateTimer || !app.isPackaged) {
return;
}
periodicUpdateTimer = setInterval(() => {
void runUpdateCheck('periodic');
}, PERIODIC_UPDATE_CHECK_INTERVAL_MS);
}
function createWindow() { function createWindow() {
const sess = session.fromPartition('persist:chattz'); const sess = session.fromPartition('persist:chattz');
const backendUrl = resolveBackendUrl(); const backendUrl = resolveBackendUrl();
@ -270,6 +282,7 @@ app.whenReady().then(() => {
setTimeout(() => { setTimeout(() => {
void runUpdateCheck('startup'); void runUpdateCheck('startup');
}, 5000); }, 5000);
startPeriodicUpdateChecks();
app.on('activate', () => { app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) { 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) { function safeOrigin(value) {
try { try {
return new URL(value).origin; return new URL(value).origin;