This commit is contained in:
parent
c9592a9cb0
commit
9d7f658fc0
1 changed files with 20 additions and 0 deletions
20
main.js
20
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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue