Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.
Update system overhaul (#1505)
shivamf82bae166802
diff --git a/apps/desktop/src/main.ts b/apps/desktop/src/main.tsindex 81a02d446..f1086e9c2 100644--- a/apps/desktop/src/main.ts+++ b/apps/desktop/src/main.ts@@ -20,6 +20,7 @@ import * as Effect from "effect/Effect";import type {DesktopTheme,DesktopUpdateActionResult,+ DesktopUpdateCheckResult,DesktopUpdateState,} from "@t3tools/contracts";import { autoUpdater } from "electron-updater";@@ -56,6 +57,7 @@ const UPDATE_STATE_CHANNEL = "desktop:update-state";const UPDATE_GET_STATE_CHANNEL = "desktop:update-get-state";const UPDATE_DOWNLOAD_CHANNEL = "desktop:update-download";const UPDATE_INSTALL_CHANNEL = "desktop:update-install";+const UPDATE_CHECK_CHANNEL = "desktop:update-check";const GET_WS_URL_CHANNEL = "desktop:get-ws-url";const BASE_DIR = process.env.T3CODE_HOME?.trim() || Path.join(OS.homedir(), ".t3");const STATE_DIR = Path.join(BASE_DIR, "userdata");@@ -756,13 +758,13 @@ function shouldEnableAutoUpdates(): boolean {);}-async function checkForUpdates(reason: string): Promise<void> {- if (isQuitting || !updaterConfigured || updateCheckInFlight) return;+async function checkForUpdates(reason: string): Promise<boolean> {+ if (isQuitting || !updaterConfigured || updateCheckInFlight) return false;if (updateState.status === "downloading" || updateState.status === "downloaded") {console.info(`[desktop-updater] Skipping update check (${reason}) while status=${updateState.status}.`,);- return;+ return false;}updateCheckInFlight = true;setUpdateState(reduceDesktopUpdateStateOnCheckStart(updateState, new Date().toISOString()));@@ -770,12 +772,14 @@ async function checkForUpdates(reason: string): Promise<void> {try {await autoUpdater.checkForUpdates();+ return true;} catch (error: unknown) {const message = error instanceof Error ? error.message : String(error);setUpdateState(reduceDesktopUpdateStateOnCheckFailure(updateState, message, new Date().toISOString()),);console.error(`[desktop-updater] Failed to check for updates: ${message}`);+ return true;} finally {updateCheckInFlight = false;}@@ -1263,6 +1267,21 @@ function registerIpcHandlers(): void {state: updateState,} satisfies DesktopUpdateActionResult;});++ ipcMain.removeHandler(UPDATE_CHECK_CHANNEL);+ ipcMain.handle(UPDATE_CHECK_CHANNEL, async () => {+ if (!updaterConfigured) {+ return {+ checked: false,+ state: updateState,+ } satisfies DesktopUpdateCheckResult;+ }+ const checked = await checkForUpdates("web-ui");+ return {+ checked,+ state: updateState,+ } satisfies DesktopUpdateCheckResult;+ });}function getIconOption(): { icon: string } | Record<string, never> {diff --git a/apps/desktop/src/preload.ts b/apps/desktop/src/preload.tsindex 2fb7e3a1d..3d59db171 100644--- a/apps/desktop/src/preload.ts+++ b/apps/desktop/src/preload.ts@@ -9,6 +9,7 @@ const OPEN_EXTERNAL_CHANNEL = "desktop:open-external";const MENU_ACTION_CHANNEL = "desktop:menu-action";const UPDATE_STATE_CHANNEL = "desktop:update-state";const UPDATE_GET_STATE_CHANNEL = "desktop:update-get-state";+const UPDATE_CHECK_CHANNEL = "desktop:update-check";const UPDATE_DOWNLOAD_CHANNEL = "desktop:update-download";const UPDATE_INSTALL_CHANNEL = "desktop:update-install";const GET_WS_URL_CHANNEL = "desktop:get-ws-url";@@ -35,6 +36,7 @@ contextBridge.exposeInMainWorld("desktopBridge", {};},getUpdateState: () => ipcRenderer.invoke(UPDATE_GET_STATE_CHANNEL),+ checkForUpdate: () => ipcRenderer.invoke(UPDATE_CHECK_CHANNEL),downloadUpdate: () => ipcRenderer.invoke(UPDATE_DOWNLOAD_CHANNEL),installUpdate: () => ipcRenderer.invoke(UPDATE_INSTALL_CHANNEL),onUpdateState: (listener) => {diff --git a/apps/web/src/components/Sidebar.tsx b/apps/web/src/components/Sidebar.tsxindex 89640ed5d..100d0e3f4 100644--- a/apps/web/src/components/Sidebar.tsx+++ b/apps/web/src/components/Sidebar.tsx@@ -5,7 +5,6 @@ import {FolderIcon,GitPullRequestIcon,PlusIcon,- RocketIcon,SettingsIcon,SquarePenIcon,TerminalIcon,@@ -78,12 +77,10 @@ import { SettingsSidebarNav } from "./settings/SettingsSidebarNav";import {getArm64IntelBuildWarningDescription,getDesktopUpdateActionError,- getDesktopUpdateButtonTooltip,+ getDesktopUpdateInstallConfirmationMessage,isDesktopUpdateButtonDisabled,resolveDesktopUpdateButtonAction,shouldShowArm64IntelBuildWarning,- shouldHighlightDesktopUpdateError,- shouldShowDesktopUpdateButton,shouldToastDesktopUpdateActionResult,} from "./desktopUpdate.logic";import { Alert, AlertAction, AlertDescription, AlertTitle } from "./ui/alert";@@ -120,6 +117,7 @@ import {sortProjectsForSidebar,sortThreadsForSidebar,} from "./Sidebar.logic";+import { SidebarUpdatePill } from "./sidebar/SidebarUpdatePill";import { useCopyToClipboard } from "~/hooks/useCopyToClipboard";import { useSettings, useUpdateSettings } from "~/hooks/useSettings";@@ -1661,12 +1659,6 @@ export default function Sidebar() {};}, []);- const showDesktopUpdateButton = isElectron && shouldShowDesktopUpdateButton(desktopUpdateState);-- const desktopUpdateTooltip = desktopUpdateState- ? getDesktopUpdateButtonTooltip(desktopUpdateState)- : "Update available";-const desktopUpdateButtonDisabled = isDesktopUpdateButtonDisabled(desktopUpdateState);const desktopUpdateButtonAction = desktopUpdateState? resolveDesktopUpdateButtonAction(desktopUpdateState)@@ -1677,17 +1669,6 @@ export default function Sidebar() {desktopUpdateState && showArm64IntelBuildWarning? getArm64IntelBuildWarningDescription(desktopUpdateState): null;- const desktopUpdateButtonInteractivityClasses = desktopUpdateButtonDisabled- ? "cursor-not-allowed opacity-60"- : "hover:bg-accent hover:text-foreground";- const desktopUpdateButtonClasses =- desktopUpdateState?.status === "downloaded"- ? "text-emerald-500"- : desktopUpdateState?.status === "downloading"- ? "text-sky-400"- : shouldHighlightDesktopUpdateError(desktopUpdateState)- ? "text-rose-500 animate-pulse"- : "text-amber-500 animate-pulse";const newThreadShortcutLabel =shortcutLabelForCommand(keybindings, "chat.newLocal", sidebarShortcutLabelOptions) ??shortcutLabelForCommand(keybindings, "chat.new", sidebarShortcutLabelOptions);@@ -1728,6 +1709,10 @@ export default function Sidebar() {}if (desktopUpdateButtonAction === "install") {+ const confirmed = window.confirm(+ getDesktopUpdateInstallConfirmationMessage(desktopUpdateState),+ );+ if (!confirmed) return;void bridge.installUpdate().then((result) => {@@ -1795,30 +1780,9 @@ export default function Sidebar() {return (<>{isElectron ? (- <>- <SidebarHeader className="drag-region h-[52px] flex-row items-center gap-2 px-4 py-0 pl-[90px]">- {wordmark}- {showDesktopUpdateButton && (- <Tooltip>- <TooltipTrigger- render={- <button- type="button"- aria-label={desktopUpdateTooltip}- aria-disabled={desktopUpdateButtonDisabled || undefined}- disabled={desktopUpdateButtonDisabled}- className={`inline-flex size-7 ml-auto mt-1.5 items-center justify-center rounded-md text-muted-foreground transition-colors ${desktopUpdateButtonInteractivityClasses} ${desktopUpdateButtonClasses}`}- onClick={handleDesktopUpdateButtonClick}- >- <RocketIcon className="size-3.5" />- </button>- }- />- <TooltipPopup side="bottom">{desktopUpdateTooltip}</TooltipPopup>- </Tooltip>- )}- </SidebarHeader>- </>+ <SidebarHeader className="drag-region h-[52px] flex-row items-center gap-2 px-4 py-0 pl-[90px]">+ {wordmark}+ </SidebarHeader>) : (<SidebarHeader className="gap-3 px-3 py-2 sm:gap-2.5 sm:px-4 sm:py-3">{wordmark}@@ -2006,6 +1970,7 @@ export default function Sidebar() {<SidebarSeparator /><SidebarFooter className="p-2">+ <SidebarUpdatePill /><SidebarMenu><SidebarMenuItem><SidebarMenuButtondiff --git a/apps/web/src/components/desktopUpdate.logic.test.ts b/apps/web/src/components/desktopUpdate.logic.test.tsindex 340b9a016..84bde5304 100644--- a/apps/web/src/components/desktopUpdate.logic.test.ts+++ b/apps/web/src/components/desktopUpdate.logic.test.ts@@ -2,12 +2,13 @@ import { describe, expect, it } from "vitest";import type { DesktopUpdateActionResult, DesktopUpdateState } from "@t3tools/contracts";import {+ canCheckForUpdate,getArm64IntelBuildWarningDescription,getDesktopUpdateActionError,getDesktopUpdateButtonTooltip,+ getDesktopUpdateInstallConfirmationMessage,isDesktopUpdateButtonDisabled,resolveDesktopUpdateButtonAction,- shouldHighlightDesktopUpdateError,shouldShowArm64IntelBuildWarning,shouldShowDesktopUpdateButton,shouldToastDesktopUpdateActionResult,@@ -69,6 +70,16 @@ describe("desktop update button state", () => {expect(getDesktopUpdateButtonTooltip(state)).toContain("Click to retry");});+ it("prefers install when a downloaded version already exists", () => {+ const state: DesktopUpdateState = {+ ...baseState,+ status: "available",+ availableVersion: "1.1.0",+ downloadedVersion: "1.1.0",+ };+ expect(resolveDesktopUpdateButtonAction(state)).toBe("install");+ });+it("hides the button for non-actionable check errors", () => {const state: DesktopUpdateState = {...baseState,@@ -169,25 +180,6 @@ describe("desktop update UI helpers", () => {).toBe(false);});- it("highlights only actionable updater errors", () => {- expect(- shouldHighlightDesktopUpdateError({- ...baseState,- status: "error",- errorContext: "download",- canRetry: true,- }),- ).toBe(true);- expect(- shouldHighlightDesktopUpdateError({- ...baseState,- status: "error",- errorContext: "check",- canRetry: true,- }),- ).toBe(false);- });-it("shows an Apple Silicon warning for Intel builds under Rosetta", () => {const state: DesktopUpdateState = {...baseState,@@ -213,4 +205,87 @@ describe("desktop update UI helpers", () => {expect(getArm64IntelBuildWarningDescription(state)).toContain("Download the available update");});++ it("includes the downloaded version in the install confirmation copy", () => {+ expect(+ getDesktopUpdateInstallConfirmationMessage({+ availableVersion: "1.1.0",+ downloadedVersion: "1.1.1",+ }),+ ).toContain("Install update 1.1.1 and restart T3 Code?");+ });++ it("falls back to generic install confirmation copy when no version is available", () => {+ expect(+ getDesktopUpdateInstallConfirmationMessage({+ availableVersion: null,+ downloadedVersion: null,+ }),+ ).toContain("Install update and restart T3 Code?");+ });+});++describe("canCheckForUpdate", () => {+ it("returns false for null state", () => {+ expect(canCheckForUpdate(null)).toBe(false);+ });++ it("returns false when updates are disabled", () => {+ expect(canCheckForUpdate({ ...baseState, enabled: false, status: "disabled" })).toBe(false);+ });++ it("returns false while checking", () => {+ expect(canCheckForUpdate({ ...baseState, status: "checking" })).toBe(false);+ });++ it("returns false while downloading", () => {+ expect(canCheckForUpdate({ ...baseState, status: "downloading", downloadPercent: 50 })).toBe(+ false,+ );+ });++ it("returns false once an update has been downloaded", () => {+ expect(+ canCheckForUpdate({+ ...baseState,+ status: "downloaded",+ availableVersion: "1.1.0",+ downloadedVersion: "1.1.0",+ }),+ ).toBe(false);+ });++ it("returns true when idle", () => {+ expect(canCheckForUpdate({ ...baseState, status: "idle" })).toBe(true);+ });++ it("returns true when up-to-date", () => {+ expect(canCheckForUpdate({ ...baseState, status: "up-to-date" })).toBe(true);+ });++ it("returns true when an update is available", () => {+ expect(+ canCheckForUpdate({ ...baseState, status: "available", availableVersion: "1.1.0" }),+ ).toBe(true);+ });++ it("returns true on error so the user can retry", () => {+ expect(+ canCheckForUpdate({+ ...baseState,+ status: "error",+ errorContext: "check",+ message: "network",+ }),+ ).toBe(true);+ });+});++describe("getDesktopUpdateButtonTooltip", () => {+ it("returns 'Up to date' for non-actionable states", () => {+ expect(getDesktopUpdateButtonTooltip({ ...baseState, status: "idle" })).toBe("Up to date");+ expect(getDesktopUpdateButtonTooltip({ ...baseState, status: "up-to-date" })).toBe(+ "Up to date",+ );+ });});diff --git a/apps/web/src/components/desktopUpdate.logic.ts b/apps/web/src/components/desktopUpdate.logic.tsindex 5c9c30302..38983c810 100644--- a/apps/web/src/components/desktopUpdate.logic.ts+++ b/apps/web/src/components/desktopUpdate.logic.ts@@ -5,16 +5,13 @@ export type DesktopUpdateButtonAction = "download" | "install" | "none";export function resolveDesktopUpdateButtonAction(state: DesktopUpdateState,): DesktopUpdateButtonAction {+ if (state.downloadedVersion) {+ return "install";+ }if (state.status === "available") {return "download";}- if (state.status === "downloaded") {- return "install";- }if (state.status === "error") {- if (state.errorContext === "install" && state.downloadedVersion) {- return "install";- }if (state.errorContext === "download" && state.availableVersion) {return "download";}@@ -76,7 +73,14 @@ export function getDesktopUpdateButtonTooltip(state: DesktopUpdateState): string}return state.message ?? "Update failed";}- return "Update available";+ return "Up to date";+}++export function getDesktopUpdateInstallConfirmationMessage(+ state: Pick<DesktopUpdateState, "availableVersion" | "downloadedVersion">,+): string {+ const version = state.downloadedVersion ?? state.availableVersion;+ return `Install update${version ? ` ${version}` : ""} and restart T3 Code?\n\nAny running tasks will be interrupted. Make sure you're ready before continuing.`;}export function getDesktopUpdateActionError(result: DesktopUpdateActionResult): string | null {@@ -94,3 +98,13 @@ export function shouldHighlightDesktopUpdateError(state: DesktopUpdateState | nuif (!state || state.status !== "error") return false;return state.errorContext === "download" || state.errorContext === "install";}++export function canCheckForUpdate(state: DesktopUpdateState | null): boolean {+ if (!state || !state.enabled) return false;+ return (+ state.status !== "checking" &&+ state.status !== "downloading" &&+ state.status !== "downloaded" &&+ state.status !== "disabled"+ );+}diff --git a/apps/web/src/components/settings/SettingsPanels.tsx b/apps/web/src/components/settings/SettingsPanels.tsxindex bb149c00a..f9fdb1d61 100644--- a/apps/web/src/components/settings/SettingsPanels.tsx+++ b/apps/web/src/components/settings/SettingsPanels.tsx@@ -22,12 +22,24 @@ import { DEFAULT_UNIFIED_SETTINGS } from "@t3tools/contracts/settings";import { normalizeModelSlug } from "@t3tools/shared/model";import { Equal } from "effect";import { APP_VERSION } from "../../branding";+import {+ canCheckForUpdate,+ getDesktopUpdateButtonTooltip,+ getDesktopUpdateInstallConfirmationMessage,+ isDesktopUpdateButtonDisabled,+ resolveDesktopUpdateButtonAction,+} from "../../components/desktopUpdate.logic";import { ProviderModelPicker } from "../chat/ProviderModelPicker";import { TraitsPicker } from "../chat/TraitsPicker";import { resolveAndPersistPreferredEditor } from "../../editorPreferences";+import { isElectron } from "../../env";import { useTheme } from "../../hooks/useTheme";import { useSettings, useUpdateSettings } from "../../hooks/useSettings";import { useThreadActions } from "../../hooks/useThreadActions";+import {+ setDesktopUpdateStateQueryData,+ useDesktopUpdateState,+} from "../../lib/desktopUpdateReactQuery";import { serverConfigQueryOptions, serverQueryKeys } from "../../lib/serverReactQuery";import {MAX_CUSTOM_MODEL_LENGTH,@@ -236,7 +248,7 @@ function SettingsRow({control,children,}: {- title: string;+ title: ReactNode;description: string;status?: ReactNode;resetAction?: ReactNode;@@ -299,6 +311,133 @@ function SettingsPageContainer({ children }: { children: ReactNode }) {);}+function AboutVersionTitle() {+ return (+ <span className="inline-flex items-center gap-2">+ <span>Version</span>+ <code className="text-[11px] font-medium text-muted-foreground">{APP_VERSION}</code>+ </span>+ );+}++function AboutVersionSection() {+ const queryClient = useQueryClient();+ const updateStateQuery = useDesktopUpdateState();++ const updateState = updateStateQuery.data ?? null;++ const handleButtonClick = useCallback(() => {+ const bridge = window.desktopBridge;+ if (!bridge) return;++ const action = updateState ? resolveDesktopUpdateButtonAction(updateState) : "none";++ if (action === "download") {+ void bridge+ .downloadUpdate()+ .then((result) => {+ setDesktopUpdateStateQueryData(queryClient, result.state);+ })+ .catch((error: unknown) => {+ toastManager.add({+ type: "error",+ title: "Could not download update",+ description: error instanceof Error ? error.message : "Download failed.",+ });+ });+ return;+ }++ if (action === "install") {+ const confirmed = window.confirm(+ getDesktopUpdateInstallConfirmationMessage(+ updateState ?? { availableVersion: null, downloadedVersion: null },+ ),+ );+ if (!confirmed) return;+ void bridge+ .installUpdate()+ .then((result) => {+ setDesktopUpdateStateQueryData(queryClient, result.state);+ })+ .catch((error: unknown) => {+ toastManager.add({+ type: "error",+ title: "Could not install update",+ description: error instanceof Error ? error.message : "Install failed.",+ });+ });+ return;+ }++ if (typeof bridge.checkForUpdate !== "function") return;+ void bridge+ .checkForUpdate()+ .then((result) => {+ setDesktopUpdateStateQueryData(queryClient, result.state);+ if (!result.checked) {+ toastManager.add({+ type: "error",+ title: "Could not check for updates",+ description:+ result.state.message ?? "Automatic updates are not available in this build.",+ });+ }+ })+ .catch((error: unknown) => {+ toastManager.add({+ type: "error",+ title: "Could not check for updates",+ description: error instanceof Error ? error.message : "Update check failed.",+ });+ });+ }, [queryClient, updateState]);++ const action = updateState ? resolveDesktopUpdateButtonAction(updateState) : "none";+ const buttonTooltip = updateState ? getDesktopUpdateButtonTooltip(updateState) : null;+ const buttonDisabled =+ action === "none"+ ? !canCheckForUpdate(updateState)+ : isDesktopUpdateButtonDisabled(updateState);++ const actionLabel: Record<string, string> = { download: "Download", install: "Install" };+ const statusLabel: Record<string, string> = {+ checking: "Checking…",+ downloading: "Downloading…",+ "up-to-date": "Up to Date",+ };+ const buttonLabel =+ actionLabel[action] ?? statusLabel[updateState?.status ?? ""] ?? "Check for Updates";+ const description =+ action === "download" || action === "install"+ ? "Update available."+ : "Current version of the application.";++ return (+ <SettingsRow+ title={<AboutVersionTitle />}+ description={description}+ control={+ <Tooltip>+ <TooltipTrigger+ render={+ <Button+ size="xs"+ variant={action === "install" ? "default" : "outline"}+ disabled={buttonDisabled}+ onClick={handleButtonClick}+ >+ {buttonLabel}+ </Button>+ }+ />+ {buttonTooltip ? <TooltipPopup>{buttonTooltip}</TooltipPopup> : null}+ </Tooltip>+ }+ />+ );+}+export function useSettingsRestore(onRestored?: () => void) {const { theme, setTheme } = useTheme();const settings = useSettings();@@ -1258,12 +1397,17 @@ export function GeneralSettingsPanel() {</Button>}/>+ </SettingsSection>- <SettingsRow- title="Version"- description="Current application version."- control={<code className="text-xs font-medium text-muted-foreground">{APP_VERSION}</code>}- />+ <SettingsSection title="About">+ {isElectron ? (+ <AboutVersionSection />+ ) : (+ <SettingsRow+ title={<AboutVersionTitle />}+ description="Current version of the application."+ />+ )}</SettingsSection></SettingsPageContainer>);@@ -1325,7 +1469,7 @@ export function ArchivedThreadsPanel() {<SettingsPageContainer>{archivedGroups.length === 0 ? (<SettingsSection title="Archived threads">- <Empty className="min-h-[22rem]">+ <Empty className="min-h-88"><EmptyMedia variant="icon"><ArchiveIcon /></EmptyMedia>diff --git a/apps/web/src/components/settings/SettingsSidebarNav.tsx b/apps/web/src/components/settings/SettingsSidebarNav.tsxindex 20914b499..6ba698c91 100644--- a/apps/web/src/components/settings/SettingsSidebarNav.tsx+++ b/apps/web/src/components/settings/SettingsSidebarNav.tsx@@ -20,7 +20,7 @@ export const SETTINGS_NAV_ITEMS: ReadonlyArray<{icon: ComponentType<{ className?: string }>;}> = [{ label: "General", to: "/settings/general", icon: Settings2Icon },- { label: "Archived threads", to: "/settings/archived", icon: ArchiveIcon },+ { label: "Archive", to: "/settings/archived", icon: ArchiveIcon },];export function SettingsSidebarNav({ pathname }: { pathname: string }) {diff --git a/apps/web/src/components/sidebar/SidebarUpdatePill.tsx b/apps/web/src/components/sidebar/SidebarUpdatePill.tsxnew file mode 100644index 000000000..2f9aec112--- /dev/null+++ b/apps/web/src/components/sidebar/SidebarUpdatePill.tsx@@ -0,0 +1,176 @@+import { DownloadIcon, RotateCwIcon, TriangleAlertIcon, XIcon } from "lucide-react";+import { useQueryClient } from "@tanstack/react-query";+import { useCallback, useState } from "react";+import { isElectron } from "../../env";+import {+ setDesktopUpdateStateQueryData,+ useDesktopUpdateState,+} from "../../lib/desktopUpdateReactQuery";+import { toastManager } from "../ui/toast";+import {+ getArm64IntelBuildWarningDescription,+ getDesktopUpdateActionError,+ getDesktopUpdateButtonTooltip,+ getDesktopUpdateInstallConfirmationMessage,+ isDesktopUpdateButtonDisabled,+ resolveDesktopUpdateButtonAction,+ shouldShowArm64IntelBuildWarning,+ shouldShowDesktopUpdateButton,+ shouldToastDesktopUpdateActionResult,+} from "../desktopUpdate.logic";+import { Alert, AlertDescription, AlertTitle } from "../ui/alert";+import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";++export function SidebarUpdatePill() {+ const queryClient = useQueryClient();+ const state = useDesktopUpdateState().data ?? null;+ const [dismissed, setDismissed] = useState(false);++ const visible = isElectron && shouldShowDesktopUpdateButton(state) && !dismissed;+ const tooltip = state ? getDesktopUpdateButtonTooltip(state) : "Update available";+ const disabled = isDesktopUpdateButtonDisabled(state);+ const action = state ? resolveDesktopUpdateButtonAction(state) : "none";++ const showArm64Warning = isElectron && shouldShowArm64IntelBuildWarning(state);+ const arm64Description =+ state && showArm64Warning ? getArm64IntelBuildWarningDescription(state) : null;++ const handleAction = useCallback(() => {+ const bridge = window.desktopBridge;+ if (!bridge || !state) return;+ if (disabled || action === "none") return;++ if (action === "download") {+ void bridge+ .downloadUpdate()+ .then((result) => {+ setDesktopUpdateStateQueryData(queryClient, result.state);+ if (result.completed) {+ toastManager.add({+ type: "success",+ title: "Update downloaded",+ description: "Restart the app from the update button to install it.",+ });+ }+ if (!shouldToastDesktopUpdateActionResult(result)) return;+ const actionError = getDesktopUpdateActionError(result);+ if (!actionError) return;+ toastManager.add({+ type: "error",+ title: "Could not download update",+ description: actionError,+ });+ })+ .catch((error) => {+ toastManager.add({+ type: "error",+ title: "Could not start update download",+ description: error instanceof Error ? error.message : "An unexpected error occurred.",+ });+ });+ return;+ }++ if (action === "install") {+ const confirmed = window.confirm(getDesktopUpdateInstallConfirmationMessage(state));+ if (!confirmed) return;+ void bridge+ .installUpdate()+ .then((result) => {+ setDesktopUpdateStateQueryData(queryClient, result.state);+ if (!shouldToastDesktopUpdateActionResult(result)) return;+ const actionError = getDesktopUpdateActionError(result);+ if (!actionError) return;+ toastManager.add({+ type: "error",+ title: "Could not install update",+ description: actionError,+ });+ })+ .catch((error) => {+ toastManager.add({+ type: "error",+ title: "Could not install update",+ description: error instanceof Error ? error.message : "An unexpected error occurred.",+ });+ });+ }+ }, [action, disabled, queryClient, state]);++ if (!visible && !showArm64Warning) return null;++ return (+ <div className="flex flex-col gap-1">+ {showArm64Warning && arm64Description && (+ <Alert variant="warning" className="rounded-2xl border-warning/40 bg-warning/8 text-xs">+ <TriangleAlertIcon />+ <AlertTitle>Intel build on Apple Silicon</AlertTitle>+ <AlertDescription>{arm64Description}</AlertDescription>+ </Alert>+ )}+ {visible && (+ <div+ className={`group/update relative flex h-7 w-full items-center rounded-lg bg-primary/15 text-xs font-medium text-primary ${+ disabled ? " cursor-not-allowed opacity-60" : ""+ }`}+ >+ <div className="pointer-events-none absolute inset-0 rounded-lg transition-colors group-has-[button.update-main:hover]/update:bg-primary/22" />+ <Tooltip>+ <TooltipTrigger+ render={+ <button+ type="button"+ aria-label={tooltip}+ aria-disabled={disabled || undefined}+ disabled={disabled}+ className="update-main relative flex h-full flex-1 items-center gap-2 px-2 enabled:cursor-pointer"+ onClick={handleAction}+ >+ {action === "install" ? (+ <>+ <RotateCwIcon className="size-3.5" />+ <span>Restart to update</span>+ </>+ ) : state?.status === "downloading" ? (+ <>+ <DownloadIcon className="size-3.5" />+ <span>+ Downloading+ {typeof state.downloadPercent === "number"+ ? ` (${Math.floor(state.downloadPercent)}%)`+ : "…"}+ </span>+ </>+ ) : (+ <>+ <DownloadIcon className="size-3.5" />+ <span>Update available</span>+ </>+ )}+ </button>+ }+ />+ <TooltipPopup side="top">{tooltip}</TooltipPopup>+ </Tooltip>+ {action === "download" && (+ <Tooltip>+ <TooltipTrigger+ render={+ <button+ type="button"+ aria-label="Dismiss update"+ className="mr-1 inline-flex size-5 items-center justify-center rounded-md text-primary/60 transition-colors hover:text-primary"+ onClick={() => setDismissed(true)}+ >+ <XIcon className="size-3.5" />+ </button>+ }+ />+ <TooltipPopup side="top">Dismiss until next launch</TooltipPopup>+ </Tooltip>+ )}+ </div>+ )}+ </div>+ );+}diff --git a/apps/web/src/lib/desktopUpdateReactQuery.test.ts b/apps/web/src/lib/desktopUpdateReactQuery.test.tsnew file mode 100644index 000000000..a0f475591--- /dev/null+++ b/apps/web/src/lib/desktopUpdateReactQuery.test.ts@@ -0,0 +1,49 @@+import { QueryClient } from "@tanstack/react-query";+import { describe, expect, it } from "vitest";+import type { DesktopUpdateState } from "@t3tools/contracts";+import {+ desktopUpdateQueryKeys,+ desktopUpdateStateQueryOptions,+ setDesktopUpdateStateQueryData,+} from "./desktopUpdateReactQuery";++const baseState: DesktopUpdateState = {+ enabled: true,+ status: "idle",+ currentVersion: "1.0.0",+ hostArch: "x64",+ appArch: "x64",+ runningUnderArm64Translation: false,+ availableVersion: null,+ downloadedVersion: null,+ downloadPercent: null,+ checkedAt: null,+ message: null,+ errorContext: null,+ canRetry: false,+};++describe("desktopUpdateStateQueryOptions", () => {+ it("always refetches on mount so Settings does not reuse stale desktop update state", () => {+ const options = desktopUpdateStateQueryOptions();++ expect(options.staleTime).toBe(Infinity);+ expect(options.refetchOnMount).toBe("always");+ });+});++describe("setDesktopUpdateStateQueryData", () => {+ it("writes desktop update state into the shared cache key", () => {+ const queryClient = new QueryClient();+ const nextState: DesktopUpdateState = {+ ...baseState,+ status: "downloaded",+ availableVersion: "1.1.0",+ downloadedVersion: "1.1.0",+ };++ setDesktopUpdateStateQueryData(queryClient, nextState);++ expect(queryClient.getQueryData(desktopUpdateQueryKeys.state())).toEqual(nextState);+ });+});diff --git a/apps/web/src/lib/desktopUpdateReactQuery.ts b/apps/web/src/lib/desktopUpdateReactQuery.tsnew file mode 100644index 000000000..931577278--- /dev/null+++ b/apps/web/src/lib/desktopUpdateReactQuery.ts@@ -0,0 +1,42 @@+import { queryOptions, useQuery, useQueryClient, type QueryClient } from "@tanstack/react-query";+import { useEffect } from "react";+import type { DesktopUpdateState } from "@t3tools/contracts";++export const desktopUpdateQueryKeys = {+ all: ["desktop", "update"] as const,+ state: () => ["desktop", "update", "state"] as const,+};++export const setDesktopUpdateStateQueryData = (+ queryClient: QueryClient,+ state: DesktopUpdateState | null,+) => queryClient.setQueryData(desktopUpdateQueryKeys.state(), state);++export function desktopUpdateStateQueryOptions() {+ return queryOptions({+ queryKey: desktopUpdateQueryKeys.state(),+ queryFn: async () => {+ const bridge = window.desktopBridge;+ if (!bridge || typeof bridge.getUpdateState !== "function") return null;+ return bridge.getUpdateState();+ },+ staleTime: Infinity,+ refetchOnMount: "always",+ });+}++export function useDesktopUpdateState() {+ const queryClient = useQueryClient();+ const query = useQuery(desktopUpdateStateQueryOptions());++ useEffect(() => {+ const bridge = window.desktopBridge;+ if (!bridge || typeof bridge.onUpdateState !== "function") return;++ return bridge.onUpdateState((nextState) => {+ setDesktopUpdateStateQueryData(queryClient, nextState);+ });+ }, [queryClient]);++ return query;+}diff --git a/packages/contracts/src/ipc.ts b/packages/contracts/src/ipc.tsindex 0443128dd..5585e7f30 100644--- a/packages/contracts/src/ipc.ts+++ b/packages/contracts/src/ipc.ts@@ -101,6 +101,11 @@ export interface DesktopUpdateActionResult {state: DesktopUpdateState;}+export interface DesktopUpdateCheckResult {+ checked: boolean;+ state: DesktopUpdateState;+}+export interface DesktopBridge {getWsUrl: () => string | null;pickFolder: () => Promise<string | null>;@@ -113,6 +118,7 @@ export interface DesktopBridge {openExternal: (url: string) => Promise<boolean>;onMenuAction: (listener: (action: string) => void) => () => void;getUpdateState: () => Promise<DesktopUpdateState>;+ checkForUpdate: () => Promise<DesktopUpdateCheckResult>;downloadUpdate: () => Promise<DesktopUpdateActionResult>;installUpdate: () => Promise<DesktopUpdateActionResult>;onUpdateState: (listener: (state: DesktopUpdateState) => void) => () => void;