Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 17 additions & 11 deletions apps/desktop/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -700,12 +700,15 @@ function dispatchMenuAction(action: string): void {
}

function handleCheckForUpdatesMenuClick(): void {
const hasUpdateFeedConfig =
readAppUpdateYml() !== null || Boolean(process.env.T3CODE_DESKTOP_MOCK_UPDATES);
const disabledReason = getAutoUpdateDisabledReason({
isDevelopment,
isPackaged: app.isPackaged,
platform: process.platform,
appImage: process.env.APPIMAGE,
disabledByEnv: process.env.T3CODE_DISABLE_AUTO_UPDATE === "1",
hasUpdateFeedConfig,
});
if (disabledReason) {
console.info("[desktop-updater] Manual update check requested, but updates are disabled.");
Expand Down Expand Up @@ -942,13 +945,16 @@ function setUpdateState(patch: Partial<DesktopUpdateState>): void {
}

function shouldEnableAutoUpdates(): boolean {
const hasUpdateFeedConfig =
readAppUpdateYml() !== null || Boolean(process.env.T3CODE_DESKTOP_MOCK_UPDATES);
return (
getAutoUpdateDisabledReason({
isDevelopment,
isPackaged: app.isPackaged,
platform: process.platform,
appImage: process.env.APPIMAGE,
disabledByEnv: process.env.T3CODE_DISABLE_AUTO_UPDATE === "1",
hasUpdateFeedConfig,
}) === null
);
}
Expand Down Expand Up @@ -1032,17 +1038,6 @@ async function installDownloadedUpdate(): Promise<{ accepted: boolean; completed
}

function configureAutoUpdater(): void {
const enabled = shouldEnableAutoUpdates();
setUpdateState({
...createInitialDesktopUpdateState(app.getVersion(), desktopRuntimeInfo),
enabled,
status: enabled ? "idle" : "disabled",
});
if (!enabled) {
return;
}
updaterConfigured = true;

const githubToken =
process.env.T3CODE_DESKTOP_UPDATE_GITHUB_TOKEN?.trim() || process.env.GH_TOKEN?.trim() || "";
if (githubToken) {
Expand All @@ -1067,6 +1062,17 @@ function configureAutoUpdater(): void {
});
}

const enabled = shouldEnableAutoUpdates();
setUpdateState({
...createInitialDesktopUpdateState(app.getVersion(), desktopRuntimeInfo),
enabled,
status: enabled ? "idle" : "disabled",
});
if (!enabled) {
return;
}
updaterConfigured = true;

autoUpdater.autoDownload = false;
autoUpdater.autoInstallOnAppQuit = false;
// Keep alpha branding, but force all installs onto the stable update track.
Expand Down
29 changes: 29 additions & 0 deletions apps/desktop/src/updateState.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,37 @@ describe("getAutoUpdateDisabledReason", () => {
platform: "darwin",
appImage: undefined,
disabledByEnv: false,
hasUpdateFeedConfig: true,
}),
).toContain("packaged production builds");
});

it("reports packaged local builds without an update feed as disabled", () => {
expect(
getAutoUpdateDisabledReason({
isDevelopment: false,
isPackaged: true,
platform: "darwin",
appImage: undefined,
disabledByEnv: false,
hasUpdateFeedConfig: false,
}),
).toContain("no update feed");
});

it("allows packaged builds with an update feed", () => {
expect(
getAutoUpdateDisabledReason({
isDevelopment: false,
isPackaged: true,
platform: "darwin",
appImage: undefined,
disabledByEnv: false,
hasUpdateFeedConfig: true,
}),
).toBeNull();
});

it("reports env-disabled auto updates", () => {
expect(
getAutoUpdateDisabledReason({
Expand All @@ -83,6 +110,7 @@ describe("getAutoUpdateDisabledReason", () => {
platform: "darwin",
appImage: undefined,
disabledByEnv: true,
hasUpdateFeedConfig: true,
}),
).toContain("T3CODE_DISABLE_AUTO_UPDATE");
});
Expand All @@ -95,6 +123,7 @@ describe("getAutoUpdateDisabledReason", () => {
platform: "linux",
appImage: undefined,
disabledByEnv: false,
hasUpdateFeedConfig: true,
}),
).toContain("AppImage");
});
Expand Down
4 changes: 4 additions & 0 deletions apps/desktop/src/updateState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ export function getAutoUpdateDisabledReason(args: {
platform: NodeJS.Platform;
appImage?: string | undefined;
disabledByEnv: boolean;
hasUpdateFeedConfig: boolean;
}): string | null {
if (!args.hasUpdateFeedConfig) {
return "Automatic updates are not available because no update feed is configured.";
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feed URL check precedes more fundamental dev/packaged checks

Medium Severity

The hasFeedURL check is ordered before the isDevelopment and isPackaged checks. This causes development and unpackaged builds, which typically lack a feed URL, to display the less accurate "no update feed URL is configured" message instead of "only available in packaged production builds." Tests currently mask this behavior.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 6763cb6. Configure here.

if (args.isDevelopment || !args.isPackaged) {
return "Automatic updates are only available in packaged production builds.";
}
Expand Down
Loading