Add: Auto-Updater fuer Electron App

- Server: /updates Endpoint fuer Squirrel.Windows Update-Feed
- Electron: autoUpdater mit 30min Check-Intervall
- Preload: IPC-Events fuer Update-Status ans Frontend

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Daniel 2026-03-07 13:45:27 +01:00
parent c8799710ac
commit 5eab3c1956
3 changed files with 59 additions and 3 deletions

View file

@ -1,4 +1,4 @@
const { app, BrowserWindow, session, shell, desktopCapturer } = require('electron');
const { app, BrowserWindow, session, shell, desktopCapturer, autoUpdater } = require('electron');
const path = require('path');
const { setupAdBlocker } = require('./ad-blocker');
@ -11,6 +11,43 @@ try {
const HUB_URL = process.env.GAMING_HUB_URL || 'https://hub.daddelolymp.de';
function setupAutoUpdater() {
if (process.platform !== 'win32') return;
const updateURL = `${HUB_URL}/updates`;
try {
autoUpdater.setFeedURL({ url: updateURL });
} catch (e) {
console.error('[AutoUpdater] setFeedURL failed:', e.message);
return;
}
autoUpdater.on('update-available', () => {
console.log('[AutoUpdater] Update available, downloading...');
});
autoUpdater.on('update-downloaded', (_event, releaseNotes, releaseName) => {
console.log('[AutoUpdater] Update downloaded:', releaseName || 'new version');
});
autoUpdater.on('update-not-available', () => {
console.log('[AutoUpdater] App is up to date.');
});
autoUpdater.on('error', (err) => {
console.error('[AutoUpdater] Error:', err.message);
});
// Check for updates after 5 seconds, then every 30 minutes
setTimeout(() => {
try { autoUpdater.checkForUpdates(); } catch (e) { console.error('[AutoUpdater]', e.message); }
}, 5000);
setInterval(() => {
try { autoUpdater.checkForUpdates(); } catch (e) { console.error('[AutoUpdater]', e.message); }
}, 30 * 60 * 1000);
}
let mainWindow;
function createWindow() {
@ -64,7 +101,10 @@ function createWindow() {
});
}
app.whenReady().then(createWindow);
app.whenReady().then(() => {
createWindow();
setupAutoUpdater();
});
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') app.quit();

View file

@ -1,6 +1,9 @@
const { contextBridge } = require('electron');
const { contextBridge, ipcRenderer } = require('electron');
contextBridge.exposeInMainWorld('electronAPI', {
isElectron: true,
version: '1.5.0',
onUpdateAvailable: (callback) => ipcRenderer.on('update-available', callback),
onUpdateReady: (callback) => ipcRenderer.on('update-ready', callback),
installUpdate: () => ipcRenderer.send('install-update'),
});