Skip to content

Commit 5d9eb18

Browse files
fix: don't let un-updateable builds check for an update (#1808)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
1 parent abb84c0 commit 5d9eb18

3 files changed

Lines changed: 50 additions & 11 deletions

File tree

apps/desktop/src/main.ts

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -700,12 +700,15 @@ function dispatchMenuAction(action: string): void {
700700
}
701701

702702
function handleCheckForUpdatesMenuClick(): void {
703+
const hasUpdateFeedConfig =
704+
readAppUpdateYml() !== null || Boolean(process.env.T3CODE_DESKTOP_MOCK_UPDATES);
703705
const disabledReason = getAutoUpdateDisabledReason({
704706
isDevelopment,
705707
isPackaged: app.isPackaged,
706708
platform: process.platform,
707709
appImage: process.env.APPIMAGE,
708710
disabledByEnv: process.env.T3CODE_DISABLE_AUTO_UPDATE === "1",
711+
hasUpdateFeedConfig,
709712
});
710713
if (disabledReason) {
711714
console.info("[desktop-updater] Manual update check requested, but updates are disabled.");
@@ -942,13 +945,16 @@ function setUpdateState(patch: Partial<DesktopUpdateState>): void {
942945
}
943946

944947
function shouldEnableAutoUpdates(): boolean {
948+
const hasUpdateFeedConfig =
949+
readAppUpdateYml() !== null || Boolean(process.env.T3CODE_DESKTOP_MOCK_UPDATES);
945950
return (
946951
getAutoUpdateDisabledReason({
947952
isDevelopment,
948953
isPackaged: app.isPackaged,
949954
platform: process.platform,
950955
appImage: process.env.APPIMAGE,
951956
disabledByEnv: process.env.T3CODE_DISABLE_AUTO_UPDATE === "1",
957+
hasUpdateFeedConfig,
952958
}) === null
953959
);
954960
}
@@ -1032,17 +1038,6 @@ async function installDownloadedUpdate(): Promise<{ accepted: boolean; completed
10321038
}
10331039

10341040
function configureAutoUpdater(): void {
1035-
const enabled = shouldEnableAutoUpdates();
1036-
setUpdateState({
1037-
...createInitialDesktopUpdateState(app.getVersion(), desktopRuntimeInfo),
1038-
enabled,
1039-
status: enabled ? "idle" : "disabled",
1040-
});
1041-
if (!enabled) {
1042-
return;
1043-
}
1044-
updaterConfigured = true;
1045-
10461041
const githubToken =
10471042
process.env.T3CODE_DESKTOP_UPDATE_GITHUB_TOKEN?.trim() || process.env.GH_TOKEN?.trim() || "";
10481043
if (githubToken) {
@@ -1067,6 +1062,17 @@ function configureAutoUpdater(): void {
10671062
});
10681063
}
10691064

1065+
const enabled = shouldEnableAutoUpdates();
1066+
setUpdateState({
1067+
...createInitialDesktopUpdateState(app.getVersion(), desktopRuntimeInfo),
1068+
enabled,
1069+
status: enabled ? "idle" : "disabled",
1070+
});
1071+
if (!enabled) {
1072+
return;
1073+
}
1074+
updaterConfigured = true;
1075+
10701076
autoUpdater.autoDownload = false;
10711077
autoUpdater.autoInstallOnAppQuit = false;
10721078
// Keep alpha branding, but force all installs onto the stable update track.

apps/desktop/src/updateState.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,37 @@ describe("getAutoUpdateDisabledReason", () => {
7171
platform: "darwin",
7272
appImage: undefined,
7373
disabledByEnv: false,
74+
hasUpdateFeedConfig: true,
7475
}),
7576
).toContain("packaged production builds");
7677
});
7778

79+
it("reports packaged local builds without an update feed as disabled", () => {
80+
expect(
81+
getAutoUpdateDisabledReason({
82+
isDevelopment: false,
83+
isPackaged: true,
84+
platform: "darwin",
85+
appImage: undefined,
86+
disabledByEnv: false,
87+
hasUpdateFeedConfig: false,
88+
}),
89+
).toContain("no update feed");
90+
});
91+
92+
it("allows packaged builds with an update feed", () => {
93+
expect(
94+
getAutoUpdateDisabledReason({
95+
isDevelopment: false,
96+
isPackaged: true,
97+
platform: "darwin",
98+
appImage: undefined,
99+
disabledByEnv: false,
100+
hasUpdateFeedConfig: true,
101+
}),
102+
).toBeNull();
103+
});
104+
78105
it("reports env-disabled auto updates", () => {
79106
expect(
80107
getAutoUpdateDisabledReason({
@@ -83,6 +110,7 @@ describe("getAutoUpdateDisabledReason", () => {
83110
platform: "darwin",
84111
appImage: undefined,
85112
disabledByEnv: true,
113+
hasUpdateFeedConfig: true,
86114
}),
87115
).toContain("T3CODE_DISABLE_AUTO_UPDATE");
88116
});
@@ -95,6 +123,7 @@ describe("getAutoUpdateDisabledReason", () => {
95123
platform: "linux",
96124
appImage: undefined,
97125
disabledByEnv: false,
126+
hasUpdateFeedConfig: true,
98127
}),
99128
).toContain("AppImage");
100129
});

apps/desktop/src/updateState.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ export function getAutoUpdateDisabledReason(args: {
3434
platform: NodeJS.Platform;
3535
appImage?: string | undefined;
3636
disabledByEnv: boolean;
37+
hasUpdateFeedConfig: boolean;
3738
}): string | null {
39+
if (!args.hasUpdateFeedConfig) {
40+
return "Automatic updates are not available because no update feed is configured.";
41+
}
3842
if (args.isDevelopment || !args.isPackaged) {
3943
return "Automatic updates are only available in packaged production builds.";
4044
}

0 commit comments

Comments
 (0)