Skip to content

Commit cc7d40e

Browse files
committed
fix(web): follow configured desktop update repository
1 parent 9c16146 commit cc7d40e

4 files changed

Lines changed: 44 additions & 9 deletions

File tree

‎apps/web/src/components/desktopUpdate.logic.test.ts‎

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,13 +201,28 @@ describe("getDesktopUpdateActionError", () => {
201201

202202
describe("desktop update UI helpers", () => {
203203
it("builds the stable release URL for a downloaded version", () => {
204-
expect(getDesktopUpdateReleaseUrl("0.0.30")).toBe(
204+
expect(getDesktopUpdateReleaseUrl("0.0.30", "pingdotgg/t3code")).toBe(
205205
"https://github.com/pingdotgg/t3code/releases/tag/v0.0.30",
206206
);
207207
});
208208

209+
it("uses the configured desktop update repository for release URLs", () => {
210+
expect(getDesktopUpdateReleaseUrl("1.2.3", "JustYannicc/t3code")).toBe(
211+
"https://github.com/JustYannicc/t3code/releases/tag/v1.2.3",
212+
);
213+
expect(getDesktopUpdateReleaseHistoryUrl("JustYannicc/t3code")).toBe(
214+
"https://github.com/JustYannicc/t3code/releases",
215+
);
216+
});
217+
218+
it("falls back to the upstream repository for an invalid configured repository", () => {
219+
expect(getDesktopUpdateReleaseHistoryUrl("owner/repo/extra")).toBe(
220+
"https://github.com/pingdotgg/t3code/releases",
221+
);
222+
});
223+
209224
it("builds the nightly release URL without dropping its version suffix", () => {
210-
expect(getDesktopUpdateReleaseUrl("0.0.30-nightly.20260728.931")).toBe(
225+
expect(getDesktopUpdateReleaseUrl("0.0.30-nightly.20260728.931", "pingdotgg/t3code")).toBe(
211226
"https://github.com/pingdotgg/t3code/releases/tag/v0.0.30-nightly.20260728.931",
212227
);
213228
});
@@ -218,7 +233,7 @@ describe("desktop update UI helpers", () => {
218233
});
219234

220235
it("builds the release history URL", () => {
221-
expect(getDesktopUpdateReleaseHistoryUrl()).toBe(
236+
expect(getDesktopUpdateReleaseHistoryUrl("pingdotgg/t3code")).toBe(
222237
"https://github.com/pingdotgg/t3code/releases",
223238
);
224239
});

‎apps/web/src/components/desktopUpdate.logic.ts‎

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,15 @@ import type { DesktopUpdateActionResult, DesktopUpdateState } from "@t3tools/con
22

33
export type DesktopUpdateButtonAction = "download" | "install" | "none";
44

5-
const DESKTOP_RELEASE_HISTORY_URL = "https://github.com/pingdotgg/t3code/releases";
6-
const DESKTOP_RELEASE_TAG_URL = `${DESKTOP_RELEASE_HISTORY_URL}/tag`;
5+
const DEFAULT_DESKTOP_RELEASE_REPOSITORY = "pingdotgg/t3code";
6+
7+
function desktopReleaseRepositoryUrl(repository: string | undefined): string {
8+
const configuredRepository = repository?.trim() ?? "";
9+
const [owner, name, ...extra] = configuredRepository.split("/");
10+
const releaseRepository =
11+
owner && name && extra.length === 0 ? configuredRepository : DEFAULT_DESKTOP_RELEASE_REPOSITORY;
12+
return `https://github.com/${releaseRepository}/releases`;
13+
}
714

815
/**
916
* The main process fills `downloadedVersion` from the updater's `update-downloaded`
@@ -14,14 +21,19 @@ export function getDesktopUpdateDownloadedVersion(state: DesktopUpdateState): st
1421
return state.downloadedVersion ?? state.availableVersion;
1522
}
1623

17-
export function getDesktopUpdateReleaseUrl(version: string | null): string | null {
24+
export function getDesktopUpdateReleaseUrl(
25+
version: string | null,
26+
repository: string | undefined = import.meta.env.T3CODE_DESKTOP_UPDATE_REPOSITORY,
27+
): string | null {
1828
const normalizedVersion = version?.trim();
1929
if (!normalizedVersion) return null;
20-
return `${DESKTOP_RELEASE_TAG_URL}/v${encodeURIComponent(normalizedVersion)}`;
30+
return `${desktopReleaseRepositoryUrl(repository)}/tag/v${encodeURIComponent(normalizedVersion)}`;
2131
}
2232

23-
export function getDesktopUpdateReleaseHistoryUrl(): string {
24-
return DESKTOP_RELEASE_HISTORY_URL;
33+
export function getDesktopUpdateReleaseHistoryUrl(
34+
repository: string | undefined = import.meta.env.T3CODE_DESKTOP_UPDATE_REPOSITORY,
35+
): string {
36+
return desktopReleaseRepositoryUrl(repository);
2537
}
2638

2739
export function resolveDesktopUpdateButtonAction(

‎apps/web/src/vite-env.d.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ interface ImportMetaEnv {
1313
readonly VITE_RELAY_OTLP_TRACES_URL: string;
1414
readonly VITE_RELAY_OTLP_TRACES_DATASET: string;
1515
readonly VITE_RELAY_OTLP_TRACES_TOKEN: string;
16+
readonly T3CODE_DESKTOP_UPDATE_REPOSITORY: string;
1617
readonly APP_VERSION: string;
1718
}
1819

‎apps/web/vite.config.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ const configuredRelayTracingDataset = repoEnv.VITE_RELAY_OTLP_TRACES_DATASET?.tr
4242
const configuredRelayTracingToken = repoEnv.VITE_RELAY_OTLP_TRACES_TOKEN?.trim() || "";
4343
const configuredHostedAppChannel = process.env.VITE_HOSTED_APP_CHANNEL?.trim() || "";
4444
const configuredAppVersion = process.env.APP_VERSION?.trim() || pkg.version;
45+
const configuredDesktopUpdateRepository =
46+
process.env.T3CODE_DESKTOP_UPDATE_REPOSITORY?.trim() ||
47+
process.env.GITHUB_REPOSITORY?.trim() ||
48+
"";
4549
const configuredHostedAppUrl = (() => {
4650
const explicitHostedAppUrl = process.env.VITE_HOSTED_APP_URL?.trim();
4751
if (explicitHostedAppUrl) {
@@ -215,6 +219,9 @@ export default defineConfig(() => {
215219
"import.meta.env.VITE_RELAY_OTLP_TRACES_TOKEN": JSON.stringify(configuredRelayTracingToken),
216220
"import.meta.env.VITE_HOSTED_APP_URL": JSON.stringify(configuredHostedAppUrl ?? ""),
217221
"import.meta.env.VITE_HOSTED_APP_CHANNEL": JSON.stringify(configuredHostedAppChannel),
222+
"import.meta.env.T3CODE_DESKTOP_UPDATE_REPOSITORY": JSON.stringify(
223+
configuredDesktopUpdateRepository,
224+
),
218225
"import.meta.env.APP_VERSION": JSON.stringify(configuredAppVersion),
219226
},
220227
resolve: {

0 commit comments

Comments
 (0)