Point desktop updates at the Gitea release feed
The updater now resolves the newest non-draft desktop-v* release through the Gitea API at check time (J621_UPDATE_REPO, lowercase because the API path is case-sensitive), picks the platform's latest*.yml asset and uses that release as a generic electron-updater feed; J621_UPDATE_URL still overrides everything. Verified against the live API: release picked, yml fetched, artifact HEAD 200. electron-builder's publish.url is now metadata only (still needed so the build emits latest*.yml). Docs updated: CD release assets are the feed, the website /desktop/ feed only matters for installs before 0.1.2.
This commit is contained in:
+82
-4
@@ -238,8 +238,9 @@ function isDownloadNavigation(url: URL): boolean {
|
||||
/**
|
||||
* Updates are manual by design: Linux packages install through pacman/dpkg
|
||||
* (pkexec/sudo) and the Windows build is unsigned, so the app asks before
|
||||
* downloading and again before installing. The feed comes from `publish` in
|
||||
* electron-builder.yml and can be overridden with J621_UPDATE_URL.
|
||||
* downloading and again before installing. The feed is resolved at check time
|
||||
* from the newest `desktop-v*` release on Gitea (`J621_UPDATE_REPO`);
|
||||
* `J621_UPDATE_URL` overrides it for forks and the smoke test.
|
||||
*/
|
||||
type UpdateEvent =
|
||||
| { state: "available"; version: string }
|
||||
@@ -250,9 +251,84 @@ type UpdateEvent =
|
||||
let updateReporter: ((event: UpdateEvent) => void) | null = null;
|
||||
let updateCheckRunning = false;
|
||||
|
||||
function setUpUpdates(win: BrowserWindow): void {
|
||||
const UPDATE_REPO =
|
||||
process.env.J621_UPDATE_REPO?.trim() ||
|
||||
"https://gitea.rainbow-herring.ts.net/jakebreath/j621";
|
||||
|
||||
interface ReleaseAsset {
|
||||
name: string;
|
||||
browser_download_url: string;
|
||||
}
|
||||
|
||||
interface Release {
|
||||
tag_name: string;
|
||||
draft: boolean;
|
||||
prerelease: boolean;
|
||||
assets?: ReleaseAsset[];
|
||||
}
|
||||
|
||||
function releaseVersion(tag: string): [number, number, number] | null {
|
||||
const match = /^desktop-v(\d+)\.(\d+)\.(\d+)$/.exec(tag);
|
||||
if (!match) return null;
|
||||
return [Number(match[1]), Number(match[2]), Number(match[3])];
|
||||
}
|
||||
|
||||
function compareVersions(
|
||||
a: [number, number, number],
|
||||
b: [number, number, number],
|
||||
): number {
|
||||
for (let index = 0; index < 3; index += 1) {
|
||||
if (a[index] !== b[index]) return a[index] - b[index];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the generic feed base electron-updater should use.
|
||||
*
|
||||
* Gitea's API path is case-sensitive (owner/repo must match the login), while
|
||||
* the asset URLs it returns are canonical, so the base is derived from the
|
||||
* platform's metadata asset (`latest-linux.yml` / `latest.yml`).
|
||||
*/
|
||||
async function resolveReleaseFeed(): Promise<string> {
|
||||
const override = process.env.J621_UPDATE_URL?.trim();
|
||||
if (override) autoUpdater.setFeedURL({ provider: "generic", url: override });
|
||||
if (override) return override;
|
||||
const match = /^(https?:\/\/[^/]+)\/([^/]+)\/([^/]+?)\/?$/.exec(UPDATE_REPO);
|
||||
if (!match) {
|
||||
throw new Error(
|
||||
`J621_UPDATE_REPO must be <origin>/<owner>/<repo> (got ${UPDATE_REPO}).`,
|
||||
);
|
||||
}
|
||||
const [, origin, owner, repo] = match;
|
||||
const response = await fetch(
|
||||
`${origin}/api/v1/repos/${owner}/${repo}/releases?limit=50`,
|
||||
{ headers: { Accept: "application/json" } },
|
||||
);
|
||||
if (!response.ok) {
|
||||
throw new Error(`Release lookup on Gitea failed (HTTP ${response.status}).`);
|
||||
}
|
||||
const releases = (await response.json()) as Release[];
|
||||
const assetName =
|
||||
process.platform === "win32" ? "latest.yml" : "latest-linux.yml";
|
||||
let best: { version: [number, number, number]; asset: ReleaseAsset } | null =
|
||||
null;
|
||||
for (const release of releases) {
|
||||
if (release.draft || release.prerelease) continue;
|
||||
const version = releaseVersion(release.tag_name);
|
||||
if (!version) continue;
|
||||
const asset = release.assets?.find((entry) => entry.name === assetName);
|
||||
if (!asset) continue;
|
||||
if (!best || compareVersions(version, best.version) > 0) {
|
||||
best = { version, asset };
|
||||
}
|
||||
}
|
||||
if (!best) {
|
||||
throw new Error(`No ${assetName} asset found in ${UPDATE_REPO} releases.`);
|
||||
}
|
||||
return best.asset.browser_download_url.replace(/\/[^/]*$/, "");
|
||||
}
|
||||
|
||||
function setUpUpdates(win: BrowserWindow): void {
|
||||
if (!app.isPackaged) autoUpdater.forceDevUpdateConfig = true;
|
||||
autoUpdater.autoDownload = false;
|
||||
autoUpdater.autoInstallOnAppQuit = false;
|
||||
@@ -336,6 +412,8 @@ async function checkForUpdates(win: BrowserWindow): Promise<void> {
|
||||
if (updateCheckRunning) return;
|
||||
updateCheckRunning = true;
|
||||
try {
|
||||
const feed = await resolveReleaseFeed();
|
||||
autoUpdater.setFeedURL({ provider: "generic", url: feed });
|
||||
await autoUpdater.checkForUpdates();
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.message : String(error);
|
||||
|
||||
Reference in New Issue
Block a user