The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { thrownErrorMessage } from "@t3tools/client-runtime/errors"; |
| 2 | import { managedUpdatesDenial } from "@t3tools/client-runtime/contract-labels"; |
| 3 | import { type DesktopBridge, type DesktopUpdateState } from "@t3tools/contracts"; |
| 4 | import { TriangleAlertIcon } from "lucide-react"; |
| 5 | import { msg, T, useGT, useMessages } from "gt-react"; |
| 6 | import { type ComponentProps, useId, useRef, useState } from "react"; |
| 7 | import { flushSync } from "react-dom"; |
| 8 | import { settlePromise, squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime"; |
| 9 | import { isElectron } from "../../env"; |
| 10 | import { m } from "../../i18n/messages"; |
| 11 | import { useMediaQuery } from "../../hooks/useMediaQuery"; |
| 12 | import { cn } from "../../lib/utils"; |
| 13 | import { ensureLocalApi } from "../../localApi"; |
| 14 | import { useDesktopUpdateState } from "../../state/desktopUpdate"; |
| 15 | import { usePrimaryManagedPolicy } from "../../state/managedPolicy"; |
| 16 | import { stackedThreadToast, toastManager } from "../ui/toast"; |
| 17 | import { |
| 18 | canCheckForUpdate, |
| 19 | getArm64IntelBuildWarningDescription, |
| 20 | getDesktopUpdateActionError, |
| 21 | getDesktopUpdateButtonTooltip, |
| 22 | getDesktopUpdateDownloadedVersion, |
| 23 | getDesktopUpdateIdleTooltip, |
| 24 | getDesktopUpdateInstallConfirmationMessage, |
| 25 | isDesktopUpdateButtonDisabled, |
| 26 | resolveDesktopUpdateButtonAction, |
| 27 | shouldShowArm64IntelBuildWarning, |
| 28 | shouldToastDesktopUpdateActionResult, |
| 29 | } from "../desktopUpdate.logic"; |
| 30 | import { showDesktopUpdateDownloadedToast } from "../desktopUpdate.toast"; |
| 31 | import { useCheckProviderUpdates } from "../ProviderUpdatesAction"; |
| 32 | import { Alert, AlertDescription, AlertTitle } from "../ui/alert"; |
| 33 | import { Popover, PopoverCreateHandle, PopoverPopup, PopoverTrigger } from "../ui/popover"; |
| 34 | import { SidebarMenuItem } from "../ui/sidebar"; |
| 35 | import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip"; |
| 36 | import { |
| 37 | DesktopUpdateStatusIcon, |
| 38 | type DesktopUpdateStatusIconState, |
| 39 | shouldContinueDesktopUpdateCheckAnimation, |
| 40 | shouldShowDesktopUpdateCheckIcon, |
| 41 | } from "./DesktopUpdateStatusIcon"; |
| 42 | import { SidebarUpdateReleaseNotes } from "./SidebarUpdateReleaseNotes"; |
| 43 | import { SidebarUpdateCapsule } from "./SidebarUpdateCapsule"; |
| 44 | import { UpdateEverythingDialog } from "./UpdateEverythingDialog"; |
| 45 | import type { UpdateEverythingRun, UpdateRunLocalState } from "./updateEverything.logic"; |
| 46 | import { |
| 47 | clearSavedUpdateEverythingResult, |
| 48 | saveUpdateEverythingResult, |
| 49 | useUpdateEverythingRun, |
| 50 | } from "./updateEverythingRun"; |
| 51 | import { type ReportLocalUpdateError, useUpdateEverything } from "./useUpdateEverything"; |
| 52 | |
| 53 | type SidebarUpdatePopoverChangeDetails = Parameters< |
| 54 | NonNullable<ComponentProps<typeof Popover>["onOpenChange"]> |
| 55 | >[1]; |
| 56 | type SidebarUpdatePopoverHandle = ReturnType<typeof PopoverCreateHandle>; |
| 57 | |
| 58 | function shouldUseSidebarUpdateReleaseNotesPopover( |
| 59 | showUpdateDetails: boolean, |
| 60 | state: DesktopUpdateState | null, |
| 61 | ): boolean { |
| 62 | return showUpdateDetails && (state?.releaseNotes.length ?? 0) > 0; |
| 63 | } |
| 64 | |
| 65 | function handleSidebarUpdateReleaseNotesPopoverOpenChange( |
| 66 | _open: boolean, |
| 67 | details: Pick<SidebarUpdatePopoverChangeDetails, "reason" | "cancel">, |
| 68 | ): void { |
| 69 | if (details.reason === "trigger-press") details.cancel(); |
| 70 | } |
| 71 | |
| 72 | function openSidebarUpdateReleaseNotesPopoverOnForwardTab( |
| 73 | event: { readonly key: string; readonly shiftKey: boolean }, |
| 74 | handle: Pick<SidebarUpdatePopoverHandle, "open">, |
| 75 | triggerId: string, |
| 76 | ): void { |
| 77 | if (event.key !== "Tab" || event.shiftKey) return; |
| 78 | // Hover-open popovers do not manage focus. Promote this one before native Tab runs. |
| 79 | flushSync(() => handle.open(triggerId)); |
| 80 | } |
| 81 | |
| 82 | function resolveSidebarUpdatePresentation({ |
| 83 | action, |
| 84 | showsEverything, |
| 85 | run, |
| 86 | isDownloading, |
| 87 | showCheckIcon, |
| 88 | }: { |
| 89 | readonly action: ReturnType<typeof resolveDesktopUpdateButtonAction>; |
| 90 | readonly showsEverything: boolean; |
| 91 | readonly run: UpdateEverythingRun | null; |
| 92 | readonly isDownloading: boolean; |
| 93 | readonly showCheckIcon: boolean; |
| 94 | }) { |
| 95 | const showUpdateDetails = action !== "none" || showsEverything || run !== null || isDownloading; |
| 96 | const iconStatus: DesktopUpdateStatusIconState = showCheckIcon |
| 97 | ? "checking" |
| 98 | : isDownloading |
| 99 | ? "downloading" |
| 100 | : run !== null |
| 101 | ? run.localVersion !== null && action === "install" |
| 102 | ? "downloaded" |
| 103 | : "everything" |
| 104 | : showsEverything |
| 105 | ? "everything" |
| 106 | : action === "install" |
| 107 | ? "downloaded" |
| 108 | : action === "download" |
| 109 | ? "available" |
| 110 | : "idle"; |
| 111 | |
| 112 | return { |
| 113 | iconStatus, |
| 114 | showUpdateDetails, |
| 115 | showUpdateIconState: showUpdateDetails && !showCheckIcon, |
| 116 | } as const; |
| 117 | } |
| 118 | |
| 119 | export function SidebarUpdateArchitectureWarning() { |
| 120 | return isElectron ? <SidebarUpdateArchitectureWarningContent /> : null; |
| 121 | } |
| 122 | |
| 123 | function SidebarUpdateArchitectureWarningContent() { |
| 124 | const state = useDesktopUpdateState(); |
| 125 | const messages = useMessages(); |
| 126 | const visible = shouldShowArm64IntelBuildWarning(state); |
| 127 | const description = |
| 128 | state && visible ? getArm64IntelBuildWarningDescription(state, messages) : null; |
| 129 | |
| 130 | if (!visible || !description) return null; |
| 131 | |
| 132 | return ( |
| 133 | <Alert variant="warning"> |
| 134 | <TriangleAlertIcon /> |
| 135 | <AlertTitle> |
| 136 | <T>Intel build on Apple Silicon</T> |
| 137 | </AlertTitle> |
| 138 | <AlertDescription>{description}</AlertDescription> |
| 139 | </Alert> |
| 140 | ); |
| 141 | } |
| 142 | |
| 143 | const toastUpdateError: ReportLocalUpdateError = (title, description) => { |
| 144 | toastManager.add(stackedThreadToast({ type: "error", title, description })); |
| 145 | }; |
| 146 | |
| 147 | export async function downloadLocalUpdate( |
| 148 | bridge: DesktopBridge, |
| 149 | { |
| 150 | notifyDownloaded, |
| 151 | reportError = toastUpdateError, |
| 152 | }: { readonly notifyDownloaded: boolean; readonly reportError?: ReportLocalUpdateError }, |
| 153 | ): Promise<boolean> { |
| 154 | try { |
| 155 | const result = await bridge.downloadUpdate(); |
| 156 | if (result.completed && notifyDownloaded) { |
| 157 | showDesktopUpdateDownloadedToast(bridge, result.state); |
| 158 | } |
| 159 | const actionError = shouldToastDesktopUpdateActionResult(result) |
| 160 | ? getDesktopUpdateActionError(result) |
| 161 | : null; |
| 162 | if (actionError) reportError(m(msg("Could not download update")), actionError); |
| 163 | return result.completed; |
| 164 | } catch (error) { |
| 165 | reportError( |
| 166 | m(msg("Could not start update download")), |
| 167 | thrownErrorMessage(error, m) ?? m(msg("An unexpected error occurred.")), |
| 168 | ); |
| 169 | return false; |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | export async function installLocalUpdate( |
| 174 | bridge: DesktopBridge, |
| 175 | reportError: ReportLocalUpdateError = toastUpdateError, |
| 176 | expectedVersion?: string, |
| 177 | ): Promise<boolean> { |
| 178 | try { |
| 179 | const result = await bridge.installUpdate(expectedVersion); |
| 180 | if (!result.accepted) { |
| 181 | showDesktopUpdateDownloadedToast(bridge, result.state); |
| 182 | return false; |
| 183 | } |
| 184 | const actionError = shouldToastDesktopUpdateActionResult(result) |
| 185 | ? getDesktopUpdateActionError(result) |
| 186 | : null; |
| 187 | if (!actionError) return true; |
| 188 | reportError(m(msg("Could not install update")), actionError); |
| 189 | return false; |
| 190 | } catch (error) { |
| 191 | reportError( |
| 192 | m(msg("Could not install update")), |
| 193 | thrownErrorMessage(error, m) ?? m(msg("An unexpected error occurred.")), |
| 194 | ); |
| 195 | return false; |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | export function SidebarUpdatePill() { |
| 200 | return <SidebarUpdateControl />; |
| 201 | } |
| 202 | |
| 203 | function SidebarUpdateControl() { |
| 204 | const state = useDesktopUpdateState(); |
| 205 | const gt = useGT(); |
| 206 | const messages = useMessages(); |
| 207 | // The desktop updates this machine, whose policy the primary environment reports. |
| 208 | const updatesDenial = managedUpdatesDenial(usePrimaryManagedPolicy(), messages); |
| 209 | const [isActionPending, setIsActionPending] = useState(false); |
| 210 | const [providerCheck, setProviderCheck] = useState<"button" | "dialog" | null>(null); |
| 211 | const isCheckingProviders = providerCheck === "button"; |
| 212 | const [isConfirmingEverything, setIsConfirmingEverything] = useState(false); |
| 213 | const [checkAnimationKey, setCheckAnimationKey] = useState(0); |
| 214 | const [releaseNotesPopoverHandle] = useState(() => PopoverCreateHandle()); |
| 215 | const suppressReleaseNotesFocusOpen = useRef(false); |
| 216 | const releaseNotesPopupRef = useRef<HTMLDivElement>(null); |
| 217 | const releaseNotesTriggerId = useId(); |
| 218 | const prefersReducedMotion = useMediaQuery("(prefers-reduced-motion: reduce)"); |
| 219 | |
| 220 | const updateStatus = state?.status; |
| 221 | const [isCheckAnimationLatched, setIsCheckAnimationLatched] = useState( |
| 222 | () => !prefersReducedMotion && updateStatus === "checking", |
| 223 | ); |
| 224 | const [latchInputs, setLatchInputs] = useState({ prefersReducedMotion, updateStatus }); |
| 225 | if ( |
| 226 | latchInputs.prefersReducedMotion !== prefersReducedMotion || |
| 227 | latchInputs.updateStatus !== updateStatus |
| 228 | ) { |
| 229 | setLatchInputs({ prefersReducedMotion, updateStatus }); |
| 230 | if (prefersReducedMotion) { |
| 231 | setIsCheckAnimationLatched(false); |
| 232 | } else if (updateStatus === "checking") { |
| 233 | setIsCheckAnimationLatched(true); |
| 234 | } |
| 235 | } |
| 236 | |
| 237 | const action = state ? resolveDesktopUpdateButtonAction(state) : "none"; |
| 238 | const isDownloading = state?.status === "downloading"; |
| 239 | const localUpdateVersion = |
| 240 | state && action !== "none" ? getDesktopUpdateDownloadedVersion(state) : null; |
| 241 | const everything = useUpdateEverything(localUpdateVersion); |
| 242 | const checkProviderUpdates = useCheckProviderUpdates(); |
| 243 | const runsEverything = everything.hasUpdates && !isDownloading; |
| 244 | const run = useUpdateEverythingRun(); |
| 245 | const isRunningEverything = run !== null; |
| 246 | const showCheckIcon = shouldShowDesktopUpdateCheckIcon({ |
| 247 | isAnimationLatched: isCheckAnimationLatched, |
| 248 | isChecking: state?.status === "checking" || isCheckingProviders, |
| 249 | prefersReducedMotion, |
| 250 | }); |
| 251 | const { iconStatus, showUpdateDetails, showUpdateIconState } = resolveSidebarUpdatePresentation({ |
| 252 | action, |
| 253 | showsEverything: runsEverything, |
| 254 | run, |
| 255 | isDownloading, |
| 256 | showCheckIcon, |
| 257 | }); |
| 258 | const idleTooltip = |
| 259 | !showUpdateDetails && !showCheckIcon |
| 260 | ? getDesktopUpdateIdleTooltip(state, updatesDenial, messages) |
| 261 | : null; |
| 262 | const tooltip = runsEverything |
| 263 | ? everything.summary |
| 264 | : showUpdateDetails |
| 265 | ? state |
| 266 | ? getDesktopUpdateButtonTooltip(state, messages) |
| 267 | : gt("Update available") |
| 268 | : showCheckIcon |
| 269 | ? gt("Checking for updates…") |
| 270 | : (idleTooltip?.title ?? gt("Check for updates")); |
| 271 | const disabled = showCheckIcon |
| 272 | ? true |
| 273 | : runsEverything |
| 274 | ? false |
| 275 | : showUpdateDetails |
| 276 | ? isDesktopUpdateButtonDisabled(state) |
| 277 | : !canCheckForUpdate(state); |
| 278 | const isInteractionDisabled = disabled || isActionPending || isRunningEverything; |
| 279 | const showReleaseNotesPopover = |
| 280 | !isRunningEverything && shouldUseSidebarUpdateReleaseNotesPopover(showUpdateDetails, state); |
| 281 | |
| 282 | const [releaseNotesOpen, setReleaseNotesOpen] = useState(false); |
| 283 | const [releaseNotesTriggerFocusVisible, setReleaseNotesTriggerFocusVisible] = useState(false); |
| 284 | // Release notes close when they stop applying, and open when they start |
| 285 | // applying while the trigger already holds keyboard focus. |
| 286 | const [releaseNotesShownBefore, setReleaseNotesShownBefore] = useState(showReleaseNotesPopover); |
| 287 | if (releaseNotesShownBefore !== showReleaseNotesPopover) { |
| 288 | setReleaseNotesShownBefore(showReleaseNotesPopover); |
| 289 | setReleaseNotesOpen(showReleaseNotesPopover && releaseNotesTriggerFocusVisible); |
| 290 | } |
| 291 | |
| 292 | const handleAction = async () => { |
| 293 | const bridge = window.desktopBridge; |
| 294 | if (isInteractionDisabled) return; |
| 295 | |
| 296 | if (runsEverything) { |
| 297 | setIsConfirmingEverything(true); |
| 298 | // Machines that still cache an older latest version add their rows while the dialog is open. |
| 299 | setProviderCheck("dialog"); |
| 300 | void checkProviderUpdates({ quiet: true }).finally(() => setProviderCheck(null)); |
| 301 | return; |
| 302 | } |
| 303 | |
| 304 | if (!bridge || !state) return; |
| 305 | setIsActionPending(true); |
| 306 | |
| 307 | if (action === "download") { |
| 308 | void downloadLocalUpdate(bridge, { notifyDownloaded: true }).finally(() => |
| 309 | setIsActionPending(false), |
| 310 | ); |
| 311 | return; |
| 312 | } |
| 313 | |
| 314 | if (action === "install") { |
| 315 | let confirmed = false; |
| 316 | try { |
| 317 | confirmed = await ensureLocalApi().dialogs.confirm( |
| 318 | getDesktopUpdateInstallConfirmationMessage(state), |
| 319 | { initialFocus: "confirm" }, |
| 320 | ); |
| 321 | } catch (error) { |
| 322 | setIsActionPending(false); |
| 323 | toastManager.add( |
| 324 | stackedThreadToast({ |
| 325 | type: "error", |
| 326 | title: gt("Could not confirm update"), |
| 327 | description: thrownErrorMessage(error, m) ?? gt("Update confirmation failed."), |
| 328 | }), |
| 329 | ); |
| 330 | return; |
| 331 | } |
| 332 | if (!confirmed) { |
| 333 | setIsActionPending(false); |
| 334 | return; |
| 335 | } |
| 336 | void installLocalUpdate(bridge).finally(() => setIsActionPending(false)); |
| 337 | return; |
| 338 | } |
| 339 | |
| 340 | if (!prefersReducedMotion) { |
| 341 | setIsCheckAnimationLatched(true); |
| 342 | setCheckAnimationKey((key) => key + 1); |
| 343 | } |
| 344 | const appCheck = bridge |
| 345 | .checkForUpdate() |
| 346 | .then((result) => { |
| 347 | if (result.checked) return; |
| 348 | toastManager.add( |
| 349 | stackedThreadToast({ |
| 350 | type: "error", |
| 351 | title: gt("Could not check for updates"), |
| 352 | description: |
| 353 | updatesDenial ?? |
| 354 | result.state.message ?? |
| 355 | gt("Automatic updates are not available in this build."), |
| 356 | }), |
| 357 | ); |
| 358 | }) |
| 359 | .catch((error) => { |
| 360 | toastManager.add( |
| 361 | stackedThreadToast({ |
| 362 | type: "error", |
| 363 | title: gt("Could not check for updates"), |
| 364 | description: thrownErrorMessage(error, m) ?? gt("Update check failed."), |
| 365 | }), |
| 366 | ); |
| 367 | }); |
| 368 | setProviderCheck("button"); |
| 369 | const providersChecked = checkProviderUpdates().finally(() => setProviderCheck(null)); |
| 370 | void Promise.allSettled([appCheck, providersChecked]).then(() => setIsActionPending(false)); |
| 371 | }; |
| 372 | |
| 373 | const runEverything = async () => { |
| 374 | const bridge = window.desktopBridge; |
| 375 | setIsConfirmingEverything(false); |
| 376 | setIsActionPending(true); |
| 377 | const result = await settlePromise(() => |
| 378 | everything.run({ |
| 379 | ...(bridge && action === "download" |
| 380 | ? { |
| 381 | downloadLocal: (reportError) => |
| 382 | downloadLocalUpdate(bridge, { notifyDownloaded: false, reportError }), |
| 383 | } |
| 384 | : {}), |
| 385 | ...(bridge && action !== "none" |
| 386 | ? { installLocal: (reportError) => installLocalUpdate(bridge, reportError) } |
| 387 | : {}), |
| 388 | }), |
| 389 | ); |
| 390 | if (result._tag === "Failure") { |
| 391 | const error = squashAtomCommandFailure(result); |
| 392 | toastManager.add( |
| 393 | stackedThreadToast({ |
| 394 | type: "error", |
| 395 | title: gt("Could not update everything"), |
| 396 | description: thrownErrorMessage(error, m) ?? gt("An unexpected error occurred."), |
| 397 | }), |
| 398 | ); |
| 399 | } |
| 400 | setIsActionPending(false); |
| 401 | }; |
| 402 | |
| 403 | const handleCheckAnimationIteration = () => { |
| 404 | setIsCheckAnimationLatched( |
| 405 | shouldContinueDesktopUpdateCheckAnimation({ |
| 406 | isChecking: state?.status === "checking" || isCheckingProviders, |
| 407 | prefersReducedMotion, |
| 408 | }), |
| 409 | ); |
| 410 | }; |
| 411 | |
| 412 | if (!isElectron && !runsEverything && !isRunningEverything) return null; |
| 413 | |
| 414 | const statusIcon = ( |
| 415 | <DesktopUpdateStatusIcon |
| 416 | key={showCheckIcon ? checkAnimationKey : iconStatus} |
| 417 | downloadPercent={state?.downloadPercent ?? null} |
| 418 | isCheckAnimating={showCheckIcon && !prefersReducedMotion} |
| 419 | onCheckAnimationIteration={handleCheckAnimationIteration} |
| 420 | status={iconStatus} |
| 421 | /> |
| 422 | ); |
| 423 | const confirmDialog = ( |
| 424 | <UpdateEverythingDialog |
| 425 | open={isConfirmingEverything} |
| 426 | onOpenChange={setIsConfirmingEverything} |
| 427 | version={everything.version} |
| 428 | providerCount={everything.providerCount} |
| 429 | rows={everything.rows} |
| 430 | restarts={everything.restarts} |
| 431 | checking={providerCheck === "dialog"} |
| 432 | onConfirm={() => void runEverything()} |
| 433 | /> |
| 434 | ); |
| 435 | |
| 436 | if (run !== null) { |
| 437 | const local: UpdateRunLocalState = |
| 438 | run.localVersion === null |
| 439 | ? null |
| 440 | : state?.status === "downloading" |
| 441 | ? { status: "downloading", percent: state.downloadPercent } |
| 442 | : { status: "waiting" }; |
| 443 | return ( |
| 444 | <SidebarMenuItem className="@container/sidebar-update ml-auto flex min-w-8 flex-1"> |
| 445 | <SidebarUpdateCapsule |
| 446 | run={run} |
| 447 | local={local} |
| 448 | icon={statusIcon} |
| 449 | {...(run.localVersion === null && action === "install" && window.desktopBridge |
| 450 | ? { |
| 451 | onRestart: async () => { |
| 452 | saveUpdateEverythingResult({ |
| 453 | localVersion: localUpdateVersion, |
| 454 | updatedServers: 0, |
| 455 | updatedProviders: 0, |
| 456 | failures: [], |
| 457 | restarting: [], |
| 458 | }); |
| 459 | if (!(await installLocalUpdate(window.desktopBridge!))) { |
| 460 | clearSavedUpdateEverythingResult(); |
| 461 | } |
| 462 | }, |
| 463 | } |
| 464 | : {})} |
| 465 | /> |
| 466 | {confirmDialog} |
| 467 | </SidebarMenuItem> |
| 468 | ); |
| 469 | } |
| 470 | |
| 471 | const updateButton = ( |
| 472 | <button |
| 473 | type="button" |
| 474 | aria-label={ |
| 475 | idleTooltip?.detail |
| 476 | ? gt("{tooltip}: {detail}", { tooltip, detail: idleTooltip.detail }) |
| 477 | : tooltip |
| 478 | } |
| 479 | aria-disabled={isInteractionDisabled || undefined} |
| 480 | className={cn( |
| 481 | "inline-flex size-8 items-center justify-center rounded-full outline-hidden ring-ring transition-colors focus-visible:ring-2 focus-visible:ring-inset", |
| 482 | isInteractionDisabled ? "cursor-not-allowed" : "cursor-pointer", |
| 483 | showUpdateIconState |
| 484 | ? cn( |
| 485 | "bg-sidebar-control-surface text-sidebar-foreground", |
| 486 | !isInteractionDisabled && "hover:bg-sidebar-row-hover", |
| 487 | ) |
| 488 | : cn( |
| 489 | "text-(--sidebar-icon-color)", |
| 490 | !isInteractionDisabled && "hover:bg-sidebar-row-hover hover:text-sidebar-foreground", |
| 491 | ), |
| 492 | disabled && !showUpdateIconState && "opacity-60", |
| 493 | )} |
| 494 | onClick={handleAction} |
| 495 | onBlur={() => { |
| 496 | suppressReleaseNotesFocusOpen.current = false; |
| 497 | setReleaseNotesTriggerFocusVisible(false); |
| 498 | }} |
| 499 | onFocus={(event) => { |
| 500 | const focusVisible = event.currentTarget.matches(":focus-visible"); |
| 501 | setReleaseNotesTriggerFocusVisible(focusVisible); |
| 502 | if (!showReleaseNotesPopover || !focusVisible) return; |
| 503 | if (suppressReleaseNotesFocusOpen.current) { |
| 504 | suppressReleaseNotesFocusOpen.current = false; |
| 505 | return; |
| 506 | } |
| 507 | flushSync(() => releaseNotesPopoverHandle.open(releaseNotesTriggerId)); |
| 508 | }} |
| 509 | onKeyDown={(event) => { |
| 510 | if (!showReleaseNotesPopover) return; |
| 511 | openSidebarUpdateReleaseNotesPopoverOnForwardTab( |
| 512 | event, |
| 513 | releaseNotesPopoverHandle, |
| 514 | releaseNotesTriggerId, |
| 515 | ); |
| 516 | }} |
| 517 | > |
| 518 | {statusIcon} |
| 519 | </button> |
| 520 | ); |
| 521 | |
| 522 | return ( |
| 523 | <SidebarMenuItem className="ml-auto shrink-0"> |
| 524 | <Popover |
| 525 | handle={releaseNotesPopoverHandle} |
| 526 | open={releaseNotesOpen && showReleaseNotesPopover} |
| 527 | triggerId={releaseNotesTriggerId} |
| 528 | onOpenChange={(open, details) => { |
| 529 | if (open && !showReleaseNotesPopover) { |
| 530 | details.cancel(); |
| 531 | return; |
| 532 | } |
| 533 | handleSidebarUpdateReleaseNotesPopoverOpenChange(open, details); |
| 534 | if (!details.isCanceled) setReleaseNotesOpen(open); |
| 535 | }} |
| 536 | > |
| 537 | <Tooltip disabled={showReleaseNotesPopover}> |
| 538 | <TooltipTrigger |
| 539 | id={releaseNotesTriggerId} |
| 540 | render={ |
| 541 | <PopoverTrigger |
| 542 | {...(!showReleaseNotesPopover |
| 543 | ? { |
| 544 | "aria-controls": undefined, |
| 545 | "aria-expanded": undefined, |
| 546 | "aria-haspopup": undefined, |
| 547 | } |
| 548 | : {})} |
| 549 | closeDelay={150} |
| 550 | handle={releaseNotesPopoverHandle} |
| 551 | id={releaseNotesTriggerId} |
| 552 | openOnHover={showReleaseNotesPopover} |
| 553 | render={updateButton} |
| 554 | /> |
| 555 | } |
| 556 | /> |
| 557 | {!showReleaseNotesPopover ? ( |
| 558 | <TooltipPopup |
| 559 | align="center" |
| 560 | side="top" |
| 561 | variant={showUpdateDetails ? "glass" : "default"} |
| 562 | > |
| 563 | {idleTooltip?.detail ? ( |
| 564 | <div className="text-left"> |
| 565 | <div className="font-medium">{idleTooltip.title}</div> |
| 566 | <div className="text-muted-foreground">{idleTooltip.detail}</div> |
| 567 | </div> |
| 568 | ) : ( |
| 569 | <span className="whitespace-pre-line">{tooltip}</span> |
| 570 | )} |
| 571 | </TooltipPopup> |
| 572 | ) : null} |
| 573 | </Tooltip> |
| 574 | {showReleaseNotesPopover && state ? ( |
| 575 | <PopoverPopup |
| 576 | align="center" |
| 577 | aria-label={gt("Update release notes")} |
| 578 | initialFocus={false} |
| 579 | onKeyDownCapture={(event) => { |
| 580 | if ( |
| 581 | event.key === "Escape" && |
| 582 | releaseNotesPopupRef.current?.contains(document.activeElement) |
| 583 | ) { |
| 584 | suppressReleaseNotesFocusOpen.current = true; |
| 585 | } |
| 586 | }} |
| 587 | ref={releaseNotesPopupRef} |
| 588 | side="top" |
| 589 | tooltipStyle |
| 590 | > |
| 591 | <SidebarUpdateReleaseNotes |
| 592 | shell={window.desktopBridge} |
| 593 | state={state} |
| 594 | tooltip={tooltip} |
| 595 | /> |
| 596 | </PopoverPopup> |
| 597 | ) : null} |
| 598 | </Popover> |
| 599 | {confirmDialog} |
| 600 | </SidebarMenuItem> |
| 601 | ); |
| 602 | } |