import { Network } from "lucide-react"; import { useHosts, useTranslation, type PluginHostRecord, type StandaloneViewProps, } from "@termix/plugin-sdk/frontend"; import { ConnectionScreen, FullScreenAppWrapper, Select2, } from "@termix/plugin-sdk/ui"; import { TunnelTab } from "./TunnelTab"; import { C2STunnelPresetManager } from "./C2STunnelPresetManager"; import { hostTunnelSettings } from "./host-tunnels"; /** The `?view=tunnel` full-screen page for one host. */ export function TunnelStandalone({ hostId }: StandaloneViewProps) { const { t } = useTranslation(); return ( {(hostConfig, phase) => { if (phase === "loading") { return (
); } if (!hostConfig) { return (
); } const host = { ...hostConfig, id: String(hostConfig.id), } as unknown as PluginHostRecord; return ; }}
); } /** The rail panel for the desktop app's client tunnels. */ export function PortForwardingPanel() { return (
); } export interface TunnelWidgetConfig { hostId: number; } /** Homepage widget: the tunnel tab for one host. */ export function TunnelWidget({ widget, config, }: { widget: { title?: string | null }; config: TunnelWidgetConfig; }) { const { t } = useTranslation(); const { hosts, loaded } = useHosts(); const placeholder = (text: string) => (
{text}
); if (!config.hostId) return placeholder(t("common.noHostConfigured")); if (!loaded) return placeholder(t("common.loading")); const host = hosts.find( (candidate) => String(candidate.id) === String(config.hostId) && hostTunnelSettings(candidate).enabled, ); if (!host) return placeholder(t("common.noHostConfigured")); return (
{widget.title && (
{widget.title}
)}
e.stopPropagation()} >
); } /** The widget's edit form: pick a host with tunnels on. */ export function TunnelWidgetEditForm({ config, onChange, }: { config: TunnelWidgetConfig; onChange: (config: TunnelWidgetConfig) => void; }) { const { t } = useTranslation(); const { hosts } = useHosts(); const options = hosts.filter( (host) => host.enableSsh !== false && hostTunnelSettings(host).enabled, ); return (
onChange({ ...config, hostId: Number(e.target.value) }) } className="h-8 text-xs border border-border bg-background px-2" > {options.map((host) => ( ))}
); }