diff --git a/packages/app/src/devices/tailscale-hint.test.ts b/packages/app/src/devices/tailscale-hint.test.ts new file mode 100644 index 0000000000..46ecf8c2b0 --- /dev/null +++ b/packages/app/src/devices/tailscale-hint.test.ts @@ -0,0 +1,36 @@ +import { describe, expect, it } from "vitest"; +import type { TailscaleStatus } from "@getpaseo/protocol/messages"; +import { i18n } from "@/i18n/i18next"; +import { describeTailscale } from "./tailscale-hint"; + +// Statuses as the host reports them; see `createDaemonListeners` in the server's listeners.ts. +const off: TailscaleStatus = { ip: "100.101.102.103", address: null, state: "off" }; + +describe("the Tailscale row's hint", () => { + it("says why Tailscale stays off when the host listens on a socket", () => { + const socketHint = "Off, because this host listens on a local socket"; + expect(describeTailscale({ ...off, lockedBy: "main", mainIsSocket: true }, i18n.t)).toBe( + socketHint, + ); + expect(describeTailscale({ ...off, lockedBy: "launch", mainIsSocket: true }, i18n.t)).toBe( + socketHint, + ); + }); + + it("keeps the hint of every other state", () => { + const hint = (status: TailscaleStatus) => describeTailscale(status, i18n.t); + expect(hint(off)).toBe("Direct over your tailnet, enter an address"); + expect(hint({ ip: null, address: null, state: "unavailable", lockedBy: "launch" })).toBe( + "Tailscale is not running on this host", + ); + expect(hint({ ...off, state: "waiting", address: "100.101.102.103:6767" })).toBe( + "Waiting for Tailscale to start on this host", + ); + expect(hint({ ...off, state: "on", address: "100.101.102.103:6767", lockedBy: "main" })).toBe( + "Always on, because this host already accepts Tailscale connections", + ); + expect(hint({ ...off, lockedBy: "launch" })).toBe( + "Controlled by the command that starts this host", + ); + }); +}); diff --git a/packages/app/src/devices/tailscale-hint.ts b/packages/app/src/devices/tailscale-hint.ts new file mode 100644 index 0000000000..519befdc96 --- /dev/null +++ b/packages/app/src/devices/tailscale-hint.ts @@ -0,0 +1,13 @@ +import type { TailscaleStatus } from "@getpaseo/protocol/messages"; +import type { TFunction } from "i18next"; + +/** The line under the Tailscale label for each state the host reports, most specific first. */ +export function describeTailscale(status: TailscaleStatus, t: TFunction): string { + if (status.state === "unavailable") return t("devices.tailscale.unavailable"); + if (status.state === "waiting") return t("devices.tailscale.waiting"); + // A socket is why Tailscale cannot be on, even when the launch command also fixes the address. + if (status.mainIsSocket) return t("devices.tailscale.socket"); + if (status.lockedBy === "launch") return t("devices.tailscale.launch"); + if (status.lockedBy === "main") return t("devices.tailscale.alwaysOn"); + return t("devices.tailscale.hint"); +} diff --git a/packages/app/src/devices/tailscale-row.tsx b/packages/app/src/devices/tailscale-row.tsx index 9f86505bfe..a60dfca109 100644 --- a/packages/app/src/devices/tailscale-row.tsx +++ b/packages/app/src/devices/tailscale-row.tsx @@ -1,7 +1,5 @@ import { useCallback, useMemo } from "react"; import { useMutation, useQueryClient } from "@tanstack/react-query"; -import type { TailscaleStatus } from "@getpaseo/protocol/messages"; -import type { TFunction } from "i18next"; import { useTranslation } from "react-i18next"; import { SettingsAction, SettingsRowChildren, SettingsSwitch } from "@/components/settings"; import { useToast } from "@/contexts/toast-context"; @@ -10,6 +8,7 @@ import { useHostRuntimeClient, useHostRuntimeSnapshot } from "@/runtime/host-run import { useSessionStore } from "@/stores/session-store"; import { confirmDialog } from "@/utils/confirm-dialog"; import { copyToClipboard } from "@/utils/copy-to-clipboard"; +import { describeTailscale } from "./tailscale-hint"; const UPDATES_DOCS_URL = "https://paseo.sh/docs/updates"; const TAILSCALE_DOWNLOAD_URL = "https://tailscale.com/download"; @@ -71,7 +70,7 @@ function TailscaleControl({ serverId, client }: { serverId: string; client: Host <>