Skip to content

Commit 9dc4439

Browse files
committed
Fix auto-updater GitHub latest tag lookup
1 parent 96a8239 commit 9dc4439

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

electron/main.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import path from 'path';
66
import fs from 'fs/promises';
77
import { createReadStream, createWriteStream } from 'fs';
88
import { autoUpdater } from 'electron-updater';
9+
import { GitHubProvider } from 'electron-updater/out/providers/GitHubProvider';
910
import { databaseService } from './database';
1011
import { pythonManager } from './pythonManager';
1112
import log from 'electron-log/main';
@@ -61,6 +62,38 @@ const broadcastPythonEvent = (channel: string, payload: any) => {
6162
pythonManager.events.on('run-log', (payload) => broadcastPythonEvent('python:run-log', payload));
6263
pythonManager.events.on('run-status', (payload) => broadcastPythonEvent('python:run-status', payload));
6364

65+
// Work around GitHub returning HTTP 406 for JSON-only requests to the
66+
// `/releases/latest` endpoint by attempting to resolve the latest tag via the
67+
// REST API before falling back to the default behaviour implemented by
68+
// electron-updater. This avoids the auto-update check failing on startup.
69+
const originalGetLatestTagName = GitHubProvider.prototype.getLatestTagName;
70+
GitHubProvider.prototype.getLatestTagName = async function (this: GitHubProvider, cancellationToken) {
71+
const { owner, repo } = this.options;
72+
const apiUrl = new URL(`/repos/${owner}/${repo}/releases/latest`, 'https://api.github.com');
73+
74+
try {
75+
const rawResponse = await this.httpRequest(
76+
apiUrl,
77+
{
78+
Accept: 'application/vnd.github+json',
79+
'User-Agent': 'docforge-auto-updater'
80+
},
81+
cancellationToken
82+
);
83+
84+
if (rawResponse) {
85+
const parsed = JSON.parse(rawResponse) as { tag_name?: string };
86+
if (parsed.tag_name) {
87+
return parsed.tag_name;
88+
}
89+
}
90+
} catch (error) {
91+
console.warn('Failed to resolve latest release tag via GitHub API, falling back to default behaviour.', error);
92+
}
93+
94+
return originalGetLatestTagName.call(this, cancellationToken);
95+
};
96+
6497
// --- Auto Updater Setup ---
6598
// Note: For auto-updates to work, you need to configure `electron-builder` in package.json
6699
// and sign your application.

0 commit comments

Comments
 (0)