Upload via Git Manager GUI

This commit is contained in:
Git Manager GUI
2026-05-07 22:16:17 +02:00
parent 781820d5a1
commit 8bf7f47186

View File

@@ -15,6 +15,22 @@ class Updater {
this.checkingForUpdates = false; 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 * Hauptfunktion zur Prüfung auf Updates
*/ */
@@ -58,6 +74,11 @@ class Updater {
} }
} catch (error) { } catch (error) {
console.error('[Updater] Fehler beim Update-Check:', error); console.error('[Updater] Fehler beim Update-Check:', error);
this.emitUpdateError('Update-Pruefung fehlgeschlagen.', {
phase: 'check',
silent: !!silent,
error: String(error?.message || error)
});
} finally { } finally {
this.checkingForUpdates = false; this.checkingForUpdates = false;
} }
@@ -67,6 +88,10 @@ class Updater {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const options = { headers: { 'User-Agent': 'GitManager-GUI-Updater' } }; const options = { headers: { 'User-Agent': 'GitManager-GUI-Updater' } };
https.get(GITEA_API_URL, options, (res) => { https.get(GITEA_API_URL, options, (res) => {
if (res.statusCode !== 200) {
reject(new Error(`Release-API antwortete mit HTTP ${res.statusCode}`));
return;
}
let data = ''; let data = '';
res.on('data', chunk => data += chunk); res.on('data', chunk => data += chunk);
res.on('end', () => { res.on('end', () => {
@@ -212,11 +237,19 @@ class Updater {
async startDownload(asset) { async startDownload(asset) {
if (!asset || !asset.browser_download_url) { if (!asset || !asset.browser_download_url) {
console.error("[Updater] Kein gültiges Asset gefunden!"); console.error("[Updater] Kein gültiges Asset gefunden!");
this.emitUpdateError('Update-Download fehlgeschlagen: Kein gueltiges Installer-Asset gefunden.', {
phase: 'download',
reason: 'invalid-asset'
});
return; return;
} }
if (!this.isTrustedDownloadUrl(asset.browser_download_url)) { if (!this.isTrustedDownloadUrl(asset.browser_download_url)) {
console.error('[Updater] Unsichere Download-URL blockiert.'); console.error('[Updater] Unsichere Download-URL blockiert.');
this.emitUpdateError('Update blockiert: Unsichere Download-URL.', {
phase: 'download',
reason: 'untrusted-download-url'
});
return; return;
} }
@@ -228,11 +261,20 @@ class Updater {
expectedSha256 = await this.resolveExpectedSha256(asset); expectedSha256 = await this.resolveExpectedSha256(asset);
} catch (e) { } catch (e) {
console.error('[Updater] Konnte erwartete Checksumme nicht laden:', e?.message || 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; return;
} }
if (!expectedSha256) { if (!expectedSha256) {
console.error('[Updater] Kein SHA-256-Checksum-Wert gefunden. Update wurde aus Sicherheitsgruenden blockiert.'); 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; return;
} }
@@ -242,6 +284,10 @@ class Updater {
if (!this.isTrustedDownloadUrl(url)) { if (!this.isTrustedDownloadUrl(url)) {
console.error('[Updater] Unsicherer Redirect/Download blockiert.'); console.error('[Updater] Unsicherer Redirect/Download blockiert.');
fs.unlink(tempPath, () => {}); fs.unlink(tempPath, () => {});
this.emitUpdateError('Update blockiert: Unsicherer Redirect oder Download-Host.', {
phase: 'download',
reason: 'untrusted-redirect'
});
return; return;
} }
@@ -253,6 +299,11 @@ class Updater {
if (res.statusCode !== 200) { if (res.statusCode !== 200) {
console.error(`[Updater] Download-Fehler: Status ${res.statusCode}`); 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; return;
} }
@@ -265,11 +316,20 @@ class Updater {
if (actualSha256 !== expectedSha256) { if (actualSha256 !== expectedSha256) {
console.error('[Updater] Checksum-Validierung fehlgeschlagen. Installation wurde blockiert.'); console.error('[Updater] Checksum-Validierung fehlgeschlagen. Installation wurde blockiert.');
fs.unlink(tempPath, () => {}); fs.unlink(tempPath, () => {});
this.emitUpdateError('Update blockiert: Checksum-Validierung fehlgeschlagen.', {
phase: 'download',
reason: 'checksum-mismatch'
});
return; return;
} }
} catch (verifyErr) { } catch (verifyErr) {
console.error('[Updater] Checksum-Validierung konnte nicht ausgeführt werden:', verifyErr?.message || verifyErr); console.error('[Updater] Checksum-Validierung konnte nicht ausgeführt werden:', verifyErr?.message || verifyErr);
fs.unlink(tempPath, () => {}); fs.unlink(tempPath, () => {});
this.emitUpdateError('Update-Download fehlgeschlagen: Checksum-Validierung nicht moeglich.', {
phase: 'download',
reason: 'checksum-verify-failed',
error: String(verifyErr?.message || verifyErr)
});
return; return;
} }
@@ -279,6 +339,11 @@ class Updater {
}).on('error', (err) => { }).on('error', (err) => {
fs.unlink(tempPath, () => {}); fs.unlink(tempPath, () => {});
console.error("[Updater] Netzwerkfehler beim Download:", err); console.error("[Updater] Netzwerkfehler beim Download:", err);
this.emitUpdateError('Update-Download fehlgeschlagen: Netzwerkfehler.', {
phase: 'download',
reason: 'network-error',
error: String(err?.message || err)
});
}); });
}; };