feat(web): make advertised endpoint defaults explicit
Co-authored-by: codex <[email protected]>
This commit is contained in:
1 parent
b500b84e34
commit
722b41412e
7 files changed
+424
-82
No files matched your search
@@ -123,7 +123,11 @@ An `AdvertisedEndpoint` is a server or desktop-authored candidate endpoint for a
|
||||
|
||||
Clients should treat advertised endpoints as hints, not as proof that a route works from the current device. The final connection attempt still decides whether the endpoint is reachable.
|
||||
|
||||
Endpoint selection should prefer:
|
||||
The UI presents one default advertised endpoint in the network-access summary and keeps the rest behind an expandable advanced list. The default controls pairing QR codes and primary copy actions. Users can override it, but that override is a UI preference, not backend configuration.
|
||||
|
||||
Persist the override by stable endpoint kind rather than raw URL whenever possible. For example, a LAN endpoint should be stored as the desktop LAN endpoint preference, not as `192.168.x.y`, because the address can change when the user switches networks. Provider endpoints should use provider-specific stable keys such as Tailscale IP or Tailscale MagicDNS HTTPS. Custom endpoints may fall back to their concrete identity.
|
||||
|
||||
When no user default is saved, endpoint selection should prefer:
|
||||
|
||||
1. endpoints compatible with the hosted HTTPS app
|
||||
2. explicitly default endpoints
|
||||
|
||||
@@ -22,10 +22,12 @@ If you are already running the desktop app and want to make it reachable from ot
|
||||
|
||||
1. Open **Settings** → **Connections**.
|
||||
2. Under **Manage Local Backend**, toggle **Network access** on. This will restart the app and run the backend on all network interfaces.
|
||||
3. The settings panel will show reachable endpoints for the backend. At minimum this includes the local LAN HTTP endpoint when network access is enabled.
|
||||
3. The settings panel will show the default reachable endpoint, with a `+N` control when more endpoints are available. Expand it to inspect alternatives such as loopback, LAN, private-network, or HTTPS endpoints.
|
||||
4. Use **Create Link** to generate a pairing link you can share with another device.
|
||||
|
||||
The app chooses the best reachable endpoint for pairing links:
|
||||
The default endpoint controls the QR code and primary copy action for pairing links. You can change it from the expanded endpoint list. The preference is stored by endpoint type, so choosing the local LAN endpoint survives normal IP address changes when you move between networks.
|
||||
|
||||
When no user default is saved, the app chooses the best reachable endpoint for pairing links:
|
||||
|
||||
- HTTPS/WSS-compatible endpoints are preferred because they work from `https://app.t3.codes`.
|
||||
- Non-loopback HTTP endpoints are used for direct LAN pairing when HTTPS is not available.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { PlusIcon, QrCodeIcon } from "lucide-react";
|
||||
import { memo, useCallback, useEffect, useMemo, useState } from "react";
|
||||
import { ChevronDownIcon, PlusIcon, QrCodeIcon } from "lucide-react";
|
||||
import { type ReactNode, memo, useCallback, useEffect, useMemo, useState } from "react";
|
||||
import {
|
||||
type AuthClientSession,
|
||||
type AuthPairingLink,
|
||||
@@ -46,6 +46,8 @@ import { Switch } from "../ui/switch";
|
||||
import { stackedThreadToast, toastManager } from "../ui/toast";
|
||||
import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
|
||||
import { Button } from "../ui/button";
|
||||
import { Group, GroupSeparator } from "../ui/group";
|
||||
import { Menu, MenuItem, MenuPopup, MenuTrigger } from "../ui/menu";
|
||||
import { Textarea } from "../ui/textarea";
|
||||
import { setPairingTokenOnUrl } from "../../pairingUrl";
|
||||
import {
|
||||
@@ -69,6 +71,7 @@ import {
|
||||
reconnectSavedEnvironment,
|
||||
removeSavedEnvironment,
|
||||
} from "~/environments/runtime";
|
||||
import { useUiStateStore } from "~/uiStateStore";
|
||||
|
||||
const accessTimestampFormatter = new Intl.DateTimeFormat(undefined, {
|
||||
dateStyle: "medium",
|
||||
@@ -164,6 +167,7 @@ function getSavedBackendStatusTooltip(
|
||||
|
||||
/** Direct row in the card – same pattern as the Provider / ACP-agent list rows. */
|
||||
const ITEM_ROW_CLASSNAME = "border-t border-border/60 px-4 py-4 first:border-t-0 sm:px-5";
|
||||
const ENDPOINT_ROW_CLASSNAME = "border-t border-border/60 px-4 py-2.5 first:border-t-0 sm:px-5";
|
||||
|
||||
const ITEM_ROW_INNER_CLASSNAME =
|
||||
"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between";
|
||||
@@ -247,8 +251,17 @@ function removeDesktopClientSession(
|
||||
|
||||
function selectPairingEndpoint(
|
||||
endpoints: ReadonlyArray<AdvertisedEndpoint>,
|
||||
defaultEndpointKey?: string | null,
|
||||
): AdvertisedEndpoint | null {
|
||||
const availableEndpoints = endpoints.filter((endpoint) => endpoint.status !== "unavailable");
|
||||
if (defaultEndpointKey) {
|
||||
const selectedEndpoint = availableEndpoints.find(
|
||||
(endpoint) => endpointDefaultPreferenceKey(endpoint) === defaultEndpointKey,
|
||||
);
|
||||
if (selectedEndpoint) {
|
||||
return selectedEndpoint;
|
||||
}
|
||||
}
|
||||
return (
|
||||
availableEndpoints.find((endpoint) => endpoint.compatibility.hostedHttpsApp === "compatible") ??
|
||||
availableEndpoints.find((endpoint) => endpoint.isDefault) ??
|
||||
@@ -257,6 +270,30 @@ function selectPairingEndpoint(
|
||||
);
|
||||
}
|
||||
|
||||
function endpointDefaultPreferenceKey(endpoint: AdvertisedEndpoint): string {
|
||||
if (endpoint.id.startsWith("desktop-loopback:")) {
|
||||
return "desktop-core:loopback:http";
|
||||
}
|
||||
if (endpoint.id.startsWith("desktop-lan:")) {
|
||||
return "desktop-core:lan:http";
|
||||
}
|
||||
if (endpoint.id.startsWith("tailscale-ip:")) {
|
||||
return "tailscale:ip:http";
|
||||
}
|
||||
if (endpoint.id.startsWith("tailscale-magicdns:")) {
|
||||
return "tailscale:magicdns:https";
|
||||
}
|
||||
|
||||
let scheme = "unknown";
|
||||
try {
|
||||
scheme = new URL(endpoint.httpBaseUrl).protocol.replace(/:$/u, "");
|
||||
} catch {
|
||||
// Keep the stored preference stable even if a custom endpoint is malformed.
|
||||
}
|
||||
|
||||
return `${endpoint.provider.id}:${endpoint.reachability}:${scheme}:${endpoint.label}`;
|
||||
}
|
||||
|
||||
function resolveAdvertisedEndpointPairingUrl(
|
||||
endpoint: AdvertisedEndpoint,
|
||||
credential: string,
|
||||
@@ -279,6 +316,7 @@ type PairingLinkListRowProps = {
|
||||
pairingLink: ServerPairingLinkRecord;
|
||||
endpointUrl: string | null | undefined;
|
||||
endpoints: ReadonlyArray<AdvertisedEndpoint>;
|
||||
defaultEndpointKey: string | null;
|
||||
revokingPairingLinkId: string | null;
|
||||
onRevoke: (id: string) => void;
|
||||
};
|
||||
@@ -287,6 +325,7 @@ const PairingLinkListRow = memo(function PairingLinkListRow({
|
||||
pairingLink,
|
||||
endpointUrl,
|
||||
endpoints,
|
||||
defaultEndpointKey,
|
||||
revokingPairingLinkId,
|
||||
onRevoke,
|
||||
}: PairingLinkListRowProps) {
|
||||
@@ -309,9 +348,20 @@ const PairingLinkListRow = memo(function PairingLinkListRow({
|
||||
[endpointUrl, pairingLink.credential],
|
||||
);
|
||||
const endpointPairingUrl = useMemo(() => {
|
||||
const endpoint = selectPairingEndpoint(endpoints);
|
||||
const endpoint = selectPairingEndpoint(endpoints, defaultEndpointKey);
|
||||
return endpoint ? resolveAdvertisedEndpointPairingUrl(endpoint, pairingLink.credential) : null;
|
||||
}, [endpoints, pairingLink.credential]);
|
||||
}, [defaultEndpointKey, endpoints, pairingLink.credential]);
|
||||
const endpointCopyOptions = useMemo(
|
||||
() =>
|
||||
endpoints
|
||||
.filter((endpoint) => endpoint.status !== "unavailable")
|
||||
.map((endpoint) => ({
|
||||
key: endpointDefaultPreferenceKey(endpoint),
|
||||
label: endpoint.label,
|
||||
url: resolveAdvertisedEndpointPairingUrl(endpoint, pairingLink.credential),
|
||||
})),
|
||||
[endpoints, pairingLink.credential],
|
||||
);
|
||||
const shareablePairingUrl =
|
||||
endpointPairingUrl ??
|
||||
(endpointUrl != null && endpointUrl !== ""
|
||||
@@ -319,37 +369,54 @@ const PairingLinkListRow = memo(function PairingLinkListRow({
|
||||
: isLoopbackHostname(window.location.hostname)
|
||||
? null
|
||||
: currentOriginPairingUrl);
|
||||
const copyValue = shareablePairingUrl ?? pairingLink.credential;
|
||||
const revealValue = shareablePairingUrl ?? pairingLink.credential;
|
||||
const canCopyToClipboard =
|
||||
typeof window !== "undefined" &&
|
||||
window.isSecureContext &&
|
||||
navigator.clipboard?.writeText != null;
|
||||
|
||||
const { copyToClipboard, isCopied } = useCopyToClipboard({
|
||||
onCopy: () => {
|
||||
const { copyToClipboard } = useCopyToClipboard<"code" | "link">({
|
||||
onCopy: (kind) => {
|
||||
toastManager.add({
|
||||
type: "success",
|
||||
title: shareablePairingUrl ? "Pairing URL copied" : "Pairing token copied",
|
||||
description: shareablePairingUrl
|
||||
? "Open it in the client you want to pair to this environment."
|
||||
: "Paste it into another client with this backend's reachable host.",
|
||||
title: kind === "link" ? "Pairing URL copied" : "Pairing code copied",
|
||||
description:
|
||||
kind === "link"
|
||||
? "Open it in the client you want to pair to this environment."
|
||||
: "Paste it into another client to finish pairing.",
|
||||
});
|
||||
},
|
||||
onError: (error) => {
|
||||
onError: (error, kind) => {
|
||||
setIsRevealDialogOpen(true);
|
||||
toastManager.add(
|
||||
stackedThreadToast({
|
||||
type: "error",
|
||||
title: canCopyToClipboard ? "Could not copy pairing URL" : "Clipboard copy unavailable",
|
||||
title: canCopyToClipboard
|
||||
? kind === "link"
|
||||
? "Could not copy pairing URL"
|
||||
: "Could not copy pairing code"
|
||||
: "Clipboard copy unavailable",
|
||||
description: canCopyToClipboard ? error.message : "Showing the full value instead.",
|
||||
}),
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
const handleCopy = useCallback(() => {
|
||||
copyToClipboard(copyValue, undefined);
|
||||
}, [copyToClipboard, copyValue]);
|
||||
const copyPairingValue = useCallback(
|
||||
(value: string, kind: "code" | "link") => {
|
||||
copyToClipboard(value, kind);
|
||||
},
|
||||
[copyToClipboard],
|
||||
);
|
||||
|
||||
const handleCopyCode = useCallback(() => {
|
||||
copyPairingValue(pairingLink.credential, "code");
|
||||
}, [copyPairingValue, pairingLink.credential]);
|
||||
|
||||
const handleCopyDefaultLink = useCallback(() => {
|
||||
if (!shareablePairingUrl) return;
|
||||
copyPairingValue(shareablePairingUrl, "link");
|
||||
}, [copyPairingValue, shareablePairingUrl]);
|
||||
|
||||
const expiresAbsolute = formatAccessTimestamp(pairingLink.expiresAt);
|
||||
|
||||
@@ -412,27 +479,71 @@ const PairingLinkListRow = memo(function PairingLinkListRow({
|
||||
<div className="flex w-full shrink-0 items-center gap-2 sm:w-auto sm:justify-end">
|
||||
<Dialog open={isRevealDialogOpen} onOpenChange={setIsRevealDialogOpen}>
|
||||
{canCopyToClipboard ? (
|
||||
<Button size="xs" variant="outline" onClick={handleCopy}>
|
||||
{isCopied ? "Copied" : shareablePairingUrl ? "Copy" : "Copy token"}
|
||||
</Button>
|
||||
<>
|
||||
<Button size="xs" variant="outline" onClick={handleCopyCode}>
|
||||
Copy code
|
||||
</Button>
|
||||
{shareablePairingUrl ? (
|
||||
endpointCopyOptions.length > 1 ? (
|
||||
<Group aria-label="Copy pairing URL">
|
||||
<Button size="xs" variant="outline" onClick={handleCopyDefaultLink}>
|
||||
Copy pairing URL
|
||||
</Button>
|
||||
<GroupSeparator />
|
||||
<Menu>
|
||||
<MenuTrigger
|
||||
render={
|
||||
<Button
|
||||
size="icon-xs"
|
||||
variant="outline"
|
||||
aria-label="Pairing URL copy options"
|
||||
/>
|
||||
}
|
||||
>
|
||||
<ChevronDownIcon className="size-3.5" />
|
||||
</MenuTrigger>
|
||||
<MenuPopup align="end" className="min-w-52">
|
||||
{endpointCopyOptions.map((option) => (
|
||||
<MenuItem
|
||||
key={option.key}
|
||||
onClick={() => copyPairingValue(option.url, "link")}
|
||||
>
|
||||
<span className="min-w-0 flex-1">
|
||||
<span className="block truncate">{option.label}</span>
|
||||
<span className="block truncate text-[11px] text-muted-foreground">
|
||||
Pairing URL
|
||||
</span>
|
||||
</span>
|
||||
</MenuItem>
|
||||
))}
|
||||
</MenuPopup>
|
||||
</Menu>
|
||||
</Group>
|
||||
) : (
|
||||
<Button size="xs" variant="outline" onClick={handleCopyDefaultLink}>
|
||||
Copy pairing URL
|
||||
</Button>
|
||||
)
|
||||
) : null}
|
||||
</>
|
||||
) : (
|
||||
<DialogTrigger render={<Button size="xs" variant="outline" />}>
|
||||
{shareablePairingUrl ? "Show link" : "Show token"}
|
||||
{shareablePairingUrl ? "Show link" : "Show code"}
|
||||
</DialogTrigger>
|
||||
)}
|
||||
<DialogPopup className="max-w-md">
|
||||
<DialogHeader>
|
||||
<DialogTitle>{shareablePairingUrl ? "Pairing link" : "Pairing token"}</DialogTitle>
|
||||
<DialogTitle>{shareablePairingUrl ? "Pairing link" : "Pairing code"}</DialogTitle>
|
||||
<DialogDescription>
|
||||
{shareablePairingUrl
|
||||
? "Clipboard copy is unavailable here. Open or manually copy this full pairing URL on the device you want to connect."
|
||||
: "Clipboard copy is unavailable here. Manually copy this token and pair from another client using this backend's reachable host."}
|
||||
: "Clipboard copy is unavailable here. Manually copy this code into another client."}
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
<DialogPanel className="space-y-4">
|
||||
<Textarea
|
||||
readOnly
|
||||
value={copyValue}
|
||||
value={revealValue}
|
||||
rows={shareablePairingUrl ? 4 : 3}
|
||||
className="text-xs leading-relaxed"
|
||||
onFocus={(event) => event.currentTarget.select()}
|
||||
@@ -455,8 +566,8 @@ const PairingLinkListRow = memo(function PairingLinkListRow({
|
||||
Done
|
||||
</Button>
|
||||
{canCopyToClipboard ? (
|
||||
<Button variant="outline" size="xs" onClick={handleCopy}>
|
||||
{isCopied ? "Copied" : "Copy again"}
|
||||
<Button variant="outline" size="xs" onClick={handleCopyCode}>
|
||||
Copy code
|
||||
</Button>
|
||||
) : null}
|
||||
</DialogFooter>
|
||||
@@ -656,6 +767,7 @@ const AuthorizedClientsHeaderAction = memo(function AuthorizedClientsHeaderActio
|
||||
type PairingClientsListProps = {
|
||||
endpointUrl: string | null | undefined;
|
||||
endpoints: ReadonlyArray<AdvertisedEndpoint>;
|
||||
defaultEndpointKey: string | null;
|
||||
isLoading: boolean;
|
||||
pairingLinks: ReadonlyArray<ServerPairingLinkRecord>;
|
||||
clientSessions: ReadonlyArray<ServerClientSessionRecord>;
|
||||
@@ -668,6 +780,7 @@ type PairingClientsListProps = {
|
||||
const PairingClientsList = memo(function PairingClientsList({
|
||||
endpointUrl,
|
||||
endpoints,
|
||||
defaultEndpointKey,
|
||||
isLoading,
|
||||
pairingLinks,
|
||||
clientSessions,
|
||||
@@ -684,6 +797,7 @@ const PairingClientsList = memo(function PairingClientsList({
|
||||
pairingLink={pairingLink}
|
||||
endpointUrl={endpointUrl}
|
||||
endpoints={endpoints}
|
||||
defaultEndpointKey={defaultEndpointKey}
|
||||
revokingPairingLinkId={revokingPairingLinkId}
|
||||
onRevoke={onRevokePairingLink}
|
||||
/>
|
||||
@@ -709,56 +823,80 @@ const PairingClientsList = memo(function PairingClientsList({
|
||||
|
||||
type AdvertisedEndpointListRowProps = {
|
||||
endpoint: AdvertisedEndpoint;
|
||||
};
|
||||
|
||||
const endpointCompatibilityLabel = (endpoint: AdvertisedEndpoint): string => {
|
||||
if (endpoint.compatibility.hostedHttpsApp === "compatible") {
|
||||
return "Works with hosted app";
|
||||
}
|
||||
if (endpoint.compatibility.hostedHttpsApp === "mixed-content-blocked") {
|
||||
return "Desktop or direct browser only";
|
||||
}
|
||||
if (endpoint.compatibility.hostedHttpsApp === "requires-configuration") {
|
||||
return "Needs HTTPS setup";
|
||||
}
|
||||
return "Compatibility unknown";
|
||||
isDefault: boolean;
|
||||
onSetDefault: (endpoint: AdvertisedEndpoint) => void;
|
||||
};
|
||||
|
||||
const AdvertisedEndpointListRow = memo(function AdvertisedEndpointListRow({
|
||||
endpoint,
|
||||
isDefault,
|
||||
onSetDefault,
|
||||
}: AdvertisedEndpointListRowProps) {
|
||||
return (
|
||||
<div className={ITEM_ROW_CLASSNAME}>
|
||||
<div className={ITEM_ROW_INNER_CLASSNAME}>
|
||||
<div className="min-w-0 flex-1 space-y-1">
|
||||
<div className="flex min-h-5 items-center gap-1.5">
|
||||
<ConnectionStatusDot
|
||||
tooltipText={`${endpoint.provider.label} · ${endpoint.reachability}`}
|
||||
dotClassName={
|
||||
endpoint.compatibility.hostedHttpsApp === "compatible"
|
||||
? "bg-success"
|
||||
: "bg-muted-foreground/40"
|
||||
}
|
||||
/>
|
||||
<h3 className="text-sm font-medium text-foreground">{endpoint.label}</h3>
|
||||
{endpoint.provider.isAddon ? (
|
||||
<span className="rounded-md border border-border/50 bg-muted/50 px-1 py-0.5 text-[10px] text-muted-foreground/80">
|
||||
Add-on
|
||||
</span>
|
||||
) : null}
|
||||
</div>
|
||||
<p className="truncate text-xs text-muted-foreground" title={endpoint.httpBaseUrl}>
|
||||
<div className={ENDPOINT_ROW_CLASSNAME}>
|
||||
<div className="flex min-h-6 min-w-0 flex-col gap-2 sm:-my-0.5 sm:flex-row sm:items-center">
|
||||
<div className="flex min-w-0 items-baseline gap-3">
|
||||
<h3 className="shrink-0 text-sm leading-5 font-medium text-foreground">
|
||||
{endpoint.label}
|
||||
</h3>
|
||||
<p
|
||||
className="min-w-0 truncate text-xs leading-5 text-muted-foreground"
|
||||
title={endpoint.httpBaseUrl}
|
||||
>
|
||||
{endpoint.httpBaseUrl}
|
||||
</p>
|
||||
</div>
|
||||
<p className="shrink-0 text-xs text-muted-foreground">
|
||||
{endpointCompatibilityLabel(endpoint)}
|
||||
</p>
|
||||
<div className="ml-auto flex min-h-6 shrink-0 items-center justify-end gap-2">
|
||||
{isDefault ? (
|
||||
<span className="rounded-md border border-primary/30 bg-primary/10 px-1 py-0.5 text-[10px] text-primary">
|
||||
Default
|
||||
</span>
|
||||
) : null}
|
||||
{!isDefault ? (
|
||||
<Button size="xs" variant="outline" onClick={() => onSetDefault(endpoint)}>
|
||||
Set as default
|
||||
</Button>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
});
|
||||
|
||||
function NetworkAccessDescription({
|
||||
endpoint,
|
||||
hiddenEndpointCount,
|
||||
expanded,
|
||||
onToggleExpanded,
|
||||
fallback,
|
||||
}: {
|
||||
endpoint: AdvertisedEndpoint | null;
|
||||
hiddenEndpointCount: number;
|
||||
expanded: boolean;
|
||||
onToggleExpanded: () => void;
|
||||
fallback: ReactNode;
|
||||
}) {
|
||||
if (!endpoint) {
|
||||
return fallback;
|
||||
}
|
||||
|
||||
return (
|
||||
<span className="flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1">
|
||||
<span className="min-w-0 truncate">Reachable at {endpoint.httpBaseUrl}</span>
|
||||
{hiddenEndpointCount > 0 ? (
|
||||
<button
|
||||
type="button"
|
||||
className="inline-flex h-5 shrink-0 items-center rounded-md border border-border/60 px-1.5 text-[11px] font-medium text-muted-foreground hover:bg-accent hover:text-foreground"
|
||||
onClick={onToggleExpanded}
|
||||
aria-expanded={expanded}
|
||||
>
|
||||
{expanded ? "Hide" : `+${hiddenEndpointCount}`}
|
||||
</button>
|
||||
) : null}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
type SavedBackendListRowProps = {
|
||||
environmentId: EnvironmentId;
|
||||
reconnectingEnvironmentId: EnvironmentId | null;
|
||||
@@ -903,6 +1041,13 @@ export function ConnectionsSettings() {
|
||||
const [pendingDesktopServerExposureMode, setPendingDesktopServerExposureMode] = useState<
|
||||
DesktopServerExposureState["mode"] | null
|
||||
>(null);
|
||||
const [isAdvertisedEndpointListExpanded, setIsAdvertisedEndpointListExpanded] = useState(false);
|
||||
const defaultAdvertisedEndpointKey = useUiStateStore(
|
||||
(state) => state.defaultAdvertisedEndpointKey,
|
||||
);
|
||||
const setDefaultAdvertisedEndpointKey = useUiStateStore(
|
||||
(state) => state.setDefaultAdvertisedEndpointKey,
|
||||
);
|
||||
const canManageLocalBackend = currentSessionRole === "owner";
|
||||
const isLocalBackendNetworkAccessible = desktopBridge
|
||||
? desktopServerExposureState?.mode === "network-accessible"
|
||||
@@ -1236,9 +1381,23 @@ export function ConnectionsSettings() {
|
||||
() => desktopPairingLinks.filter((pairingLink) => pairingLink.role === "client"),
|
||||
[desktopPairingLinks],
|
||||
);
|
||||
const visibleDesktopAdvertisedEndpoints = isLocalBackendNetworkAccessible
|
||||
? desktopAdvertisedEndpoints
|
||||
: [];
|
||||
const visibleDesktopAdvertisedEndpoints = useMemo(
|
||||
() => (isLocalBackendNetworkAccessible ? desktopAdvertisedEndpoints : []),
|
||||
[desktopAdvertisedEndpoints, isLocalBackendNetworkAccessible],
|
||||
);
|
||||
const defaultDesktopAdvertisedEndpoint = useMemo(
|
||||
() => selectPairingEndpoint(visibleDesktopAdvertisedEndpoints, defaultAdvertisedEndpointKey),
|
||||
[defaultAdvertisedEndpointKey, visibleDesktopAdvertisedEndpoints],
|
||||
);
|
||||
const defaultDesktopAdvertisedEndpointKey = defaultDesktopAdvertisedEndpoint
|
||||
? endpointDefaultPreferenceKey(defaultDesktopAdvertisedEndpoint)
|
||||
: null;
|
||||
const handleSetDefaultAdvertisedEndpoint = useCallback(
|
||||
(endpoint: AdvertisedEndpoint) => {
|
||||
setDefaultAdvertisedEndpointKey(endpointDefaultPreferenceKey(endpoint));
|
||||
},
|
||||
[setDefaultAdvertisedEndpointKey],
|
||||
);
|
||||
return (
|
||||
<SettingsPageContainer>
|
||||
{canManageLocalBackend ? (
|
||||
@@ -1249,15 +1408,30 @@ export function ConnectionsSettings() {
|
||||
<SettingsRow
|
||||
title="Network access"
|
||||
description={
|
||||
desktopServerExposureState?.endpointUrl
|
||||
? `Reachable at ${desktopServerExposureState.endpointUrl}`
|
||||
: desktopServerExposureState?.mode === "network-accessible"
|
||||
? desktopServerExposureState.advertisedHost
|
||||
? `Exposed on all interfaces. Pairing links use ${desktopServerExposureState.advertisedHost}.`
|
||||
: "Exposed on all interfaces."
|
||||
: desktopServerExposureState
|
||||
? "Limited to this machine."
|
||||
: "Loading…"
|
||||
isLocalBackendNetworkAccessible ? (
|
||||
<NetworkAccessDescription
|
||||
endpoint={defaultDesktopAdvertisedEndpoint}
|
||||
hiddenEndpointCount={Math.max(
|
||||
visibleDesktopAdvertisedEndpoints.length - 1,
|
||||
0,
|
||||
)}
|
||||
expanded={isAdvertisedEndpointListExpanded}
|
||||
onToggleExpanded={() =>
|
||||
setIsAdvertisedEndpointListExpanded((expanded) => !expanded)
|
||||
}
|
||||
fallback={
|
||||
desktopServerExposureState?.endpointUrl
|
||||
? `Reachable at ${desktopServerExposureState.endpointUrl}`
|
||||
: desktopServerExposureState?.advertisedHost
|
||||
? `Exposed on all interfaces. Pairing links use ${desktopServerExposureState.advertisedHost}.`
|
||||
: "Exposed on all interfaces."
|
||||
}
|
||||
/>
|
||||
) : desktopServerExposureState ? (
|
||||
"Limited to this machine."
|
||||
) : (
|
||||
"Loading…"
|
||||
)
|
||||
}
|
||||
status={
|
||||
desktopServerExposureError ? (
|
||||
@@ -1330,9 +1504,19 @@ export function ConnectionsSettings() {
|
||||
</AlertDialog>
|
||||
}
|
||||
/>
|
||||
{visibleDesktopAdvertisedEndpoints.map((endpoint) => (
|
||||
<AdvertisedEndpointListRow key={endpoint.id} endpoint={endpoint} />
|
||||
))}
|
||||
{isAdvertisedEndpointListExpanded
|
||||
? visibleDesktopAdvertisedEndpoints.map((endpoint) => {
|
||||
const endpointKey = endpointDefaultPreferenceKey(endpoint);
|
||||
return (
|
||||
<AdvertisedEndpointListRow
|
||||
key={endpoint.id}
|
||||
endpoint={endpoint}
|
||||
isDefault={endpointKey === defaultDesktopAdvertisedEndpointKey}
|
||||
onSetDefault={handleSetDefaultAdvertisedEndpoint}
|
||||
/>
|
||||
);
|
||||
})
|
||||
: null}
|
||||
</>
|
||||
) : (
|
||||
<SettingsRow
|
||||
@@ -1384,6 +1568,7 @@ export function ConnectionsSettings() {
|
||||
<PairingClientsList
|
||||
endpointUrl={desktopServerExposureState?.endpointUrl}
|
||||
endpoints={visibleDesktopAdvertisedEndpoints}
|
||||
defaultEndpointKey={defaultDesktopAdvertisedEndpointKey}
|
||||
isLoading={isLoadingDesktopAccessManagement}
|
||||
pairingLinks={visibleDesktopPairingLinks}
|
||||
clientSessions={desktopClientSessions}
|
||||
|
||||
@@ -20,6 +20,7 @@ import { render } from "vitest-browser-react";
|
||||
import { __resetLocalApiForTests } from "../../localApi";
|
||||
import { AppAtomRegistryProvider } from "../../rpc/atomRegistry";
|
||||
import { resetServerStateForTests, setServerConfigSnapshot } from "../../rpc/serverState";
|
||||
import { useUiStateStore } from "../../uiStateStore";
|
||||
import { ConnectionsSettings } from "./ConnectionsSettings";
|
||||
import { GeneralSettingsPanel } from "./SettingsPanels";
|
||||
|
||||
@@ -345,6 +346,7 @@ describe("GeneralSettingsPanel observability", () => {
|
||||
resetServerStateForTests();
|
||||
await __resetLocalApiForTests();
|
||||
localStorage.clear();
|
||||
useUiStateStore.setState({ defaultAdvertisedEndpointKey: null });
|
||||
authAccessHarness.reset();
|
||||
});
|
||||
|
||||
@@ -501,6 +503,104 @@ describe("GeneralSettingsPanel observability", () => {
|
||||
.not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("collapses advertised endpoints behind the network access summary", async () => {
|
||||
window.desktopBridge = createDesktopBridgeStub({
|
||||
serverExposureState: {
|
||||
mode: "network-accessible",
|
||||
endpointUrl: "http://192.168.86.39:3773",
|
||||
advertisedHost: "192.168.86.39",
|
||||
},
|
||||
advertisedEndpoints: [
|
||||
{
|
||||
id: "desktop-loopback:3773",
|
||||
label: "This machine",
|
||||
provider: {
|
||||
id: "desktop-core",
|
||||
label: "Desktop",
|
||||
kind: "manual",
|
||||
isAddon: false,
|
||||
},
|
||||
httpBaseUrl: "http://127.0.0.1:3773/",
|
||||
wsBaseUrl: "ws://127.0.0.1:3773/",
|
||||
reachability: "loopback",
|
||||
compatibility: {
|
||||
hostedHttpsApp: "mixed-content-blocked",
|
||||
desktopApp: "compatible",
|
||||
},
|
||||
source: "desktop-core",
|
||||
status: "available",
|
||||
},
|
||||
{
|
||||
id: "desktop-lan:http://192.168.86.39:3773",
|
||||
label: "Local network",
|
||||
provider: {
|
||||
id: "desktop-core",
|
||||
label: "Desktop",
|
||||
kind: "manual",
|
||||
isAddon: false,
|
||||
},
|
||||
httpBaseUrl: "http://192.168.86.39:3773/",
|
||||
wsBaseUrl: "ws://192.168.86.39:3773/",
|
||||
reachability: "lan",
|
||||
compatibility: {
|
||||
hostedHttpsApp: "mixed-content-blocked",
|
||||
desktopApp: "compatible",
|
||||
},
|
||||
source: "desktop-core",
|
||||
status: "available",
|
||||
isDefault: true,
|
||||
},
|
||||
{
|
||||
id: "tailscale-ip:http://100.105.39.17:3773",
|
||||
label: "Tailscale IP",
|
||||
provider: {
|
||||
id: "tailscale",
|
||||
label: "Tailscale",
|
||||
kind: "private-network",
|
||||
isAddon: true,
|
||||
},
|
||||
httpBaseUrl: "http://100.105.39.17:3773/",
|
||||
wsBaseUrl: "ws://100.105.39.17:3773/",
|
||||
reachability: "private-network",
|
||||
compatibility: {
|
||||
hostedHttpsApp: "mixed-content-blocked",
|
||||
desktopApp: "compatible",
|
||||
},
|
||||
source: "desktop-addon",
|
||||
status: "available",
|
||||
},
|
||||
],
|
||||
});
|
||||
authAccessHarness.setSnapshot({
|
||||
pairingLinks: [],
|
||||
clientSessions: [],
|
||||
});
|
||||
setServerConfigSnapshot(createBaseServerConfig());
|
||||
|
||||
mounted = await render(
|
||||
<AppAtomRegistryProvider>
|
||||
<ConnectionsSettings />
|
||||
</AppAtomRegistryProvider>,
|
||||
);
|
||||
|
||||
await expect
|
||||
.element(page.getByText("Reachable at http://192.168.86.39:3773/"))
|
||||
.toBeInTheDocument();
|
||||
await expect.element(page.getByRole("button", { name: "+2" })).toBeInTheDocument();
|
||||
await expect
|
||||
.element(page.getByRole("heading", { name: "Local network", exact: true }))
|
||||
.not.toBeInTheDocument();
|
||||
|
||||
await page.getByRole("button", { name: "+2" }).click();
|
||||
|
||||
await expect
|
||||
.element(page.getByRole("heading", { name: "Local network", exact: true }))
|
||||
.toBeInTheDocument();
|
||||
await expect.element(page.getByText("Default", { exact: true })).toBeInTheDocument();
|
||||
await page.getByRole("button", { name: "Set as default" }).first().click();
|
||||
await expect.element(page.getByText("Reachable at http://127.0.0.1:3773/")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("shows diagnostics inside About with a single logs-folder action", async () => {
|
||||
setServerConfigSnapshot(createBaseServerConfig());
|
||||
|
||||
@@ -636,7 +736,7 @@ describe("GeneralSettingsPanel observability", () => {
|
||||
.element(page.getByText("Client · Mobile · iOS · Safari · 192.168.1.88"))
|
||||
.toBeInTheDocument();
|
||||
await expect
|
||||
.element(page.getByRole("button", { name: /^(Copy|Show link)$/ }))
|
||||
.element(page.getByRole("button", { name: /^(Copy code|Show link)$/ }))
|
||||
.toBeInTheDocument();
|
||||
await expect.element(page.getByText("Revoke others")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
@@ -52,7 +52,7 @@ export function SettingsRow({
|
||||
children,
|
||||
}: {
|
||||
title: ReactNode;
|
||||
description: string;
|
||||
description: ReactNode;
|
||||
status?: ReactNode;
|
||||
resetAction?: ReactNode;
|
||||
control?: ReactNode;
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
type PersistedUiState,
|
||||
persistState,
|
||||
reorderProjects,
|
||||
setDefaultAdvertisedEndpointKey,
|
||||
setProjectExpanded,
|
||||
setThreadChangedFilesExpanded,
|
||||
syncProjects,
|
||||
@@ -22,6 +23,7 @@ function makeUiState(overrides: Partial<UiState> = {}): UiState {
|
||||
projectOrder: [],
|
||||
threadLastVisitedAtById: {},
|
||||
threadChangedFilesExpandedById: {},
|
||||
defaultAdvertisedEndpointKey: null,
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
@@ -79,6 +81,18 @@ describe("uiStateStore pure functions", () => {
|
||||
expect(next).toBe(initialState);
|
||||
});
|
||||
|
||||
it("setDefaultAdvertisedEndpointKey stores endpoint preference by stable key", () => {
|
||||
const initialState = makeUiState();
|
||||
|
||||
const next = setDefaultAdvertisedEndpointKey(initialState, "desktop-core:lan:http");
|
||||
|
||||
expect(next.defaultAdvertisedEndpointKey).toBe("desktop-core:lan:http");
|
||||
expect(setDefaultAdvertisedEndpointKey(next, "desktop-core:lan:http")).toBe(next);
|
||||
expect(setDefaultAdvertisedEndpointKey(next, "")).toMatchObject({
|
||||
defaultAdvertisedEndpointKey: null,
|
||||
});
|
||||
});
|
||||
|
||||
it("reorderProjects moves all member keys of a multi-member group together", () => {
|
||||
const keyALocal = "env-local:proj-a";
|
||||
const keyARemote = "env-remote:proj-a";
|
||||
@@ -531,6 +545,17 @@ describe("uiStateStore persistence round-trip", () => {
|
||||
expect(rehydrated.projectOrder).toEqual([projectC.key, projectA.key, projectB.key]);
|
||||
});
|
||||
|
||||
it("persists the default advertised endpoint preference", () => {
|
||||
const state = setDefaultAdvertisedEndpointKey(makeUiState(), "desktop-core:lan:http");
|
||||
|
||||
persistState(state);
|
||||
|
||||
const persisted = JSON.parse(
|
||||
localStorageStub.getItem(PERSISTED_STATE_KEY) ?? "{}",
|
||||
) as PersistedUiState;
|
||||
expect(persisted.defaultAdvertisedEndpointKey).toBe("desktop-core:lan:http");
|
||||
});
|
||||
|
||||
it("preserves expand state across restart when project's logical key changes", () => {
|
||||
// After restart, in-memory previousExpandedById is empty, so the
|
||||
// previousLogicalKey-to-state bridge in syncProjects cannot help. The
|
||||
|
||||
@@ -19,6 +19,7 @@ export interface PersistedUiState {
|
||||
collapsedProjectCwds?: string[];
|
||||
expandedProjectCwds?: string[];
|
||||
projectOrderCwds?: string[];
|
||||
defaultAdvertisedEndpointKey?: string | null;
|
||||
threadChangedFilesExpandedById?: Record<string, Record<string, boolean>>;
|
||||
}
|
||||
|
||||
@@ -32,7 +33,11 @@ export interface UiThreadState {
|
||||
threadChangedFilesExpandedById: Record<string, Record<string, boolean>>;
|
||||
}
|
||||
|
||||
export interface UiState extends UiProjectState, UiThreadState {}
|
||||
export interface UiEndpointState {
|
||||
defaultAdvertisedEndpointKey: string | null;
|
||||
}
|
||||
|
||||
export interface UiState extends UiProjectState, UiThreadState, UiEndpointState {}
|
||||
|
||||
export interface SyncProjectInput {
|
||||
/** Physical project key (env + cwd). Used for manual sort order. */
|
||||
@@ -52,6 +57,7 @@ const initialState: UiState = {
|
||||
projectOrder: [],
|
||||
threadLastVisitedAtById: {},
|
||||
threadChangedFilesExpandedById: {},
|
||||
defaultAdvertisedEndpointKey: null,
|
||||
};
|
||||
|
||||
const persistedCollapsedProjectCwds = new Set<string>();
|
||||
@@ -88,6 +94,11 @@ function readPersistedState(): UiState {
|
||||
hydratePersistedProjectState(parsed);
|
||||
return {
|
||||
...initialState,
|
||||
defaultAdvertisedEndpointKey:
|
||||
typeof parsed.defaultAdvertisedEndpointKey === "string" &&
|
||||
parsed.defaultAdvertisedEndpointKey.length > 0
|
||||
? parsed.defaultAdvertisedEndpointKey
|
||||
: null,
|
||||
threadChangedFilesExpandedById: sanitizePersistedThreadChangedFilesExpanded(
|
||||
parsed.threadChangedFilesExpandedById,
|
||||
),
|
||||
@@ -179,6 +190,7 @@ export function persistState(state: UiState): void {
|
||||
collapsedProjectCwds,
|
||||
expandedProjectCwds,
|
||||
projectOrderCwds,
|
||||
defaultAdvertisedEndpointKey: state.defaultAdvertisedEndpointKey,
|
||||
threadChangedFilesExpandedById,
|
||||
} satisfies PersistedUiState),
|
||||
);
|
||||
@@ -532,6 +544,17 @@ export function setThreadChangedFilesExpanded(
|
||||
};
|
||||
}
|
||||
|
||||
export function setDefaultAdvertisedEndpointKey(state: UiState, key: string | null): UiState {
|
||||
const nextKey = key && key.length > 0 ? key : null;
|
||||
if (state.defaultAdvertisedEndpointKey === nextKey) {
|
||||
return state;
|
||||
}
|
||||
return {
|
||||
...state,
|
||||
defaultAdvertisedEndpointKey: nextKey,
|
||||
};
|
||||
}
|
||||
|
||||
export function toggleProject(state: UiState, projectId: string): UiState {
|
||||
const expanded = state.projectExpandedById[projectId] ?? true;
|
||||
return {
|
||||
@@ -606,6 +629,7 @@ interface UiStateStore extends UiState {
|
||||
markThreadUnread: (threadId: string, latestTurnCompletedAt: string | null | undefined) => void;
|
||||
clearThreadUi: (threadId: string) => void;
|
||||
setThreadChangedFilesExpanded: (threadId: string, turnId: string, expanded: boolean) => void;
|
||||
setDefaultAdvertisedEndpointKey: (key: string | null) => void;
|
||||
toggleProject: (projectId: string) => void;
|
||||
setProjectExpanded: (projectId: string, expanded: boolean) => void;
|
||||
reorderProjects: (
|
||||
@@ -625,6 +649,8 @@ export const useUiStateStore = create<UiStateStore>((set) => ({
|
||||
clearThreadUi: (threadId) => set((state) => clearThreadUi(state, threadId)),
|
||||
setThreadChangedFilesExpanded: (threadId, turnId, expanded) =>
|
||||
set((state) => setThreadChangedFilesExpanded(state, threadId, turnId, expanded)),
|
||||
setDefaultAdvertisedEndpointKey: (key) =>
|
||||
set((state) => setDefaultAdvertisedEndpointKey(state, key)),
|
||||
toggleProject: (projectId) => set((state) => toggleProject(state, projectId)),
|
||||
setProjectExpanded: (projectId, expanded) =>
|
||||
set((state) => setProjectExpanded(state, projectId, expanded)),
|
||||
|
||||
Reference in new issue
Block a user