From 8bf7f47186c64b4a7077dd94831e99ac07ac468f Mon Sep 17 00:00:00 2001 From: Git Manager GUI Date: Thu, 7 May 2026 22:16:17 +0200 Subject: [PATCH] Upload via Git Manager GUI --- updater.js | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/updater.js b/updater.js index 65c69b3..0fa5252 100644 --- a/updater.js +++ b/updater.js @@ -15,6 +15,22 @@ class Updater { this.checkingForUpdates = false; } + emitUpdateError(message, details = {}) { + const payload = { + message: String(message || 'Update-Fehler'), + details, + timestamp: new Date().toISOString() + }; + + try { + if (this.mainWindow && this.mainWindow.webContents) { + this.mainWindow.webContents.send('update-error', payload); + } + } catch (_) { + // no-op: update errors should never crash the app + } + } + /** * Hauptfunktion zur Prüfung auf Updates */ @@ -58,6 +74,11 @@ class Updater { } } catch (error) { console.error('[Updater] Fehler beim Update-Check:', error); + this.emitUpdateError('Update-Pruefung fehlgeschlagen.', { + phase: 'check', + silent: !!silent, + error: String(error?.message || error) + }); } finally { this.checkingForUpdates = false; } @@ -67,6 +88,10 @@ class Updater { return new Promise((resolve, reject) => { const options = { headers: { 'User-Agent': 'GitManager-GUI-Updater' } }; https.get(GITEA_API_URL, options, (res) => { + if (res.statusCode !== 200) { + reject(new Error(`Release-API antwortete mit HTTP ${res.statusCode}`)); + return; + } let data = ''; res.on('data', chunk => data += chunk); res.on('end', () => { @@ -212,11 +237,19 @@ class Updater { async startDownload(asset) { if (!asset || !asset.browser_download_url) { console.error("[Updater] Kein gültiges Asset gefunden!"); + this.emitUpdateError('Update-Download fehlgeschlagen: Kein gueltiges Installer-Asset gefunden.', { + phase: 'download', + reason: 'invalid-asset' + }); return; } if (!this.isTrustedDownloadUrl(asset.browser_download_url)) { console.error('[Updater] Unsichere Download-URL blockiert.'); + this.emitUpdateError('Update blockiert: Unsichere Download-URL.', { + phase: 'download', + reason: 'untrusted-download-url' + }); return; } @@ -228,11 +261,20 @@ class Updater { expectedSha256 = await this.resolveExpectedSha256(asset); } catch (e) { console.error('[Updater] Konnte erwartete Checksumme nicht laden:', e?.message || e); + this.emitUpdateError('Update-Download fehlgeschlagen: Checksumme konnte nicht geladen werden.', { + phase: 'download', + reason: 'checksum-load-failed', + error: String(e?.message || e) + }); return; } if (!expectedSha256) { console.error('[Updater] Kein SHA-256-Checksum-Wert gefunden. Update wurde aus Sicherheitsgruenden blockiert.'); + this.emitUpdateError('Update blockiert: Keine gueltige SHA-256 Checksumme gefunden.', { + phase: 'download', + reason: 'checksum-missing' + }); return; } @@ -242,6 +284,10 @@ class Updater { if (!this.isTrustedDownloadUrl(url)) { console.error('[Updater] Unsicherer Redirect/Download blockiert.'); fs.unlink(tempPath, () => {}); + this.emitUpdateError('Update blockiert: Unsicherer Redirect oder Download-Host.', { + phase: 'download', + reason: 'untrusted-redirect' + }); return; } @@ -253,6 +299,11 @@ class Updater { if (res.statusCode !== 200) { console.error(`[Updater] Download-Fehler: Status ${res.statusCode}`); + this.emitUpdateError(`Update-Download fehlgeschlagen: HTTP ${res.statusCode}.`, { + phase: 'download', + reason: 'http-error', + statusCode: res.statusCode + }); return; } @@ -265,11 +316,20 @@ class Updater { if (actualSha256 !== expectedSha256) { console.error('[Updater] Checksum-Validierung fehlgeschlagen. Installation wurde blockiert.'); fs.unlink(tempPath, () => {}); + this.emitUpdateError('Update blockiert: Checksum-Validierung fehlgeschlagen.', { + phase: 'download', + reason: 'checksum-mismatch' + }); return; } } catch (verifyErr) { console.error('[Updater] Checksum-Validierung konnte nicht ausgeführt werden:', verifyErr?.message || verifyErr); fs.unlink(tempPath, () => {}); + this.emitUpdateError('Update-Download fehlgeschlagen: Checksum-Validierung nicht moeglich.', { + phase: 'download', + reason: 'checksum-verify-failed', + error: String(verifyErr?.message || verifyErr) + }); return; } @@ -279,6 +339,11 @@ class Updater { }).on('error', (err) => { fs.unlink(tempPath, () => {}); console.error("[Updater] Netzwerkfehler beim Download:", err); + this.emitUpdateError('Update-Download fehlgeschlagen: Netzwerkfehler.', { + phase: 'download', + reason: 'network-error', + error: String(err?.message || err) + }); }); };