Skip to content
TypeScript

fix(web): Connections no longer says "Up to date" while a desktop update is pending (#14790)

Igor Makowskicd2b885b77d3
diff --git a/apps/web/src/components/settings/ConnectionsSettings.logic.test.ts b/apps/web/src/components/settings/ConnectionsSettings.logic.test.ts
index 82037ae1db7..82d1fb7bb83 100644
--- a/apps/web/src/components/settings/ConnectionsSettings.logic.test.ts
+++ b/apps/web/src/components/settings/ConnectionsSettings.logic.test.ts
@@ -1,4 +1,4 @@
-import type { AdvertisedEndpoint, DesktopWslState } from "@t3tools/contracts";
+import type { AdvertisedEndpoint, DesktopUpdateState, DesktopWslState } from "@t3tools/contracts";
import { describe, expect, it, vi } from "vite-plus/test";
import {
applyWslEnableSelection,
@@ -6,6 +6,7 @@ import {
isQrShareableEndpoint,
isWslSettingsRowVisible,
missingTailscaleEndpointDescription,
+ resolveLocalVersionStatusLabel,
selectQrEndpointOption,
togglePairingScopeSelection,
} from "./ConnectionsSettings.logic";
@@ -54,6 +55,63 @@ const baseWslState: DesktopWslState = {
preflightError: null,
};
+describe("resolveLocalVersionStatusLabel", () => {
+ const baseState: DesktopUpdateState = {
+ enabled: true,
+ status: "idle",
+ channel: "latest",
+ currentVersion: "1.0.0",
+ hostArch: "x64",
+ appArch: "x64",
+ runningUnderArm64Translation: false,
+ availableVersion: null,
+ downloadedVersion: null,
+ releaseNotes: [],
+ omittedReleaseCount: 0,
+ downloadPercent: null,
+ checkedAt: null,
+ message: null,
+ errorContext: null,
+ canRetry: false,
+ };
+
+ it("stays up to date on the web and when the desktop updater has nothing pending", () => {
+ expect(resolveLocalVersionStatusLabel(null)).toBe("Up to date");
+ expect(resolveLocalVersionStatusLabel(baseState)).toBe("Up to date");
+ });
+
+ it.each<[string, Partial<DesktopUpdateState>, string]>([
+ ["available", { status: "available", availableVersion: "1.2.0" }, "Update 1.2.0 available"],
+ [
+ "downloading",
+ { status: "downloading", availableVersion: "1.2.0" },
+ "Downloading update 1.2.0",
+ ],
+ [
+ "downloaded",
+ { status: "downloaded", availableVersion: "1.2.0", downloadedVersion: "1.1.0" },
+ "Update 1.1.0 downloaded",
+ ],
+ [
+ "a failed download that can be retried",
+ { status: "error", errorContext: "download", availableVersion: "1.2.0", canRetry: true },
+ "Update 1.2.0 available",
+ ],
+ [
+ "a failed install",
+ { status: "error", errorContext: "install", downloadedVersion: "1.1.0" },
+ "Update 1.1.0 downloaded",
+ ],
+ [
+ "a recheck that keeps a downloaded update",
+ { status: "checking", downloadedVersion: "1.1.0" },
+ "Update 1.1.0 downloaded",
+ ],
+ ])("names the pending update for %s", (_, state, label) => {
+ expect(resolveLocalVersionStatusLabel({ ...baseState, ...state })).toBe(label);
+ });
+});
+
describe("isWslSettingsRowVisible", () => {
it("shows the retry row when the WSL state failed to load", () => {
expect(isWslSettingsRowVisible({ state: null, error: "load failed" })).toBe(true);
diff --git a/apps/web/src/components/settings/ConnectionsSettings.logic.ts b/apps/web/src/components/settings/ConnectionsSettings.logic.ts
index b9b0f145dd6..9e9f5be1b91 100644
--- a/apps/web/src/components/settings/ConnectionsSettings.logic.ts
+++ b/apps/web/src/components/settings/ConnectionsSettings.logic.ts
@@ -5,8 +5,13 @@ import {
AuthTerminalReadScope,
type DesktopBridge,
type DesktopServerExposureState,
+ type DesktopUpdateState,
type DesktopWslState,
} from "@t3tools/contracts";
+import {
+ getDesktopUpdateDownloadedVersion,
+ resolveDesktopUpdateButtonAction,
+} from "../desktopUpdate.logic";
/**
* Operating terminals without being able to list them leaves a client
@@ -70,6 +75,38 @@ export function isWslSettingsRowVisible(input: {
return state ? state.available || state.enabled || state.wslOnly : error !== null;
}
+/**
+ * Passive label for this machine's Version row once client and server versions
+ * match. The desktop bundles its server, so a pending app update is the only
+ * way it falls behind. Pending states follow the sidebar update control's
+ * action, including retryable failures, so the two never disagree; the sidebar
+ * is where to act. A recheck keeps a downloaded update while `checking`, so it
+ * keeps its label too. `state` is null outside the desktop app.
+ */
+export function resolveLocalVersionStatusLabel(state: DesktopUpdateState | null): string {
+ if (!state) return "Up to date";
+ if (state.status === "downloading") {
+ return state.availableVersion
+ ? `Downloading update ${state.availableVersion}`
+ : "Downloading update";
+ }
+ const action = resolveDesktopUpdateButtonAction(state);
+ if (
+ action === "install" ||
+ state.status === "downloaded" ||
+ (state.status === "checking" && state.downloadedVersion !== null)
+ ) {
+ const version = getDesktopUpdateDownloadedVersion(state);
+ return version ? `Update ${version} downloaded` : "Update downloaded";
+ }
+ if (action === "download") {
+ return state.availableVersion
+ ? `Update ${state.availableVersion} available`
+ : "Update available";
+ }
+ return "Up to date";
+}
+
export type QrEndpointOption = {
readonly id: string;
/**
diff --git a/apps/web/src/components/settings/ConnectionsSettings.tsx b/apps/web/src/components/settings/ConnectionsSettings.tsx
index b984de57f76..ea577b2f1ac 100644
--- a/apps/web/src/components/settings/ConnectionsSettings.tsx
+++ b/apps/web/src/components/settings/ConnectionsSettings.tsx
@@ -71,6 +71,7 @@ import {
isQrShareableEndpoint,
isWslSettingsRowVisible,
missingTailscaleEndpointDescription,
+ resolveLocalVersionStatusLabel,
selectQrEndpointOption,
togglePairingScopeSelection,
} from "./ConnectionsSettings.logic";
@@ -176,6 +177,7 @@ import {
} from "~/state/desktopNetworkAccess";
import { desktopSshHostsStateAtom, filterDiscoveredSshHosts } from "~/state/desktopSshHosts";
import { desktopWslStateAtom, refreshDesktopWslState } from "~/state/desktopWslState";
+import { useDesktopUpdateState } from "~/state/desktopUpdate";
import {
type EnvironmentPresentation,
useEnvironments,
@@ -2003,6 +2005,16 @@ function CloudRemoteEnvironmentRows({
) : null;
}
+// Subscribes on its own so desktop download progress does not re-render the page.
+function LocalVersionStatusLabel() {
+ const updateState = useDesktopUpdateState();
+ return (
+ <span className="text-xs text-muted-foreground">
+ {resolveLocalVersionStatusLabel(updateState)}
+ </span>
+ );
+}
+
export function ConnectionsSettings() {
const desktopBridge = window.desktopBridge;
const keybindings = useAtomValue(primaryServerKeybindingsAtom);
@@ -3470,7 +3482,7 @@ export function ConnectionsSettings() {
}
/>
) : primaryServerUpdateState.status === "idle" && primaryServerConfig ? (
- <span className="text-xs text-muted-foreground">Up to date</span>
+ <LocalVersionStatusLabel />
) : undefined
}
/>