refactor(desktop): extract auto-updater into modules/auto-updater.ts

This commit is contained in:
CREDO23 2026-03-20 19:59:20 +02:00
parent 35da1cf1b4
commit d868464de7
2 changed files with 35 additions and 35 deletions

View file

@ -0,0 +1,33 @@
import { app, dialog } from 'electron';
import { autoUpdater } from 'electron-updater';
export function setupAutoUpdater(): void {
if (!app.isPackaged) return;
autoUpdater.autoDownload = true;
autoUpdater.on('update-available', (info) => {
console.log(`Update available: ${info.version}`);
});
autoUpdater.on('update-downloaded', (info) => {
console.log(`Update downloaded: ${info.version}`);
dialog.showMessageBox({
type: 'info',
buttons: ['Restart', 'Later'],
defaultId: 0,
title: 'Update Ready',
message: `Version ${info.version} has been downloaded. Restart to apply the update.`,
}).then(({ response }) => {
if (response === 0) {
autoUpdater.quitAndInstall();
}
});
});
autoUpdater.on('error', (err) => {
console.error('Auto-updater error:', err);
});
autoUpdater.checkForUpdates();
}