@devries-cameron20 / t3code Mirror · read-only / commits / 9dc28a125a
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 22, 20:45 UTC

refactor(web): the connections page's pure helpers live in ConnectionsSettings.logic (#22683)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Oct 21, 2026 at 01:39 UTC 9dc28a125a845cd98a7984c72169c4cc34694119
2 files changed +310 -277
apps/web/src/components/settings/ConnectionsSettings.logic.ts
+291
@@ -1,10 +1,22 @@
1 +import * as DateTime from "effect/DateTime";
2 +
3 +import { resolveDesktopPairingUrl, resolveHostedPairingUrl } from "./pairingUrls";
4 +import { getPairingTokenFromUrl, setPairingTokenOnUrl } from "../../pairingUrl";
5 +import { readHostedPairingRequest } from "../../hostedPairing";
6 +import {
7 + type ServerClientSessionRecord,
8 + type ServerPairingLinkRecord,
9 +} from "~/environments/primary";
10 import {
11 type AdvertisedEndpoint,
12 + type AuthClientSession,
13 type AuthGrantScope,
14 + type AuthPairingLink,
15 AuthTerminalOperateScope,
16 AuthTerminalReadScope,
17 type DesktopBridge,
18 type DesktopServerExposureState,
19 + type DesktopSshEnvironmentTarget,
20 type DesktopUpdateState,
21 type DesktopWslState,
22 } from "@t3tools/contracts";
@@ -150,3 +162,282 @@ export async function applyWslEnableSelection(input: {
162 }
163 return await bridge.setWslBackendEnabled(true);
164 }
165 +
166 +const accessTimestampFormatter = new Intl.DateTimeFormat(undefined, {
167 + dateStyle: "medium",
168 + timeStyle: "short",
169 +});
170 +
171 +export function formatAccessTimestamp(value: string): string {
172 + const parsed = new Date(value);
173 + if (Number.isNaN(parsed.getTime())) {
174 + return value;
175 + }
176 + return accessTimestampFormatter.format(parsed);
177 +}
178 +
179 +export function parseManualDesktopSshTarget(input: {
180 + readonly host: string;
181 + readonly username: string;
182 + readonly port: string;
183 +}): DesktopSshEnvironmentTarget {
184 + const rawHost = input.host.trim();
185 + if (rawHost.length === 0) {
186 + throw new Error("SSH host or alias is required.");
187 + }
188 +
189 + let hostname = rawHost;
190 + let username = input.username.trim() || null;
191 + let port: number | null = null;
192 +
193 + const atIndex = hostname.lastIndexOf("@");
194 + if (atIndex > 0) {
195 + const inlineUsername = hostname.slice(0, atIndex).trim();
196 + hostname = hostname.slice(atIndex + 1).trim();
197 + if (!username && inlineUsername.length > 0) {
198 + username = inlineUsername;
199 + }
200 + }
201 +
202 + const bracketedHostMatch = /^\[([^\]]+)\](?::(\d+))?$/u.exec(hostname);
203 + if (bracketedHostMatch) {
204 + hostname = bracketedHostMatch[1]!.trim();
205 + if (bracketedHostMatch[2]) {
206 + port = Number.parseInt(bracketedHostMatch[2], 10);
207 + }
208 + } else {
209 + const colonSegments = hostname.split(":");
210 + if (colonSegments.length === 2 && /^\d+$/u.test(colonSegments[1] ?? "")) {
211 + hostname = colonSegments[0]!.trim();
212 + port = Number.parseInt(colonSegments[1]!, 10);
213 + }
214 + }
215 +
216 + const rawPort = input.port.trim();
217 + if (rawPort.length > 0) {
218 + port = Number.parseInt(rawPort, 10);
219 + }
220 +
221 + if (hostname.length === 0) {
222 + throw new Error("SSH host or alias is required.");
223 + }
224 +
225 + if (port !== null && (!Number.isInteger(port) || port <= 0 || port > 65_535)) {
226 + throw new Error("SSH port must be between 1 and 65535.");
227 + }
228 +
229 + return {
230 + alias: hostname,
231 + hostname,
232 + username,
233 + port,
234 + };
235 +}
236 +
237 +export function parsePairingUrlFields(
238 + input: string,
239 +): { readonly host: string; readonly pairingCode: string } | null {
240 + const trimmed = input.trim();
241 + if (!trimmed) return null;
242 +
243 + try {
244 + const urlLikeInput =
245 + /^[a-zA-Z][a-zA-Z\d+.-]*:\/\//u.test(trimmed) || trimmed.startsWith("//")
246 + ? trimmed
247 + : `https://${trimmed}`;
248 + const url = new URL(urlLikeInput, window.location.origin);
249 + const hostedPairingRequest = readHostedPairingRequest(url);
250 + if (hostedPairingRequest) {
251 + return {
252 + host: hostedPairingRequest.host,
253 + pairingCode: hostedPairingRequest.token,
254 + };
255 + }
256 +
257 + const pairingCode = getPairingTokenFromUrl(url);
258 + if (!pairingCode) return null;
259 + return {
260 + host: url.origin,
261 + pairingCode,
262 + };
263 + } catch {
264 + return null;
265 + }
266 +}
267 +
268 +export function parseRemotePairingFields(input: {
269 + readonly host: string;
270 + readonly pairingCode: string;
271 +}): {
272 + readonly host: string;
273 + readonly pairingCode: string;
274 +} {
275 + const parsedPairingUrl = parsePairingUrlFields(input.host);
276 + if (parsedPairingUrl) return parsedPairingUrl;
277 +
278 + const host = input.host.trim();
279 + const pairingCode = input.pairingCode.trim();
280 + if (!host) {
281 + throw new Error("Enter a backend host.");
282 + }
283 + if (!pairingCode) {
284 + throw new Error("Enter a pairing code.");
285 + }
286 + return { host, pairingCode };
287 +}
288 +
289 +export function formatDesktopSshConnectionError(error: unknown): string {
290 + const fallback = "Failed to connect SSH host.";
291 + const rawMessage = error instanceof Error ? error.message : fallback;
292 + const withoutIpcPrefix = rawMessage.replace(
293 + /^Error invoking remote method 'desktop:ensure-ssh-environment':\s*/u,
294 + "",
295 + );
296 + const withoutTaggedErrorPrefix = withoutIpcPrefix.replace(/^Ssh[A-Za-z]+Error:\s*/u, "");
297 + return withoutTaggedErrorPrefix.trim() || fallback;
298 +}
299 +
300 +export function sortDesktopPairingLinks(links: ReadonlyArray<ServerPairingLinkRecord>) {
301 + return [...links].toSorted(
302 + (left, right) => new Date(right.createdAt).getTime() - new Date(left.createdAt).getTime(),
303 + );
304 +}
305 +
306 +export function summarizeAuthorizedClients(
307 + sessions: ReadonlyArray<ServerClientSessionRecord>,
308 + links: ReadonlyArray<ServerPairingLinkRecord>,
309 +): string {
310 + const parts = [
311 + `${sessions.length} ${sessions.length === 1 ? "client" : "clients"}`,
312 + links.length > 0
313 + ? `${links.length} ${links.length === 1 ? "pairing link" : "pairing links"}`
314 + : null,
315 + ];
316 + return parts.filter((part): part is string => part !== null).join(" · ");
317 +}
318 +
319 +export function sortDesktopClientSessions(sessions: ReadonlyArray<ServerClientSessionRecord>) {
320 + return [...sessions].toSorted((left, right) => {
321 + if (left.current !== right.current) {
322 + return left.current ? -1 : 1;
323 + }
324 + if (left.connected !== right.connected) {
325 + return left.connected ? -1 : 1;
326 + }
327 + return new Date(right.issuedAt).getTime() - new Date(left.issuedAt).getTime();
328 + });
329 +}
330 +
331 +export function toDesktopPairingLinkRecord(pairingLink: AuthPairingLink): ServerPairingLinkRecord {
332 + return {
333 + ...pairingLink,
334 + scopes: pairingLink.permissions ?? pairingLink.scopes,
335 + createdAt: DateTime.formatIso(pairingLink.createdAt),
336 + expiresAt: DateTime.formatIso(pairingLink.expiresAt),
337 + };
338 +}
339 +
340 +export function toDesktopClientSessionRecord(
341 + clientSession: AuthClientSession,
342 +): ServerClientSessionRecord {
343 + return {
344 + ...clientSession,
345 + scopes: clientSession.permissions ?? clientSession.scopes,
346 + issuedAt: DateTime.formatIso(clientSession.issuedAt),
347 + expiresAt: DateTime.formatIso(clientSession.expiresAt),
348 + lastConnectedAt:
349 + clientSession.lastConnectedAt === null
350 + ? null
351 + : DateTime.formatIso(clientSession.lastConnectedAt),
352 + };
353 +}
354 +
355 +export function selectPairingEndpoint(
356 + endpoints: ReadonlyArray<AdvertisedEndpoint>,
357 + defaultEndpointKey?: string | null,
358 +): AdvertisedEndpoint | null {
359 + const availableEndpoints = endpoints.filter((endpoint) => endpoint.status !== "unavailable");
360 + if (defaultEndpointKey) {
361 + const selectedEndpoint = availableEndpoints.find(
362 + (endpoint) => endpointDefaultPreferenceKey(endpoint) === defaultEndpointKey,
363 + );
364 + if (selectedEndpoint) {
365 + return selectedEndpoint;
366 + }
367 + }
368 + return (
369 + availableEndpoints.find((endpoint) => endpoint.isDefault) ??
370 + availableEndpoints.find((endpoint) => endpoint.reachability !== "loopback") ??
371 + availableEndpoints.find((endpoint) => endpoint.compatibility.hostedHttpsApp === "compatible") ??
372 + null
373 + );
374 +}
375 +
376 +export function isTailscaleHttpsEndpoint(endpoint: AdvertisedEndpoint): boolean {
377 + return endpoint.id.startsWith("tailscale-magicdns:");
378 +}
379 +
380 +export function endpointDefaultPreferenceKey(endpoint: AdvertisedEndpoint): string {
381 + if (endpoint.id.startsWith("desktop-loopback:")) {
382 + return "desktop-core:loopback:http";
383 + }
384 + if (endpoint.id.startsWith("desktop-lan:")) {
385 + return "desktop-core:lan:http";
386 + }
387 + if (endpoint.id.startsWith("tailscale-ip:")) {
388 + return "tailscale:ip:http";
389 + }
390 + if (isTailscaleHttpsEndpoint(endpoint)) {
391 + return "tailscale:magicdns:https";
392 + }
393 +
394 + let scheme = "unknown";
395 + try {
396 + scheme = new URL(endpoint.httpBaseUrl).protocol.replace(/:$/u, "");
397 + } catch {}
398 +
399 + return `${endpoint.provider.id}:${endpoint.reachability}:${scheme}:${endpoint.label}`;
400 +}
401 +
402 +export function resolveAdvertisedEndpointPairingUrl(
403 + endpoint: AdvertisedEndpoint,
404 + credential: string,
405 +): string {
406 + if (endpoint.compatibility.hostedHttpsApp === "compatible") {
407 + return (
408 + resolveHostedPairingUrl(endpoint.httpBaseUrl, credential) ??
409 + resolveDesktopPairingUrl(endpoint.httpBaseUrl, credential)
410 + );
411 + }
412 + return resolveDesktopPairingUrl(endpoint.httpBaseUrl, credential);
413 +}
414 +
415 +export function resolveCurrentOriginPairingUrl(credential: string): string {
416 + const url = new URL("/pair", window.location.href);
417 + return setPairingTokenOnUrl(url, credential).toString();
418 +}
419 +
420 +export function isHostedAppPairingUrl(value: string): boolean {
421 + try {
422 + const url = new URL(value);
423 + return url.pathname === "/pair" && url.searchParams.has("host");
424 + } catch {
425 + return false;
426 + }
427 +}
428 +
429 +export function endpointShareHint(endpoint: AdvertisedEndpoint, url: string): string {
430 + if (isHostedAppPairingUrl(url)) {
431 + return "Opens the hosted app, no install needed";
432 + }
433 + switch (endpoint.reachability) {
434 + case "lan":
435 + return "Devices on the same network";
436 + case "private-network":
437 + return "Devices on your private network";
438 + case "public":
439 + return "Reachable from anywhere";
440 + case "loopback":
441 + return "Clients on this machine";
442 + }
443 +}
apps/web/src/components/settings/ConnectionsSettings.tsx
+19 -277
@@ -60,7 +60,6 @@ import {
60 squashAtomCommandFailure,
61 } from "@t3tools/client-runtime/state/runtime";
62 import * as Cause from "effect/Cause";
63 -import * as DateTime from "effect/DateTime";
63 import * as Option from "effect/Option";
64
65 import { useCopyToClipboard } from "../../hooks/useCopyToClipboard";
@@ -148,8 +147,6 @@ import { Empty, EmptyDescription, EmptyHeader, EmptyMedia, EmptyTitle } from "..
147 import { AnimatedHeight } from "../AnimatedHeight";
148 import { EnvironmentMachineIcon } from "../EnvironmentMachineIcon";
149 import { Textarea } from "../ui/textarea";
151 -import { getPairingTokenFromUrl, setPairingTokenOnUrl } from "../../pairingUrl";
152 -import { readHostedPairingRequest } from "../../hostedPairing";
150 import {
151 createServerPairingCredential,
152 revokeOtherServerClientSessions,
@@ -218,6 +215,25 @@ import {
215 threadJumpCommandForIndex,
216 threadJumpIndexFromCommand,
217 } from "../../keybindings";
218 +import {
219 + formatAccessTimestamp,
220 + parseManualDesktopSshTarget,
221 + parsePairingUrlFields,
222 + parseRemotePairingFields,
223 + formatDesktopSshConnectionError,
224 + sortDesktopPairingLinks,
225 + summarizeAuthorizedClients,
226 + sortDesktopClientSessions,
227 + toDesktopPairingLinkRecord,
228 + toDesktopClientSessionRecord,
229 + selectPairingEndpoint,
230 + isTailscaleHttpsEndpoint,
231 + endpointDefaultPreferenceKey,
232 + resolveAdvertisedEndpointPairingUrl,
233 + resolveCurrentOriginPairingUrl,
234 + isHostedAppPairingUrl,
235 + endpointShareHint,
236 +} from "./ConnectionsSettings.logic";
237
238 const DEFAULT_TAILSCALE_SERVE_PORT = 443;
239 const EMPTY_ADVERTISED_ENDPOINTS: ReadonlyArray<AdvertisedEndpoint> = [];
@@ -229,19 +245,6 @@ const EMPTY_DISCOVERED_SSH_HOSTS: ReadonlyArray<DesktopDiscoveredSshHost> = [];
245 const BACKEND_VALUE_DEFAULT_WSL = "backend:default-wsl";
246 const BACKEND_VALUE_WSL_OFF = "backend:wsl-off";
247
232 -const accessTimestampFormatter = new Intl.DateTimeFormat(undefined, {
233 - dateStyle: "medium",
234 - timeStyle: "short",
235 -});
236 -
237 -function formatAccessTimestamp(value: string): string {
238 - const parsed = new Date(value);
239 - if (Number.isNaN(parsed.getTime())) {
240 - return value;
241 - }
242 - return accessTimestampFormatter.format(parsed);
243 -}
244 -
248 function AccessScopeSummary({
249 scopes,
250 label,
@@ -286,124 +289,6 @@ function AccessScopeSummary({
289 );
290 }
291
289 -function parseManualDesktopSshTarget(input: {
290 - readonly host: string;
291 - readonly username: string;
292 - readonly port: string;
293 -}): DesktopSshEnvironmentTarget {
294 - const rawHost = input.host.trim();
295 - if (rawHost.length === 0) {
296 - throw new Error("SSH host or alias is required.");
297 - }
298 -
299 - let hostname = rawHost;
300 - let username = input.username.trim() || null;
301 - let port: number | null = null;
302 -
303 - const atIndex = hostname.lastIndexOf("@");
304 - if (atIndex > 0) {
305 - const inlineUsername = hostname.slice(0, atIndex).trim();
306 - hostname = hostname.slice(atIndex + 1).trim();
307 - if (!username && inlineUsername.length > 0) {
308 - username = inlineUsername;
309 - }
310 - }
311 -
312 - const bracketedHostMatch = /^\[([^\]]+)\](?::(\d+))?$/u.exec(hostname);
313 - if (bracketedHostMatch) {
314 - hostname = bracketedHostMatch[1]!.trim();
315 - if (bracketedHostMatch[2]) {
316 - port = Number.parseInt(bracketedHostMatch[2], 10);
317 - }
318 - } else {
319 - const colonSegments = hostname.split(":");
320 - if (colonSegments.length === 2 && /^\d+$/u.test(colonSegments[1] ?? "")) {
321 - hostname = colonSegments[0]!.trim();
322 - port = Number.parseInt(colonSegments[1]!, 10);
323 - }
324 - }
325 -
326 - const rawPort = input.port.trim();
327 - if (rawPort.length > 0) {
328 - port = Number.parseInt(rawPort, 10);
329 - }
330 -
331 - if (hostname.length === 0) {
332 - throw new Error("SSH host or alias is required.");
333 - }
334 -
335 - if (port !== null && (!Number.isInteger(port) || port <= 0 || port > 65_535)) {
336 - throw new Error("SSH port must be between 1 and 65535.");
337 - }
338 -
339 - return {
340 - alias: hostname,
341 - hostname,
342 - username,
343 - port,
344 - };
345 -}
346 -
347 -function parsePairingUrlFields(
348 - input: string,
349 -): { readonly host: string; readonly pairingCode: string } | null {
350 - const trimmed = input.trim();
351 - if (!trimmed) return null;
352 -
353 - try {
354 - const urlLikeInput =
355 - /^[a-zA-Z][a-zA-Z\d+.-]*:\/\//u.test(trimmed) || trimmed.startsWith("//")
356 - ? trimmed
357 - : `https://${trimmed}`;
358 - const url = new URL(urlLikeInput, window.location.origin);
359 - const hostedPairingRequest = readHostedPairingRequest(url);
360 - if (hostedPairingRequest) {
361 - return {
362 - host: hostedPairingRequest.host,
363 - pairingCode: hostedPairingRequest.token,
364 - };
365 - }
366 -
367 - const pairingCode = getPairingTokenFromUrl(url);
368 - if (!pairingCode) return null;
369 - return {
370 - host: url.origin,
371 - pairingCode,
372 - };
373 - } catch {
374 - return null;
375 - }
376 -}
377 -
378 -function parseRemotePairingFields(input: { readonly host: string; readonly pairingCode: string }): {
379 - readonly host: string;
380 - readonly pairingCode: string;
381 -} {
382 - const parsedPairingUrl = parsePairingUrlFields(input.host);
383 - if (parsedPairingUrl) return parsedPairingUrl;
384 -
385 - const host = input.host.trim();
386 - const pairingCode = input.pairingCode.trim();
387 - if (!host) {
388 - throw new Error("Enter a backend host.");
389 - }
390 - if (!pairingCode) {
391 - throw new Error("Enter a pairing code.");
392 - }
393 - return { host, pairingCode };
394 -}
395 -
396 -function formatDesktopSshConnectionError(error: unknown): string {
397 - const fallback = "Failed to connect SSH host.";
398 - const rawMessage = error instanceof Error ? error.message : fallback;
399 - const withoutIpcPrefix = rawMessage.replace(
400 - /^Error invoking remote method 'desktop:ensure-ssh-environment':\s*/u,
401 - "",
402 - );
403 - const withoutTaggedErrorPrefix = withoutIpcPrefix.replace(/^Ssh[A-Za-z]+Error:\s*/u, "");
404 - return withoutTaggedErrorPrefix.trim() || fallback;
405 -}
406 -
292 const ENDPOINT_ROW_CLASSNAME = "first:rounded-t-xl last:rounded-b-xl px-3 py-2.5 sm:px-4";
293
294 type AccessSectionPresentation = "current" | "endpoint-rail";
@@ -423,149 +308,6 @@ function endpointRowClassName(presentation: AccessSectionPresentation, isAvailab
308 return cn(ENDPOINT_ROW_CLASSNAME, !isAvailable && "bg-muted/24");
309 }
310
426 -function sortDesktopPairingLinks(links: ReadonlyArray<ServerPairingLinkRecord>) {
427 - return [...links].toSorted(
428 - (left, right) => new Date(right.createdAt).getTime() - new Date(left.createdAt).getTime(),
429 - );
430 -}
431 -
432 -function summarizeAuthorizedClients(
433 - sessions: ReadonlyArray<ServerClientSessionRecord>,
434 - links: ReadonlyArray<ServerPairingLinkRecord>,
435 -): string {
436 - const parts = [
437 - `${sessions.length} ${sessions.length === 1 ? "client" : "clients"}`,
438 - links.length > 0
439 - ? `${links.length} ${links.length === 1 ? "pairing link" : "pairing links"}`
440 - : null,
441 - ];
442 - return parts.filter((part): part is string => part !== null).join(" · ");
443 -}
444 -
445 -function sortDesktopClientSessions(sessions: ReadonlyArray<ServerClientSessionRecord>) {
446 - return [...sessions].toSorted((left, right) => {
447 - if (left.current !== right.current) {
448 - return left.current ? -1 : 1;
449 - }
450 - if (left.connected !== right.connected) {
451 - return left.connected ? -1 : 1;
452 - }
453 - return new Date(right.issuedAt).getTime() - new Date(left.issuedAt).getTime();
454 - });
455 -}
456 -
457 -function toDesktopPairingLinkRecord(pairingLink: AuthPairingLink): ServerPairingLinkRecord {
458 - return {
459 - ...pairingLink,
460 - scopes: pairingLink.permissions ?? pairingLink.scopes,
461 - createdAt: DateTime.formatIso(pairingLink.createdAt),
462 - expiresAt: DateTime.formatIso(pairingLink.expiresAt),
463 - };
464 -}
465 -
466 -function toDesktopClientSessionRecord(clientSession: AuthClientSession): ServerClientSessionRecord {
467 - return {
468 - ...clientSession,
469 - scopes: clientSession.permissions ?? clientSession.scopes,
470 - issuedAt: DateTime.formatIso(clientSession.issuedAt),
471 - expiresAt: DateTime.formatIso(clientSession.expiresAt),
472 - lastConnectedAt:
473 - clientSession.lastConnectedAt === null
474 - ? null
475 - : DateTime.formatIso(clientSession.lastConnectedAt),
476 - };
477 -}
478 -
479 -function selectPairingEndpoint(
480 - endpoints: ReadonlyArray<AdvertisedEndpoint>,
481 - defaultEndpointKey?: string | null,
482 -): AdvertisedEndpoint | null {
483 - const availableEndpoints = endpoints.filter((endpoint) => endpoint.status !== "unavailable");
484 - if (defaultEndpointKey) {
485 - const selectedEndpoint = availableEndpoints.find(
486 - (endpoint) => endpointDefaultPreferenceKey(endpoint) === defaultEndpointKey,
487 - );
488 - if (selectedEndpoint) {
489 - return selectedEndpoint;
490 - }
491 - }
492 - return (
493 - availableEndpoints.find((endpoint) => endpoint.isDefault) ??
494 - availableEndpoints.find((endpoint) => endpoint.reachability !== "loopback") ??
495 - availableEndpoints.find((endpoint) => endpoint.compatibility.hostedHttpsApp === "compatible") ??
496 - null
497 - );
498 -}
499 -
500 -function isTailscaleHttpsEndpoint(endpoint: AdvertisedEndpoint): boolean {
501 - return endpoint.id.startsWith("tailscale-magicdns:");
502 -}
503 -
504 -function endpointDefaultPreferenceKey(endpoint: AdvertisedEndpoint): string {
505 - if (endpoint.id.startsWith("desktop-loopback:")) {
506 - return "desktop-core:loopback:http";
507 - }
508 - if (endpoint.id.startsWith("desktop-lan:")) {
509 - return "desktop-core:lan:http";
510 - }
511 - if (endpoint.id.startsWith("tailscale-ip:")) {
512 - return "tailscale:ip:http";
513 - }
514 - if (isTailscaleHttpsEndpoint(endpoint)) {
515 - return "tailscale:magicdns:https";
516 - }
517 -
518 - let scheme = "unknown";
519 - try {
520 - scheme = new URL(endpoint.httpBaseUrl).protocol.replace(/:$/u, "");
521 - } catch {}
522 -
523 - return `${endpoint.provider.id}:${endpoint.reachability}:${scheme}:${endpoint.label}`;
524 -}
525 -
526 -function resolveAdvertisedEndpointPairingUrl(
527 - endpoint: AdvertisedEndpoint,
528 - credential: string,
529 -): string {
530 - if (endpoint.compatibility.hostedHttpsApp === "compatible") {
531 - return (
532 - resolveHostedPairingUrl(endpoint.httpBaseUrl, credential) ??
533 - resolveDesktopPairingUrl(endpoint.httpBaseUrl, credential)
534 - );
535 - }
536 - return resolveDesktopPairingUrl(endpoint.httpBaseUrl, credential);
537 -}
538 -
539 -function resolveCurrentOriginPairingUrl(credential: string): string {
540 - const url = new URL("/pair", window.location.href);
541 - return setPairingTokenOnUrl(url, credential).toString();
542 -}
543 -
544 -function isHostedAppPairingUrl(value: string): boolean {
545 - try {
546 - const url = new URL(value);
547 - return url.pathname === "/pair" && url.searchParams.has("host");
548 - } catch {
549 - return false;
550 - }
551 -}
552 -
553 -function endpointShareHint(endpoint: AdvertisedEndpoint, url: string): string {
554 - if (isHostedAppPairingUrl(url)) {
555 - return "Opens the hosted app, no install needed";
556 - }
557 - switch (endpoint.reachability) {
558 - case "lan":
559 - return "Devices on the same network";
560 - case "private-network":
561 - return "Devices on your private network";
562 - case "public":
563 - return "Reachable from anywhere";
564 - case "loopback":
565 - return "Clients on this machine";
566 - }
567 -}
568 -
311 type PairingLinkListRowProps = {
312 pairingLink: ServerPairingLinkRecord;
313 credential: string | undefined;