2026-02-26 20:26:12 +02:00
|
|
|
import React from 'react';
|
2026-03-20 01:01:03 +02:00
|
|
|
import { Button } from '@/components/ui/button';
|
2026-02-26 20:26:12 +02:00
|
|
|
import { Input } from '@/components/ui/input';
|
|
|
|
|
import { NumberInput } from '@/components/ui/number-input';
|
|
|
|
|
import { Switch } from '@/components/ui/switch';
|
|
|
|
|
import {
|
|
|
|
|
Select,
|
|
|
|
|
SelectContent,
|
|
|
|
|
SelectItem,
|
|
|
|
|
SelectTrigger,
|
|
|
|
|
SelectValue,
|
|
|
|
|
} from '@/components/ui/select';
|
|
|
|
|
import {
|
|
|
|
|
RiAddLine,
|
|
|
|
|
RiArrowDownSLine,
|
|
|
|
|
RiArrowRightLine,
|
|
|
|
|
RiComputerLine,
|
|
|
|
|
RiExternalLinkLine,
|
|
|
|
|
RiFileCopyLine,
|
|
|
|
|
RiInformationLine,
|
|
|
|
|
RiPlug2Line,
|
|
|
|
|
RiRefreshLine,
|
|
|
|
|
RiServerLine,
|
|
|
|
|
RiShuffleLine,
|
|
|
|
|
RiTerminalWindowLine,
|
|
|
|
|
RiDeleteBinLine,
|
|
|
|
|
RiStopLine,
|
|
|
|
|
} from '@remixicon/react';
|
|
|
|
|
import {
|
|
|
|
|
Dialog,
|
|
|
|
|
DialogContent,
|
|
|
|
|
DialogDescription,
|
|
|
|
|
DialogHeader,
|
|
|
|
|
DialogTitle,
|
|
|
|
|
} from '@/components/ui/dialog';
|
|
|
|
|
import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip';
|
|
|
|
|
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from '@/components/ui/collapsible';
|
|
|
|
|
import { SettingsPageLayout } from '@/components/sections/shared/SettingsPageLayout';
|
|
|
|
|
import { useDesktopSshStore } from '@/stores/useDesktopSshStore';
|
|
|
|
|
import { useUIStore } from '@/stores/useUIStore';
|
|
|
|
|
import { toast } from '@/components/ui';
|
|
|
|
|
import { copyTextToClipboard } from '@/lib/clipboard';
|
2026-03-20 19:11:45 +08:00
|
|
|
import { openExternalUrl } from '@/lib/url';
|
2026-04-26 14:03:39 +03:00
|
|
|
import { useI18n, type I18nKey } from '@/lib/i18n';
|
2026-02-26 20:26:12 +02:00
|
|
|
import {
|
|
|
|
|
desktopSshLogsClear,
|
|
|
|
|
desktopSshLogs,
|
|
|
|
|
type DesktopSshInstance,
|
|
|
|
|
type DesktopSshPortForward,
|
|
|
|
|
type DesktopSshPortForwardType,
|
|
|
|
|
} from '@/lib/desktopSsh';
|
|
|
|
|
|
|
|
|
|
const randomPort = (): number => {
|
|
|
|
|
return Math.floor(20000 + Math.random() * 30000);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const isPortInUseError = (error: unknown): boolean => {
|
|
|
|
|
const message = (error instanceof Error ? error.message : String(error)).toLowerCase();
|
|
|
|
|
return message.includes('address already in use') || message.includes('eaddrinuse') || message.includes('port already in use');
|
|
|
|
|
};
|
|
|
|
|
|
2026-04-26 14:03:39 +03:00
|
|
|
const phaseLabelKey = (phase?: string): I18nKey => {
|
2026-02-26 20:26:12 +02:00
|
|
|
switch (phase) {
|
|
|
|
|
case 'config_resolved':
|
2026-04-26 14:03:39 +03:00
|
|
|
return 'settings.remoteInstances.page.phase.resolvingConfiguration';
|
2026-02-26 20:26:12 +02:00
|
|
|
case 'auth_check':
|
2026-04-26 14:03:39 +03:00
|
|
|
return 'settings.remoteInstances.page.phase.checkingAuth';
|
2026-02-26 20:26:12 +02:00
|
|
|
case 'master_connecting':
|
2026-04-26 14:03:39 +03:00
|
|
|
return 'settings.remoteInstances.page.phase.establishingSsh';
|
2026-02-26 20:26:12 +02:00
|
|
|
case 'remote_probe':
|
2026-04-26 14:03:39 +03:00
|
|
|
return 'settings.remoteInstances.page.phase.probingRemote';
|
2026-02-26 20:26:12 +02:00
|
|
|
case 'installing':
|
2026-04-26 14:03:39 +03:00
|
|
|
return 'settings.remoteInstances.page.phase.installingOpenChamber';
|
2026-02-26 20:26:12 +02:00
|
|
|
case 'updating':
|
2026-04-26 14:03:39 +03:00
|
|
|
return 'settings.remoteInstances.page.phase.updatingOpenChamber';
|
2026-02-26 20:26:12 +02:00
|
|
|
case 'server_detecting':
|
2026-04-26 14:03:39 +03:00
|
|
|
return 'settings.remoteInstances.page.phase.detectingServer';
|
2026-02-26 20:26:12 +02:00
|
|
|
case 'server_starting':
|
2026-04-26 14:03:39 +03:00
|
|
|
return 'settings.remoteInstances.page.phase.startingServer';
|
2026-02-26 20:26:12 +02:00
|
|
|
case 'forwarding':
|
2026-04-26 14:03:39 +03:00
|
|
|
return 'settings.remoteInstances.page.phase.forwardingPorts';
|
2026-02-26 20:26:12 +02:00
|
|
|
case 'ready':
|
2026-04-26 14:03:39 +03:00
|
|
|
return 'settings.remoteInstances.sidebar.phase.ready';
|
2026-02-26 20:26:12 +02:00
|
|
|
case 'degraded':
|
2026-04-26 14:03:39 +03:00
|
|
|
return 'settings.remoteInstances.page.phase.reconnecting';
|
2026-02-26 20:26:12 +02:00
|
|
|
case 'error':
|
2026-04-26 14:03:39 +03:00
|
|
|
return 'settings.remoteInstances.sidebar.phase.error';
|
2026-02-26 20:26:12 +02:00
|
|
|
default:
|
2026-04-26 14:03:39 +03:00
|
|
|
return 'settings.remoteInstances.sidebar.phase.idle';
|
2026-02-26 20:26:12 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const CONNECTING_PHASES = new Set<string>([
|
|
|
|
|
'config_resolved',
|
|
|
|
|
'auth_check',
|
|
|
|
|
'master_connecting',
|
|
|
|
|
'remote_probe',
|
|
|
|
|
'installing',
|
|
|
|
|
'updating',
|
|
|
|
|
'server_detecting',
|
|
|
|
|
'server_starting',
|
|
|
|
|
'forwarding',
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
const isConnectingPhase = (phase?: string): boolean => {
|
|
|
|
|
return Boolean(phase && CONNECTING_PHASES.has(phase));
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const phaseDotClass = (phase?: string): string => {
|
|
|
|
|
if (phase === 'ready') {
|
|
|
|
|
return 'bg-[var(--status-success)] animate-pulse';
|
|
|
|
|
}
|
|
|
|
|
if (phase === 'error') {
|
|
|
|
|
return 'bg-[var(--status-error)] animate-pulse';
|
|
|
|
|
}
|
|
|
|
|
if (phase === 'degraded' || isConnectingPhase(phase)) {
|
|
|
|
|
return 'bg-[var(--status-warning)] animate-pulse';
|
|
|
|
|
}
|
|
|
|
|
return 'bg-muted-foreground/40';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const buildForwardLabel = (forward: DesktopSshPortForward): string => {
|
|
|
|
|
if (forward.type === 'dynamic') {
|
|
|
|
|
return `${forward.localHost || '127.0.0.1'}:${forward.localPort || 0}`;
|
|
|
|
|
}
|
|
|
|
|
if (forward.type === 'remote') {
|
|
|
|
|
return `${forward.remoteHost || '127.0.0.1'}:${forward.remotePort || 0} -> ${forward.localHost || '127.0.0.1'}:${forward.localPort || 0}`;
|
|
|
|
|
}
|
|
|
|
|
return `${forward.localHost || '127.0.0.1'}:${forward.localPort || 0} -> ${forward.remoteHost || '127.0.0.1'}:${forward.remotePort || 0}`;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const makeForward = (): DesktopSshPortForward => {
|
|
|
|
|
return {
|
|
|
|
|
id: `forward-${Date.now()}-${Math.random().toString(16).slice(2)}`,
|
|
|
|
|
enabled: true,
|
|
|
|
|
type: 'local',
|
|
|
|
|
localHost: '127.0.0.1',
|
|
|
|
|
localPort: randomPort(),
|
|
|
|
|
remoteHost: '127.0.0.1',
|
|
|
|
|
remotePort: 80,
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const suggestConcreteHost = (pattern: string): string => {
|
|
|
|
|
const value = pattern.trim().replace(/\*/g, 'host').replace(/\?/g, 'x');
|
|
|
|
|
return value || 'user@host';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const HintLabel: React.FC<{ label: string; hint: React.ReactNode }> = ({ label, hint }) => {
|
|
|
|
|
return (
|
|
|
|
|
<span className="inline-flex items-center gap-1 typography-meta text-muted-foreground">
|
|
|
|
|
<span>{label}</span>
|
|
|
|
|
<Tooltip delayDuration={700}>
|
|
|
|
|
<TooltipTrigger asChild>
|
|
|
|
|
<RiInformationLine className="h-3.5 w-3.5 text-muted-foreground/60 cursor-help" />
|
|
|
|
|
</TooltipTrigger>
|
|
|
|
|
<TooltipContent sideOffset={8} className="max-w-xs">
|
|
|
|
|
<div className="typography-meta text-foreground">{hint}</div>
|
|
|
|
|
</TooltipContent>
|
|
|
|
|
</Tooltip>
|
|
|
|
|
</span>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2026-04-26 14:03:39 +03:00
|
|
|
const forwardTypeDescriptionKey = (type: DesktopSshPortForwardType): I18nKey => {
|
2026-02-26 20:26:12 +02:00
|
|
|
switch (type) {
|
|
|
|
|
case 'remote':
|
2026-04-26 14:03:39 +03:00
|
|
|
return 'settings.remoteInstances.page.forwardTypeDescription.remote';
|
2026-02-26 20:26:12 +02:00
|
|
|
case 'dynamic':
|
2026-04-26 14:03:39 +03:00
|
|
|
return 'settings.remoteInstances.page.forwardTypeDescription.dynamic';
|
2026-02-26 20:26:12 +02:00
|
|
|
default:
|
2026-04-26 14:03:39 +03:00
|
|
|
return 'settings.remoteInstances.page.forwardTypeDescription.local';
|
2026-02-26 20:26:12 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const formatEndpoint = (host: string | undefined, port: number | undefined): string => {
|
|
|
|
|
const value = (host || '').trim();
|
|
|
|
|
const normalizedHost = !value || value === '127.0.0.1' || value === '::1' ? 'localhost' : value;
|
|
|
|
|
return `${normalizedHost}:${port || 0}`;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const toBrowserHost = (host: string | undefined): string => {
|
|
|
|
|
const value = (host || '').trim();
|
|
|
|
|
if (!value || value === '0.0.0.0' || value === '::') {
|
|
|
|
|
return '127.0.0.1';
|
|
|
|
|
}
|
|
|
|
|
return value;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const formatLogLine = (line: string): string => {
|
|
|
|
|
const match = line.match(/^\[(\d{10,})\]\s*(?:\[([A-Z]+)\]\s*)?(.*)$/);
|
|
|
|
|
if (!match) {
|
|
|
|
|
return line;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const millis = Number(match[1]);
|
|
|
|
|
const iso = Number.isFinite(millis) ? new Date(millis).toISOString() : match[1];
|
|
|
|
|
const level = (match[2] || 'INFO').toUpperCase();
|
|
|
|
|
const message = match[3] || '';
|
|
|
|
|
return `[${iso}] [${level}] ${message}`;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const navigateToUrl = (rawUrl: string): void => {
|
|
|
|
|
const target = rawUrl.trim();
|
|
|
|
|
if (!target) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
window.location.assign(target);
|
|
|
|
|
} catch {
|
|
|
|
|
window.location.href = target;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const normalizeForSave = (instance: DesktopSshInstance): DesktopSshInstance => {
|
|
|
|
|
const trimmedCommand = instance.sshCommand.trim();
|
|
|
|
|
const nickname = instance.nickname?.trim();
|
|
|
|
|
const forwards = instance.portForwards.map((forward) => ({
|
|
|
|
|
...forward,
|
|
|
|
|
localHost: forward.localHost?.trim() || '127.0.0.1',
|
|
|
|
|
localPort: typeof forward.localPort === 'number' ? Math.max(1, Math.min(65535, Math.round(forward.localPort))) : undefined,
|
|
|
|
|
remoteHost: forward.remoteHost?.trim(),
|
|
|
|
|
remotePort:
|
|
|
|
|
typeof forward.remotePort === 'number'
|
|
|
|
|
? Math.max(1, Math.min(65535, Math.round(forward.remotePort)))
|
|
|
|
|
: undefined,
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
...instance,
|
|
|
|
|
sshCommand: trimmedCommand,
|
|
|
|
|
...(nickname ? { nickname } : { nickname: undefined }),
|
|
|
|
|
connectionTimeoutSec: Math.max(5, Math.min(240, Math.round(instance.connectionTimeoutSec || 60))),
|
|
|
|
|
localForward: {
|
|
|
|
|
...instance.localForward,
|
|
|
|
|
bindHost:
|
|
|
|
|
instance.localForward.bindHost === 'localhost' ||
|
|
|
|
|
instance.localForward.bindHost === '0.0.0.0'
|
|
|
|
|
? instance.localForward.bindHost
|
|
|
|
|
: '127.0.0.1',
|
|
|
|
|
preferredLocalPort:
|
|
|
|
|
typeof instance.localForward.preferredLocalPort === 'number'
|
|
|
|
|
? Math.max(1, Math.min(65535, Math.round(instance.localForward.preferredLocalPort)))
|
|
|
|
|
: undefined,
|
|
|
|
|
},
|
|
|
|
|
remoteOpenchamber: {
|
|
|
|
|
...instance.remoteOpenchamber,
|
|
|
|
|
preferredPort:
|
|
|
|
|
typeof instance.remoteOpenchamber.preferredPort === 'number'
|
|
|
|
|
? Math.max(1, Math.min(65535, Math.round(instance.remoteOpenchamber.preferredPort)))
|
|
|
|
|
: undefined,
|
|
|
|
|
},
|
|
|
|
|
portForwards: forwards,
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const RemoteInstancesPage: React.FC = () => {
|
2026-04-26 14:03:39 +03:00
|
|
|
const { t } = useI18n();
|
2026-02-26 20:26:12 +02:00
|
|
|
const instances = useDesktopSshStore((state) => state.instances);
|
|
|
|
|
const statusesById = useDesktopSshStore((state) => state.statusesById);
|
|
|
|
|
const importCandidates = useDesktopSshStore((state) => state.importCandidates);
|
|
|
|
|
const isImportsLoading = useDesktopSshStore((state) => state.isImportsLoading);
|
|
|
|
|
const isSaving = useDesktopSshStore((state) => state.isSaving);
|
|
|
|
|
const error = useDesktopSshStore((state) => state.error);
|
|
|
|
|
const load = useDesktopSshStore((state) => state.load);
|
|
|
|
|
const loadImports = useDesktopSshStore((state) => state.loadImports);
|
|
|
|
|
const refreshStatuses = useDesktopSshStore((state) => state.refreshStatuses);
|
|
|
|
|
const upsertInstance = useDesktopSshStore((state) => state.upsertInstance);
|
|
|
|
|
const createFromCommand = useDesktopSshStore((state) => state.createFromCommand);
|
|
|
|
|
const removeInstance = useDesktopSshStore((state) => state.removeInstance);
|
|
|
|
|
const connect = useDesktopSshStore((state) => state.connect);
|
|
|
|
|
const disconnect = useDesktopSshStore((state) => state.disconnect);
|
|
|
|
|
const retry = useDesktopSshStore((state) => state.retry);
|
|
|
|
|
|
|
|
|
|
const selectedId = useUIStore((state) => state.settingsRemoteInstancesSelectedId);
|
|
|
|
|
const setSelectedId = useUIStore((state) => state.setSettingsRemoteInstancesSelectedId);
|
|
|
|
|
|
|
|
|
|
const selectedInstance = React.useMemo(() => {
|
|
|
|
|
if (!selectedId) return null;
|
|
|
|
|
return instances.find((instance) => instance.id === selectedId) || null;
|
|
|
|
|
}, [instances, selectedId]);
|
|
|
|
|
|
|
|
|
|
const [draft, setDraft] = React.useState<DesktopSshInstance | null>(null);
|
|
|
|
|
const [logDialogOpen, setLogDialogOpen] = React.useState(false);
|
|
|
|
|
const [logDialogLoading, setLogDialogLoading] = React.useState(false);
|
|
|
|
|
const [logDialogError, setLogDialogError] = React.useState<string | null>(null);
|
|
|
|
|
const [logDialogLines, setLogDialogLines] = React.useState<string[]>([]);
|
|
|
|
|
const [patternHost, setPatternHost] = React.useState<string | null>(null);
|
|
|
|
|
const [patternDestination, setPatternDestination] = React.useState('');
|
|
|
|
|
const [patternCreating, setPatternCreating] = React.useState(false);
|
|
|
|
|
const [expandedForwards, setExpandedForwards] = React.useState<Record<string, boolean>>({});
|
|
|
|
|
const [isPrimaryActionPending, setIsPrimaryActionPending] = React.useState(false);
|
|
|
|
|
const [isRetryPending, setIsRetryPending] = React.useState(false);
|
|
|
|
|
const [clockMs, setClockMs] = React.useState(() => Date.now());
|
|
|
|
|
|
|
|
|
|
React.useEffect(() => {
|
|
|
|
|
void load();
|
|
|
|
|
void loadImports();
|
|
|
|
|
}, [load, loadImports]);
|
|
|
|
|
|
|
|
|
|
React.useEffect(() => {
|
|
|
|
|
setDraft(selectedInstance);
|
|
|
|
|
}, [selectedInstance]);
|
|
|
|
|
|
|
|
|
|
React.useEffect(() => {
|
|
|
|
|
if (!selectedId) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const interval = window.setInterval(() => {
|
2026-04-06 21:05:02 +03:00
|
|
|
// Skip polling when tab is hidden to reduce background work
|
|
|
|
|
if (typeof document !== 'undefined' && document.visibilityState !== 'visible') {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2026-02-26 20:26:12 +02:00
|
|
|
void refreshStatuses();
|
|
|
|
|
}, 2_000);
|
|
|
|
|
return () => {
|
|
|
|
|
window.clearInterval(interval);
|
|
|
|
|
};
|
|
|
|
|
}, [refreshStatuses, selectedId]);
|
|
|
|
|
|
|
|
|
|
React.useEffect(() => {
|
2026-04-06 21:05:02 +03:00
|
|
|
// Use requestAnimationFrame for smoother clock updates without setInterval overhead
|
|
|
|
|
let rafId: number | null = null;
|
|
|
|
|
let lastTime = Date.now();
|
|
|
|
|
|
|
|
|
|
const tick = () => {
|
|
|
|
|
const now = Date.now();
|
|
|
|
|
// Update only once per second
|
|
|
|
|
if (now - lastTime >= 1_000) {
|
|
|
|
|
setClockMs(now);
|
|
|
|
|
lastTime = now;
|
|
|
|
|
}
|
|
|
|
|
rafId = requestAnimationFrame(tick);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Only run when visible
|
|
|
|
|
if (typeof document === 'undefined' || document.visibilityState === 'visible') {
|
|
|
|
|
rafId = requestAnimationFrame(tick);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const onVisibility = () => {
|
|
|
|
|
if (document.visibilityState === 'visible' && rafId === null) {
|
|
|
|
|
rafId = requestAnimationFrame(tick);
|
|
|
|
|
} else if (document.visibilityState !== 'visible' && rafId !== null) {
|
|
|
|
|
cancelAnimationFrame(rafId);
|
|
|
|
|
rafId = null;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
document.addEventListener('visibilitychange', onVisibility);
|
|
|
|
|
|
2026-02-26 20:26:12 +02:00
|
|
|
return () => {
|
2026-04-06 21:05:02 +03:00
|
|
|
document.removeEventListener('visibilitychange', onVisibility);
|
|
|
|
|
if (rafId !== null) {
|
|
|
|
|
cancelAnimationFrame(rafId);
|
|
|
|
|
}
|
2026-02-26 20:26:12 +02:00
|
|
|
};
|
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
const status = selectedId ? statusesById[selectedId] : null;
|
|
|
|
|
const statusPhase = status?.phase;
|
|
|
|
|
const isReady = statusPhase === 'ready';
|
|
|
|
|
const isReconnecting = statusPhase === 'degraded';
|
|
|
|
|
const isConnecting = isConnectingPhase(statusPhase);
|
|
|
|
|
const isBusy = isConnecting || isReconnecting;
|
|
|
|
|
const canDisconnect = isReady || isBusy;
|
|
|
|
|
const statusAgeMs = status ? Math.max(0, clockMs - status.updatedAtMs) : 0;
|
|
|
|
|
const reconnectAppearsStuck = isReconnecting && statusAgeMs > 12_000;
|
|
|
|
|
|
|
|
|
|
const hasChanges = React.useMemo(() => {
|
|
|
|
|
if (!draft || !selectedInstance) return false;
|
|
|
|
|
return JSON.stringify(draft) !== JSON.stringify(selectedInstance);
|
|
|
|
|
}, [draft, selectedInstance]);
|
|
|
|
|
|
|
|
|
|
const updateDraft = React.useCallback((updater: (current: DesktopSshInstance) => DesktopSshInstance) => {
|
|
|
|
|
setDraft((current) => (current ? updater(current) : current));
|
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
const handleSave = React.useCallback(async () => {
|
|
|
|
|
if (!draft) return;
|
|
|
|
|
const normalized = normalizeForSave(draft);
|
|
|
|
|
|
|
|
|
|
if (!normalized.sshCommand.trim()) {
|
2026-04-26 14:03:39 +03:00
|
|
|
toast.error(t('settings.remoteInstances.page.toast.sshCommandRequired'));
|
2026-02-26 20:26:12 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (normalized.localForward.bindHost === '0.0.0.0') {
|
|
|
|
|
const allow = window.confirm(
|
2026-04-26 14:03:39 +03:00
|
|
|
t('settings.remoteInstances.page.confirm.bindAllInterfaces'),
|
2026-02-26 20:26:12 +02:00
|
|
|
);
|
|
|
|
|
if (!allow) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
normalized.auth.sshPassword?.enabled &&
|
|
|
|
|
normalized.auth.sshPassword.value?.trim() &&
|
|
|
|
|
normalized.auth.sshPassword.store !== 'settings'
|
|
|
|
|
) {
|
2026-04-26 14:03:39 +03:00
|
|
|
const store = window.confirm(t('settings.remoteInstances.page.confirm.storeSshPasswordPlaintext'));
|
2026-02-26 20:26:12 +02:00
|
|
|
normalized.auth.sshPassword.store = store ? 'settings' : 'never';
|
|
|
|
|
if (!store) {
|
|
|
|
|
normalized.auth.sshPassword.value = undefined;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
normalized.auth.openchamberPassword?.enabled &&
|
|
|
|
|
normalized.auth.openchamberPassword.value?.trim() &&
|
|
|
|
|
normalized.auth.openchamberPassword.store !== 'settings'
|
|
|
|
|
) {
|
2026-04-26 14:03:39 +03:00
|
|
|
const store = window.confirm(t('settings.remoteInstances.page.confirm.storeUiPasswordPlaintext'));
|
2026-02-26 20:26:12 +02:00
|
|
|
normalized.auth.openchamberPassword.store = store ? 'settings' : 'never';
|
|
|
|
|
if (!store) {
|
|
|
|
|
normalized.auth.openchamberPassword.value = undefined;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
await upsertInstance(normalized);
|
2026-04-26 14:03:39 +03:00
|
|
|
toast.success(t('settings.remoteInstances.page.toast.instanceSaved'));
|
2026-02-26 20:26:12 +02:00
|
|
|
} catch (error) {
|
2026-04-26 14:03:39 +03:00
|
|
|
toast.error(t('settings.remoteInstances.page.toast.saveFailed'), {
|
2026-02-26 20:26:12 +02:00
|
|
|
description: error instanceof Error ? error.message : String(error),
|
|
|
|
|
});
|
|
|
|
|
}
|
2026-04-26 14:03:39 +03:00
|
|
|
}, [draft, t, upsertInstance]);
|
2026-02-26 20:26:12 +02:00
|
|
|
|
|
|
|
|
const createImportedInstance = React.useCallback(
|
|
|
|
|
async (host: string, destination: string): Promise<boolean> => {
|
|
|
|
|
const id = `ssh-${Date.now()}-${Math.random().toString(16).slice(2)}`;
|
|
|
|
|
try {
|
|
|
|
|
await createFromCommand(id, `ssh ${destination}`, host);
|
|
|
|
|
setSelectedId(id);
|
2026-04-26 14:03:39 +03:00
|
|
|
toast.success(t('settings.remoteInstances.page.toast.instanceCreated'));
|
2026-02-26 20:26:12 +02:00
|
|
|
return true;
|
|
|
|
|
} catch (error) {
|
2026-04-26 14:03:39 +03:00
|
|
|
toast.error(t('settings.remoteInstances.sidebar.toast.createFailed'), {
|
2026-02-26 20:26:12 +02:00
|
|
|
description: error instanceof Error ? error.message : String(error),
|
|
|
|
|
});
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
[createFromCommand, setSelectedId],
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const closePatternDialog = React.useCallback(() => {
|
|
|
|
|
if (patternCreating) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
setPatternHost(null);
|
|
|
|
|
setPatternDestination('');
|
|
|
|
|
}, [patternCreating]);
|
|
|
|
|
|
|
|
|
|
const handleImportCandidate = React.useCallback(
|
|
|
|
|
(host: string, pattern: boolean) => {
|
|
|
|
|
if (pattern) {
|
|
|
|
|
setPatternHost(host);
|
|
|
|
|
setPatternDestination(suggestConcreteHost(host));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
void createImportedInstance(host, host);
|
|
|
|
|
},
|
|
|
|
|
[createImportedInstance],
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const handlePatternCreate = React.useCallback(async () => {
|
|
|
|
|
const host = patternHost;
|
|
|
|
|
const destination = patternDestination.trim();
|
|
|
|
|
if (!host) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (!destination) {
|
2026-04-26 14:03:39 +03:00
|
|
|
toast.error(t('settings.remoteInstances.page.toast.destinationRequired'));
|
2026-02-26 20:26:12 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setPatternCreating(true);
|
|
|
|
|
try {
|
|
|
|
|
const created = await createImportedInstance(host, destination);
|
|
|
|
|
if (created) {
|
|
|
|
|
setPatternHost(null);
|
|
|
|
|
setPatternDestination('');
|
|
|
|
|
}
|
|
|
|
|
} finally {
|
|
|
|
|
setPatternCreating(false);
|
|
|
|
|
}
|
2026-04-26 14:03:39 +03:00
|
|
|
}, [createImportedInstance, patternDestination, patternHost, t]);
|
2026-02-26 20:26:12 +02:00
|
|
|
|
|
|
|
|
const connectWithPortRecovery = React.useCallback(async () => {
|
|
|
|
|
if (!selectedInstance) return;
|
|
|
|
|
try {
|
|
|
|
|
await connect(selectedInstance.id);
|
|
|
|
|
return;
|
|
|
|
|
} catch (error) {
|
|
|
|
|
if (!isPortInUseError(error)) {
|
|
|
|
|
throw error;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-26 14:03:39 +03:00
|
|
|
const allow = window.confirm(t('settings.remoteInstances.sidebar.confirm.localPortInUseRetry'));
|
2026-02-26 20:26:12 +02:00
|
|
|
if (!allow) {
|
|
|
|
|
throw error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const nextInstance: DesktopSshInstance = {
|
|
|
|
|
...selectedInstance,
|
|
|
|
|
localForward: {
|
|
|
|
|
...selectedInstance.localForward,
|
|
|
|
|
preferredLocalPort: randomPort(),
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
await upsertInstance(nextInstance);
|
|
|
|
|
await connect(nextInstance.id);
|
2026-04-26 14:03:39 +03:00
|
|
|
toast.success(t('settings.remoteInstances.sidebar.toast.retriedWithRandomPort'));
|
2026-02-26 20:26:12 +02:00
|
|
|
}
|
2026-04-26 14:03:39 +03:00
|
|
|
}, [connect, selectedInstance, t, upsertInstance]);
|
2026-02-26 20:26:12 +02:00
|
|
|
|
|
|
|
|
const readLogsForInstance = React.useCallback(async (id: string) => {
|
|
|
|
|
const lines = await desktopSshLogs(id, 600);
|
|
|
|
|
return lines.map((line) => formatLogLine(line));
|
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
const handleOpenLogs = React.useCallback(async () => {
|
|
|
|
|
if (!draft) return;
|
|
|
|
|
setLogDialogOpen(true);
|
|
|
|
|
setLogDialogLoading(true);
|
|
|
|
|
setLogDialogError(null);
|
|
|
|
|
try {
|
|
|
|
|
const lines = await readLogsForInstance(draft.id);
|
|
|
|
|
setLogDialogLines(lines);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
setLogDialogLines([]);
|
|
|
|
|
setLogDialogError(error instanceof Error ? error.message : String(error));
|
|
|
|
|
} finally {
|
|
|
|
|
setLogDialogLoading(false);
|
|
|
|
|
}
|
|
|
|
|
}, [draft, readLogsForInstance]);
|
|
|
|
|
|
|
|
|
|
React.useEffect(() => {
|
|
|
|
|
if (!logDialogOpen || !draft) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let disposed = false;
|
|
|
|
|
const run = async () => {
|
|
|
|
|
try {
|
|
|
|
|
const lines = await readLogsForInstance(draft.id);
|
|
|
|
|
if (!disposed) {
|
|
|
|
|
setLogDialogLines(lines);
|
|
|
|
|
setLogDialogError(null);
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
if (!disposed) {
|
|
|
|
|
setLogDialogError(error instanceof Error ? error.message : String(error));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void run();
|
|
|
|
|
const interval = window.setInterval(() => {
|
2026-04-06 21:05:02 +03:00
|
|
|
// Skip polling when tab is hidden
|
|
|
|
|
if (typeof document !== 'undefined' && document.visibilityState !== 'visible') {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2026-02-26 20:26:12 +02:00
|
|
|
void run();
|
|
|
|
|
}, 1_000);
|
|
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
|
disposed = true;
|
|
|
|
|
window.clearInterval(interval);
|
|
|
|
|
};
|
|
|
|
|
}, [draft, logDialogOpen, readLogsForInstance]);
|
|
|
|
|
|
|
|
|
|
const logLinesText = React.useMemo(() => logDialogLines.join('\n'), [logDialogLines]);
|
|
|
|
|
|
|
|
|
|
const handleCopyAllLogs = React.useCallback(() => {
|
|
|
|
|
if (!logLinesText.trim()) {
|
2026-04-26 14:03:39 +03:00
|
|
|
toast.error(t('settings.remoteInstances.page.toast.noLogsToCopy'));
|
2026-02-26 20:26:12 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
void copyTextToClipboard(logLinesText).then((result) => {
|
|
|
|
|
if (result.ok) {
|
2026-04-26 14:03:39 +03:00
|
|
|
toast.success(t('settings.remoteInstances.page.toast.logsCopied'));
|
2026-02-26 20:26:12 +02:00
|
|
|
}
|
|
|
|
|
});
|
2026-04-26 14:03:39 +03:00
|
|
|
}, [logLinesText, t]);
|
2026-02-26 20:26:12 +02:00
|
|
|
|
|
|
|
|
const handleClearLogs = React.useCallback(async () => {
|
|
|
|
|
if (!draft) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
await desktopSshLogsClear(draft.id);
|
|
|
|
|
setLogDialogLines([]);
|
2026-04-26 14:03:39 +03:00
|
|
|
toast.success(t('settings.remoteInstances.page.toast.logsCleared'));
|
2026-02-26 20:26:12 +02:00
|
|
|
} catch (error) {
|
2026-04-26 14:03:39 +03:00
|
|
|
toast.error(t('settings.remoteInstances.page.toast.clearLogsFailed'), {
|
2026-02-26 20:26:12 +02:00
|
|
|
description: error instanceof Error ? error.message : String(error),
|
|
|
|
|
});
|
|
|
|
|
}
|
2026-04-26 14:03:39 +03:00
|
|
|
}, [draft, t]);
|
2026-02-26 20:26:12 +02:00
|
|
|
|
|
|
|
|
const handleOpenCurrentInstance = React.useCallback(async () => {
|
|
|
|
|
if (!status?.localUrl) {
|
2026-04-26 14:03:39 +03:00
|
|
|
toast.error(t('settings.remoteInstances.page.toast.instanceUrlUnavailable'));
|
2026-02-26 20:26:12 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const target = status.localUrl.trim();
|
|
|
|
|
if (!target) {
|
2026-04-26 14:03:39 +03:00
|
|
|
toast.error(t('settings.remoteInstances.page.toast.instanceUrlUnavailable'));
|
2026-02-26 20:26:12 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
navigateToUrl(target);
|
2026-04-26 14:03:39 +03:00
|
|
|
}, [status?.localUrl, t]);
|
2026-02-26 20:26:12 +02:00
|
|
|
|
|
|
|
|
const handlePrimaryConnectionAction = React.useCallback(() => {
|
|
|
|
|
if (!draft) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setIsPrimaryActionPending(true);
|
|
|
|
|
const operation = canDisconnect ? disconnect(draft.id) : connectWithPortRecovery();
|
|
|
|
|
void operation
|
|
|
|
|
.catch((error) => {
|
2026-04-26 14:03:39 +03:00
|
|
|
const key = canDisconnect
|
|
|
|
|
? (isReady
|
|
|
|
|
? 'settings.remoteInstances.page.toast.disconnectFailed'
|
|
|
|
|
: 'settings.remoteInstances.page.toast.cancelConnectionFailed')
|
|
|
|
|
: 'settings.remoteInstances.page.toast.connectFailed';
|
|
|
|
|
toast.error(t(key), {
|
2026-02-26 20:26:12 +02:00
|
|
|
description: error instanceof Error ? error.message : String(error),
|
|
|
|
|
});
|
|
|
|
|
})
|
|
|
|
|
.finally(() => {
|
|
|
|
|
setIsPrimaryActionPending(false);
|
|
|
|
|
});
|
2026-04-26 14:03:39 +03:00
|
|
|
}, [canDisconnect, connectWithPortRecovery, disconnect, draft, isReady, t]);
|
2026-02-26 20:26:12 +02:00
|
|
|
|
|
|
|
|
const handleRetryAction = React.useCallback(() => {
|
|
|
|
|
if (!draft) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isConnecting) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setIsRetryPending(true);
|
|
|
|
|
const operation = isReconnecting
|
|
|
|
|
? disconnect(draft.id).then(() => connectWithPortRecovery())
|
|
|
|
|
: retry(draft.id);
|
|
|
|
|
|
|
|
|
|
void operation
|
|
|
|
|
.catch((error) => {
|
2026-04-26 14:03:39 +03:00
|
|
|
toast.error(t('settings.remoteInstances.page.toast.retryFailed'), {
|
2026-02-26 20:26:12 +02:00
|
|
|
description: error instanceof Error ? error.message : String(error),
|
|
|
|
|
});
|
|
|
|
|
})
|
|
|
|
|
.finally(() => {
|
|
|
|
|
setIsRetryPending(false);
|
|
|
|
|
});
|
2026-04-26 14:03:39 +03:00
|
|
|
}, [connectWithPortRecovery, disconnect, draft, isConnecting, isReconnecting, retry, t]);
|
2026-02-26 20:26:12 +02:00
|
|
|
|
|
|
|
|
const retryButtonLabel = isConnecting
|
2026-04-26 14:03:39 +03:00
|
|
|
? t('settings.remoteInstances.page.actions.connecting')
|
2026-02-26 20:26:12 +02:00
|
|
|
: isReconnecting
|
|
|
|
|
? reconnectAppearsStuck
|
2026-04-26 14:03:39 +03:00
|
|
|
? t('settings.remoteInstances.page.actions.reconnectNow')
|
|
|
|
|
: t('settings.remoteInstances.page.actions.reconnecting')
|
|
|
|
|
: t('settings.remoteInstances.sidebar.actions.retry');
|
2026-02-26 20:26:12 +02:00
|
|
|
|
|
|
|
|
const canRetry =
|
|
|
|
|
!isPrimaryActionPending &&
|
|
|
|
|
!isRetryPending &&
|
|
|
|
|
(statusPhase === 'error' || statusPhase === 'idle' || !statusPhase || (isReconnecting && reconnectAppearsStuck)) &&
|
|
|
|
|
!isConnecting;
|
|
|
|
|
|
2026-04-26 14:03:39 +03:00
|
|
|
const primaryButtonLabel = isReady
|
|
|
|
|
? t('settings.remoteInstances.sidebar.actions.disconnect')
|
|
|
|
|
: canDisconnect
|
|
|
|
|
? t('settings.remoteInstances.page.actions.cancel')
|
|
|
|
|
: t('settings.remoteInstances.sidebar.actions.connect');
|
2026-02-26 20:26:12 +02:00
|
|
|
|
|
|
|
|
if (!draft) {
|
|
|
|
|
return (
|
|
|
|
|
<SettingsPageLayout>
|
|
|
|
|
<div className="mb-8">
|
|
|
|
|
<div className="mb-1 px-1 space-y-0.5">
|
2026-04-26 14:03:39 +03:00
|
|
|
<h3 className="typography-ui-header font-medium text-foreground">{t('settings.remoteInstances.page.title')}</h3>
|
|
|
|
|
<p className="typography-meta text-muted-foreground">{t('settings.remoteInstances.page.description')}</p>
|
2026-02-26 20:26:12 +02:00
|
|
|
</div>
|
|
|
|
|
<section className="px-2 pb-2 pt-0 space-y-3">
|
2026-04-26 14:03:39 +03:00
|
|
|
<p className="typography-meta text-muted-foreground">{t('settings.remoteInstances.page.empty.selectInstance')}</p>
|
2026-02-26 20:26:12 +02:00
|
|
|
</section>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="mb-8 border-t border-[var(--surface-subtle)] pt-8">
|
|
|
|
|
<div className="mb-1 px-1 space-y-0.5">
|
2026-04-26 14:03:39 +03:00
|
|
|
<h3 className="typography-ui-header font-medium text-foreground">{t('settings.remoteInstances.page.import.sectionTitle')}</h3>
|
2026-02-26 20:26:12 +02:00
|
|
|
</div>
|
|
|
|
|
<section className="px-2 pb-2 pt-0">
|
|
|
|
|
{isImportsLoading ? (
|
2026-04-26 14:03:39 +03:00
|
|
|
<p className="typography-meta text-muted-foreground">{t('settings.remoteInstances.page.import.loading')}</p>
|
2026-02-26 20:26:12 +02:00
|
|
|
) : importCandidates.length === 0 ? (
|
2026-04-26 14:03:39 +03:00
|
|
|
<p className="typography-meta text-muted-foreground">{t('settings.remoteInstances.page.import.noneFound')}</p>
|
2026-02-26 20:26:12 +02:00
|
|
|
) : (
|
|
|
|
|
<div className="space-y-2">
|
|
|
|
|
{importCandidates.map((candidate) => (
|
|
|
|
|
<div key={`${candidate.source}:${candidate.host}`} className="flex items-center justify-between gap-3 rounded-md border border-[var(--interactive-border)] px-3 py-2">
|
|
|
|
|
<div className="min-w-0">
|
|
|
|
|
<div className="typography-ui-label text-foreground truncate">
|
|
|
|
|
{candidate.host}
|
2026-04-26 14:03:39 +03:00
|
|
|
{candidate.pattern ? ` ${t('settings.remoteInstances.page.import.patternSuffix')}` : ''}
|
2026-02-26 20:26:12 +02:00
|
|
|
</div>
|
|
|
|
|
<div className="typography-micro text-muted-foreground">{candidate.source} config</div>
|
|
|
|
|
</div>
|
2026-03-20 01:01:03 +02:00
|
|
|
<Button
|
2026-02-26 20:26:12 +02:00
|
|
|
type="button"
|
|
|
|
|
variant="outline"
|
|
|
|
|
size="xs"
|
|
|
|
|
className="!font-normal"
|
|
|
|
|
onClick={() => void handleImportCandidate(candidate.host, candidate.pattern)}
|
|
|
|
|
>
|
2026-04-26 14:03:39 +03:00
|
|
|
{t('settings.remoteInstances.page.actions.create')}
|
2026-03-20 01:01:03 +02:00
|
|
|
</Button>
|
2026-02-26 20:26:12 +02:00
|
|
|
</div>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</section>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<Dialog
|
|
|
|
|
open={Boolean(patternHost)}
|
|
|
|
|
onOpenChange={(open) => {
|
|
|
|
|
if (!open) {
|
|
|
|
|
closePatternDialog();
|
|
|
|
|
}
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<DialogContent className="sm:max-w-md">
|
|
|
|
|
<DialogHeader>
|
2026-04-26 14:03:39 +03:00
|
|
|
<DialogTitle>{t('settings.remoteInstances.page.patternDialog.title')}</DialogTitle>
|
2026-02-26 20:26:12 +02:00
|
|
|
<DialogDescription>
|
2026-04-26 14:03:39 +03:00
|
|
|
{patternHost ? t('settings.remoteInstances.page.patternDialog.descriptionWithHost', { host: patternHost }) : t('settings.remoteInstances.page.patternDialog.description')}
|
2026-02-26 20:26:12 +02:00
|
|
|
</DialogDescription>
|
|
|
|
|
</DialogHeader>
|
|
|
|
|
<form
|
|
|
|
|
className="space-y-3"
|
|
|
|
|
onSubmit={(event) => {
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
handlePatternCreate();
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Input
|
|
|
|
|
value={patternDestination}
|
|
|
|
|
onChange={(event) => setPatternDestination(event.target.value)}
|
2026-04-26 14:03:39 +03:00
|
|
|
placeholder={t('settings.remoteInstances.page.patternDialog.destinationPlaceholder')}
|
2026-02-26 20:26:12 +02:00
|
|
|
autoFocus
|
|
|
|
|
/>
|
|
|
|
|
<div className="flex items-center justify-end gap-2">
|
2026-03-20 01:01:03 +02:00
|
|
|
<Button type="button" variant="outline" size="xs" className="!font-normal" onClick={closePatternDialog} disabled={patternCreating}>
|
2026-04-26 14:03:39 +03:00
|
|
|
{t('settings.common.actions.cancel')}
|
2026-03-20 01:01:03 +02:00
|
|
|
</Button>
|
|
|
|
|
<Button type="submit" size="xs" className="!font-normal" disabled={patternCreating}>
|
2026-04-26 14:03:39 +03:00
|
|
|
{t('settings.remoteInstances.page.actions.create')}
|
2026-03-20 01:01:03 +02:00
|
|
|
</Button>
|
2026-02-26 20:26:12 +02:00
|
|
|
</div>
|
|
|
|
|
</form>
|
|
|
|
|
</DialogContent>
|
|
|
|
|
</Dialog>
|
|
|
|
|
</SettingsPageLayout>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const isManagedMode = draft.remoteOpenchamber.mode === 'managed';
|
|
|
|
|
const instanceTitle = draft.nickname?.trim() || draft.sshParsed?.destination || draft.id;
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<SettingsPageLayout>
|
|
|
|
|
<div className="mb-6 px-1">
|
|
|
|
|
<h2 className="typography-ui-header font-semibold text-foreground truncate">{instanceTitle}</h2>
|
|
|
|
|
<div className="mt-1 flex flex-wrap items-center gap-2 typography-meta text-muted-foreground">
|
|
|
|
|
<span className={`h-2.5 w-2.5 rounded-full ${phaseDotClass(statusPhase)}`} />
|
2026-04-26 14:03:39 +03:00
|
|
|
<span>{t(phaseLabelKey(statusPhase))}</span>
|
2026-02-26 20:26:12 +02:00
|
|
|
{status?.localUrl ? <span className="font-mono text-foreground/80">{status.localUrl}</span> : null}
|
2026-04-26 14:03:39 +03:00
|
|
|
{reconnectAppearsStuck ? <span>{t('settings.remoteInstances.page.status.reconnectStale')}</span> : null}
|
2026-02-26 20:26:12 +02:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="mb-8">
|
|
|
|
|
<div className="mb-1 px-1 space-y-0.5">
|
2026-04-26 14:03:39 +03:00
|
|
|
<h3 className="typography-ui-header font-medium text-foreground">{t('settings.remoteInstances.page.section.actions')}</h3>
|
|
|
|
|
<p className="typography-meta text-muted-foreground">{t('settings.remoteInstances.page.section.actionsDescription')}</p>
|
2026-02-26 20:26:12 +02:00
|
|
|
</div>
|
|
|
|
|
<section className="px-2 pb-2 pt-0 space-y-3">
|
|
|
|
|
<div className="flex flex-wrap items-center gap-2">
|
2026-03-20 01:01:03 +02:00
|
|
|
<Button
|
2026-02-26 20:26:12 +02:00
|
|
|
type="button"
|
|
|
|
|
variant={canDisconnect ? 'outline' : 'default'}
|
|
|
|
|
size="xs"
|
|
|
|
|
className="!font-normal"
|
|
|
|
|
onClick={handlePrimaryConnectionAction}
|
|
|
|
|
disabled={isPrimaryActionPending || isRetryPending}
|
|
|
|
|
>
|
|
|
|
|
{canDisconnect ? <RiStopLine className="h-3.5 w-3.5" /> : <RiPlug2Line className="h-3.5 w-3.5" />}
|
|
|
|
|
{primaryButtonLabel}
|
2026-03-20 01:01:03 +02:00
|
|
|
</Button>
|
|
|
|
|
<Button
|
2026-02-26 20:26:12 +02:00
|
|
|
type="button"
|
|
|
|
|
variant="outline"
|
|
|
|
|
size="xs"
|
|
|
|
|
className="!font-normal"
|
|
|
|
|
onClick={handleRetryAction}
|
|
|
|
|
disabled={!canRetry}
|
|
|
|
|
>
|
|
|
|
|
<RiRefreshLine className={`h-3.5 w-3.5 ${isConnecting || (isReconnecting && !reconnectAppearsStuck) ? 'animate-spin' : ''}`} />
|
|
|
|
|
{retryButtonLabel}
|
2026-03-20 01:01:03 +02:00
|
|
|
</Button>
|
|
|
|
|
<Button
|
2026-02-26 20:26:12 +02:00
|
|
|
type="button"
|
|
|
|
|
variant="outline"
|
|
|
|
|
size="xs"
|
|
|
|
|
className="!font-normal"
|
|
|
|
|
onClick={() => {
|
|
|
|
|
void handleOpenLogs();
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<RiTerminalWindowLine className="h-3.5 w-3.5" />
|
2026-04-26 14:03:39 +03:00
|
|
|
{t('settings.remoteInstances.page.actions.logs')}
|
2026-03-20 01:01:03 +02:00
|
|
|
</Button>
|
|
|
|
|
<Button
|
2026-02-26 20:26:12 +02:00
|
|
|
type="button"
|
|
|
|
|
variant="outline"
|
|
|
|
|
size="xs"
|
|
|
|
|
className="!font-normal text-[var(--status-error)] border-[var(--status-error)]/30 hover:text-[var(--status-error)]"
|
|
|
|
|
onClick={() => {
|
2026-04-26 14:03:39 +03:00
|
|
|
const ok = window.confirm(t('settings.remoteInstances.page.confirm.removeInstance'));
|
2026-02-26 20:26:12 +02:00
|
|
|
if (!ok) return;
|
|
|
|
|
void removeInstance(draft.id)
|
|
|
|
|
.then(() => {
|
|
|
|
|
setSelectedId(null);
|
2026-04-26 14:03:39 +03:00
|
|
|
toast.success(t('settings.remoteInstances.page.toast.instanceRemoved'));
|
2026-02-26 20:26:12 +02:00
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
2026-04-26 14:03:39 +03:00
|
|
|
toast.error(t('settings.remoteInstances.page.toast.removeInstanceFailed'), {
|
2026-02-26 20:26:12 +02:00
|
|
|
description: err instanceof Error ? err.message : String(err),
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<RiDeleteBinLine className="h-3.5 w-3.5" />
|
2026-04-26 14:03:39 +03:00
|
|
|
{t('settings.remoteInstances.sidebar.actions.remove')}
|
2026-03-20 01:01:03 +02:00
|
|
|
</Button>
|
2026-02-26 20:26:12 +02:00
|
|
|
</div>
|
|
|
|
|
{status?.localUrl ? (
|
|
|
|
|
<div className="flex flex-wrap items-center gap-2 typography-meta text-muted-foreground">
|
2026-04-26 14:03:39 +03:00
|
|
|
<span>{t('settings.remoteInstances.page.status.currentLocalUrl')}</span>
|
2026-02-26 20:26:12 +02:00
|
|
|
<span className="font-mono text-foreground/90">{status.localUrl}</span>
|
|
|
|
|
</div>
|
|
|
|
|
) : null}
|
|
|
|
|
</section>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="mb-8">
|
|
|
|
|
<div className="mb-1 px-1 space-y-0.5">
|
2026-04-26 14:03:39 +03:00
|
|
|
<h3 className="typography-ui-header font-medium text-foreground">{t('settings.remoteInstances.page.section.instance')}</h3>
|
|
|
|
|
<p className="typography-meta text-muted-foreground">{t('settings.remoteInstances.page.section.instanceDescription')}</p>
|
2026-02-26 20:26:12 +02:00
|
|
|
</div>
|
|
|
|
|
<section className="px-2 pb-2 pt-0 space-y-3">
|
|
|
|
|
<div className="flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8">
|
2026-04-26 14:03:39 +03:00
|
|
|
<span className="typography-ui-label text-foreground w-56 shrink-0">{t('settings.remoteInstances.page.field.sshCommand')}</span>
|
2026-02-26 20:26:12 +02:00
|
|
|
<Input
|
|
|
|
|
className="h-7 md:max-w-xl"
|
|
|
|
|
value={draft.sshCommand}
|
|
|
|
|
onChange={(event) =>
|
|
|
|
|
updateDraft((current) => ({
|
|
|
|
|
...current,
|
|
|
|
|
sshCommand: event.target.value,
|
|
|
|
|
}))
|
|
|
|
|
}
|
2026-04-26 14:03:39 +03:00
|
|
|
placeholder={t('settings.remoteInstances.page.field.sshCommandPlaceholder')}
|
2026-02-26 20:26:12 +02:00
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8">
|
2026-04-26 14:03:39 +03:00
|
|
|
<span className="typography-ui-label text-foreground w-56 shrink-0">{t('settings.remoteInstances.page.field.nickname')}</span>
|
2026-02-26 20:26:12 +02:00
|
|
|
<Input
|
|
|
|
|
className="h-7 md:max-w-sm"
|
|
|
|
|
value={draft.nickname || ''}
|
|
|
|
|
onChange={(event) =>
|
|
|
|
|
updateDraft((current) => ({
|
|
|
|
|
...current,
|
|
|
|
|
nickname: event.target.value,
|
|
|
|
|
}))
|
|
|
|
|
}
|
2026-04-26 14:03:39 +03:00
|
|
|
placeholder={t('settings.remoteInstances.page.field.nicknamePlaceholder')}
|
2026-02-26 20:26:12 +02:00
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8">
|
2026-04-26 14:03:39 +03:00
|
|
|
<span className="typography-ui-label text-foreground w-56 shrink-0">{t('settings.remoteInstances.page.field.connectionTimeoutSeconds')}</span>
|
2026-02-26 20:26:12 +02:00
|
|
|
<NumberInput
|
|
|
|
|
containerClassName="w-fit"
|
|
|
|
|
min={5}
|
|
|
|
|
max={240}
|
|
|
|
|
step={1}
|
|
|
|
|
className="w-16 tabular-nums"
|
|
|
|
|
value={draft.connectionTimeoutSec}
|
|
|
|
|
onValueChange={(next) => {
|
|
|
|
|
updateDraft((current) => ({
|
|
|
|
|
...current,
|
|
|
|
|
connectionTimeoutSec: Number.isFinite(next) ? next : current.connectionTimeoutSec,
|
|
|
|
|
}));
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</section>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="mb-8 border-t border-[var(--surface-subtle)] pt-8">
|
|
|
|
|
<div className="mb-1 px-1 space-y-0.5">
|
2026-04-26 14:03:39 +03:00
|
|
|
<h3 className="typography-ui-header font-medium text-foreground">{t('settings.remoteInstances.page.section.remoteServer')}</h3>
|
|
|
|
|
<p className="typography-meta text-muted-foreground">{t('settings.remoteInstances.page.section.remoteServerDescription')}</p>
|
2026-02-26 20:26:12 +02:00
|
|
|
</div>
|
|
|
|
|
<section className="px-2 pb-2 pt-0 space-y-3">
|
|
|
|
|
<div className="flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8">
|
|
|
|
|
<div className="w-56 shrink-0">
|
2026-04-26 14:03:39 +03:00
|
|
|
<HintLabel
|
|
|
|
|
label={t('settings.remoteInstances.page.field.mode')}
|
|
|
|
|
hint={t('settings.remoteInstances.page.field.modeHint')}
|
|
|
|
|
/>
|
2026-02-26 20:26:12 +02:00
|
|
|
</div>
|
|
|
|
|
<Select
|
|
|
|
|
value={draft.remoteOpenchamber.mode}
|
|
|
|
|
onValueChange={(value) =>
|
|
|
|
|
updateDraft((current) => ({
|
|
|
|
|
...current,
|
|
|
|
|
remoteOpenchamber: {
|
|
|
|
|
...current.remoteOpenchamber,
|
|
|
|
|
mode: value === 'external' ? 'external' : 'managed',
|
|
|
|
|
},
|
|
|
|
|
}))
|
|
|
|
|
}
|
|
|
|
|
>
|
|
|
|
|
<SelectTrigger className="h-7 w-fit min-w-[140px]">
|
2026-04-26 14:03:39 +03:00
|
|
|
<SelectValue placeholder={t('settings.remoteInstances.page.field.modePlaceholder')} />
|
2026-02-26 20:26:12 +02:00
|
|
|
</SelectTrigger>
|
|
|
|
|
<SelectContent>
|
2026-04-26 14:03:39 +03:00
|
|
|
<SelectItem value="managed">{t('settings.remoteInstances.page.field.modeManaged')}</SelectItem>
|
|
|
|
|
<SelectItem value="external">{t('settings.remoteInstances.page.field.modeExternal')}</SelectItem>
|
2026-02-26 20:26:12 +02:00
|
|
|
</SelectContent>
|
|
|
|
|
</Select>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8">
|
|
|
|
|
<div className="w-56 shrink-0">
|
2026-04-26 14:03:39 +03:00
|
|
|
<HintLabel
|
|
|
|
|
label={t('settings.remoteInstances.page.field.preferredRemotePort')}
|
|
|
|
|
hint={t('settings.remoteInstances.page.field.preferredRemotePortHint')}
|
|
|
|
|
/>
|
2026-02-26 20:26:12 +02:00
|
|
|
</div>
|
|
|
|
|
<NumberInput
|
|
|
|
|
containerClassName="w-fit"
|
|
|
|
|
min={1}
|
|
|
|
|
max={65535}
|
|
|
|
|
step={1}
|
|
|
|
|
className="w-20 tabular-nums"
|
|
|
|
|
value={draft.remoteOpenchamber.preferredPort}
|
|
|
|
|
onValueChange={(next) => {
|
|
|
|
|
updateDraft((current) => ({
|
|
|
|
|
...current,
|
|
|
|
|
remoteOpenchamber: {
|
|
|
|
|
...current.remoteOpenchamber,
|
|
|
|
|
preferredPort: Number.isFinite(next) && next > 0 ? next : undefined,
|
|
|
|
|
},
|
|
|
|
|
}));
|
|
|
|
|
}}
|
|
|
|
|
onClear={() => {
|
|
|
|
|
updateDraft((current) => ({
|
|
|
|
|
...current,
|
|
|
|
|
remoteOpenchamber: {
|
|
|
|
|
...current.remoteOpenchamber,
|
|
|
|
|
preferredPort: undefined,
|
|
|
|
|
},
|
|
|
|
|
}));
|
|
|
|
|
}}
|
2026-04-26 14:03:39 +03:00
|
|
|
emptyLabel={t('settings.remoteInstances.page.field.auto')}
|
2026-02-26 20:26:12 +02:00
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{isManagedMode ? (
|
|
|
|
|
<div className="flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8">
|
|
|
|
|
<div className="w-56 shrink-0">
|
|
|
|
|
<HintLabel
|
2026-04-26 14:03:39 +03:00
|
|
|
label={t('settings.remoteInstances.page.field.installMethod')}
|
|
|
|
|
hint={t('settings.remoteInstances.page.field.installMethodHint')}
|
2026-02-26 20:26:12 +02:00
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
<Select
|
|
|
|
|
value={draft.remoteOpenchamber.installMethod}
|
|
|
|
|
onValueChange={(value) =>
|
|
|
|
|
updateDraft((current) => ({
|
|
|
|
|
...current,
|
|
|
|
|
remoteOpenchamber: {
|
|
|
|
|
...current.remoteOpenchamber,
|
|
|
|
|
installMethod:
|
|
|
|
|
value === 'npm' || value === 'download_release' || value === 'upload_bundle'
|
|
|
|
|
? value
|
|
|
|
|
: 'bun',
|
|
|
|
|
},
|
|
|
|
|
}))
|
|
|
|
|
}
|
|
|
|
|
>
|
|
|
|
|
<SelectTrigger className="h-7 w-fit min-w-[140px]">
|
2026-04-26 14:03:39 +03:00
|
|
|
<SelectValue placeholder={t('settings.remoteInstances.page.field.selectInstallMethodPlaceholder')} />
|
2026-02-26 20:26:12 +02:00
|
|
|
</SelectTrigger>
|
|
|
|
|
<SelectContent>
|
|
|
|
|
<SelectItem value="bun">bun</SelectItem>
|
|
|
|
|
<SelectItem value="npm">npm</SelectItem>
|
2026-04-26 14:03:39 +03:00
|
|
|
<SelectItem value="download_release">{t('settings.remoteInstances.page.field.installMethodDownloadRelease')}</SelectItem>
|
|
|
|
|
<SelectItem value="upload_bundle">{t('settings.remoteInstances.page.field.installMethodUploadBundle')}</SelectItem>
|
2026-02-26 20:26:12 +02:00
|
|
|
</SelectContent>
|
|
|
|
|
</Select>
|
|
|
|
|
</div>
|
|
|
|
|
) : null}
|
|
|
|
|
|
|
|
|
|
{isManagedMode ? (
|
|
|
|
|
<div className="flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8">
|
|
|
|
|
<div className="w-56 shrink-0">
|
|
|
|
|
<HintLabel
|
2026-04-26 14:03:39 +03:00
|
|
|
label={t('settings.remoteInstances.page.field.keepServerRunning')}
|
|
|
|
|
hint={t('settings.remoteInstances.page.field.keepServerRunningHint')}
|
2026-02-26 20:26:12 +02:00
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="flex w-full items-center gap-2 md:max-w-xs">
|
|
|
|
|
<Switch
|
|
|
|
|
checked={draft.remoteOpenchamber.keepRunning}
|
|
|
|
|
onCheckedChange={(checked) =>
|
|
|
|
|
updateDraft((current) => ({
|
|
|
|
|
...current,
|
|
|
|
|
remoteOpenchamber: {
|
|
|
|
|
...current.remoteOpenchamber,
|
|
|
|
|
keepRunning: checked,
|
|
|
|
|
},
|
|
|
|
|
}))
|
|
|
|
|
}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
) : null}
|
|
|
|
|
</section>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="mb-8 border-t border-[var(--surface-subtle)] pt-8">
|
|
|
|
|
<div className="mb-1 px-1 space-y-0.5">
|
2026-04-26 14:03:39 +03:00
|
|
|
<h3 className="typography-ui-header font-medium text-foreground">{t('settings.remoteInstances.page.section.mainTunnel')}</h3>
|
|
|
|
|
<p className="typography-meta text-muted-foreground">{t('settings.remoteInstances.page.section.mainTunnelDescription')}</p>
|
2026-02-26 20:26:12 +02:00
|
|
|
</div>
|
|
|
|
|
<section className="px-2 pb-2 pt-0 space-y-3">
|
|
|
|
|
<div className="flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8">
|
|
|
|
|
<div className="w-56 shrink-0">
|
2026-04-26 14:03:39 +03:00
|
|
|
<HintLabel
|
|
|
|
|
label={t('settings.remoteInstances.page.field.bindHost')}
|
|
|
|
|
hint={t('settings.remoteInstances.page.field.bindHostHint')}
|
|
|
|
|
/>
|
2026-02-26 20:26:12 +02:00
|
|
|
</div>
|
|
|
|
|
<Select
|
|
|
|
|
value={draft.localForward.bindHost}
|
|
|
|
|
onValueChange={(value) => {
|
|
|
|
|
if (value === '0.0.0.0') {
|
|
|
|
|
const allow = window.confirm(
|
2026-04-26 14:03:39 +03:00
|
|
|
t('settings.remoteInstances.page.confirm.bindAllInterfaces'),
|
2026-02-26 20:26:12 +02:00
|
|
|
);
|
|
|
|
|
if (!allow) return;
|
|
|
|
|
}
|
|
|
|
|
updateDraft((current) => ({
|
|
|
|
|
...current,
|
|
|
|
|
localForward: {
|
|
|
|
|
...current.localForward,
|
|
|
|
|
bindHost: value === 'localhost' || value === '0.0.0.0' ? value : '127.0.0.1',
|
|
|
|
|
},
|
|
|
|
|
}));
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<SelectTrigger className="h-7 w-fit min-w-[140px]">
|
2026-04-26 14:03:39 +03:00
|
|
|
<SelectValue placeholder={t('settings.remoteInstances.page.field.selectBindHostPlaceholder')} />
|
2026-02-26 20:26:12 +02:00
|
|
|
</SelectTrigger>
|
|
|
|
|
<SelectContent>
|
|
|
|
|
<SelectItem value="127.0.0.1">127.0.0.1</SelectItem>
|
|
|
|
|
<SelectItem value="localhost">localhost</SelectItem>
|
|
|
|
|
<SelectItem value="0.0.0.0">0.0.0.0</SelectItem>
|
|
|
|
|
</SelectContent>
|
|
|
|
|
</Select>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8">
|
|
|
|
|
<div className="w-56 shrink-0">
|
2026-04-26 14:03:39 +03:00
|
|
|
<HintLabel
|
|
|
|
|
label={t('settings.remoteInstances.page.field.preferredLocalPort')}
|
|
|
|
|
hint={t('settings.remoteInstances.page.field.preferredLocalPortHint')}
|
|
|
|
|
/>
|
2026-02-26 20:26:12 +02:00
|
|
|
</div>
|
|
|
|
|
<div className="flex w-full items-center gap-2 md:max-w-sm">
|
|
|
|
|
<NumberInput
|
|
|
|
|
containerClassName="w-fit"
|
|
|
|
|
min={1}
|
|
|
|
|
max={65535}
|
|
|
|
|
step={1}
|
|
|
|
|
className="w-20 tabular-nums"
|
|
|
|
|
value={draft.localForward.preferredLocalPort}
|
|
|
|
|
onValueChange={(next) => {
|
|
|
|
|
updateDraft((current) => ({
|
|
|
|
|
...current,
|
|
|
|
|
localForward: {
|
|
|
|
|
...current.localForward,
|
|
|
|
|
preferredLocalPort: Number.isFinite(next) && next > 0 ? next : undefined,
|
|
|
|
|
},
|
|
|
|
|
}));
|
|
|
|
|
}}
|
|
|
|
|
onClear={() => {
|
|
|
|
|
updateDraft((current) => ({
|
|
|
|
|
...current,
|
|
|
|
|
localForward: {
|
|
|
|
|
...current.localForward,
|
|
|
|
|
preferredLocalPort: undefined,
|
|
|
|
|
},
|
|
|
|
|
}));
|
|
|
|
|
}}
|
2026-04-26 14:03:39 +03:00
|
|
|
emptyLabel={t('settings.remoteInstances.page.field.auto')}
|
2026-02-26 20:26:12 +02:00
|
|
|
/>
|
2026-03-20 01:01:03 +02:00
|
|
|
<Button
|
2026-02-26 20:26:12 +02:00
|
|
|
type="button"
|
|
|
|
|
variant="outline"
|
|
|
|
|
size="xs"
|
|
|
|
|
className="!font-normal h-7 w-7 px-0"
|
2026-04-26 14:03:39 +03:00
|
|
|
title={t('settings.remoteInstances.page.actions.pickRandomPort')}
|
2026-02-26 20:26:12 +02:00
|
|
|
onClick={() =>
|
|
|
|
|
updateDraft((current) => ({
|
|
|
|
|
...current,
|
|
|
|
|
localForward: {
|
|
|
|
|
...current.localForward,
|
|
|
|
|
preferredLocalPort: randomPort(),
|
|
|
|
|
},
|
|
|
|
|
}))
|
|
|
|
|
}
|
|
|
|
|
>
|
|
|
|
|
<RiShuffleLine className="h-3.5 w-3.5" />
|
2026-03-20 01:01:03 +02:00
|
|
|
</Button>
|
2026-02-26 20:26:12 +02:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</section>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="mb-8 border-t border-[var(--surface-subtle)] pt-8">
|
|
|
|
|
<div className="mb-1 px-1 space-y-0.5">
|
2026-04-26 14:03:39 +03:00
|
|
|
<h3 className="typography-ui-header font-medium text-foreground">{t('settings.remoteInstances.page.section.authentication')}</h3>
|
|
|
|
|
<p className="typography-meta text-muted-foreground">{t('settings.remoteInstances.page.section.authenticationDescription')}</p>
|
2026-02-26 20:26:12 +02:00
|
|
|
</div>
|
|
|
|
|
<section className="px-2 pb-2 pt-0 space-y-3">
|
|
|
|
|
<div className="flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8">
|
2026-04-26 14:03:39 +03:00
|
|
|
<span className="typography-ui-label text-foreground w-56 shrink-0">{t('settings.remoteInstances.page.field.sshPasswordOptional')}</span>
|
2026-02-26 20:26:12 +02:00
|
|
|
<Input
|
|
|
|
|
className="h-7 md:max-w-sm"
|
|
|
|
|
type="password"
|
|
|
|
|
value={draft.auth.sshPassword?.value || ''}
|
|
|
|
|
onChange={(event) =>
|
|
|
|
|
updateDraft((current) => ({
|
|
|
|
|
...current,
|
|
|
|
|
auth: {
|
|
|
|
|
...current.auth,
|
|
|
|
|
sshPassword: {
|
|
|
|
|
enabled: event.target.value.trim().length > 0,
|
|
|
|
|
value: event.target.value,
|
|
|
|
|
store: current.auth.sshPassword?.store || 'never',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}))
|
|
|
|
|
}
|
2026-04-26 14:03:39 +03:00
|
|
|
placeholder={t('settings.remoteInstances.page.field.sshPasswordPlaceholder')}
|
2026-02-26 20:26:12 +02:00
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8">
|
2026-04-26 14:03:39 +03:00
|
|
|
<span className="typography-ui-label text-foreground w-56 shrink-0">{t('settings.remoteInstances.page.field.uiPasswordOptional')}</span>
|
2026-02-26 20:26:12 +02:00
|
|
|
<Input
|
|
|
|
|
className="h-7 md:max-w-sm"
|
|
|
|
|
type="password"
|
|
|
|
|
value={draft.auth.openchamberPassword?.value || ''}
|
|
|
|
|
onChange={(event) =>
|
|
|
|
|
updateDraft((current) => ({
|
|
|
|
|
...current,
|
|
|
|
|
auth: {
|
|
|
|
|
...current.auth,
|
|
|
|
|
openchamberPassword: {
|
|
|
|
|
enabled: event.target.value.trim().length > 0,
|
|
|
|
|
value: event.target.value,
|
|
|
|
|
store: current.auth.openchamberPassword?.store || 'never',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}))
|
|
|
|
|
}
|
2026-04-26 14:03:39 +03:00
|
|
|
placeholder={t('settings.remoteInstances.page.field.uiPasswordPlaceholder')}
|
2026-02-26 20:26:12 +02:00
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</section>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="mb-8 border-t border-[var(--surface-subtle)] pt-8">
|
|
|
|
|
<div className="mb-1 px-1 space-y-0.5">
|
2026-04-26 14:03:39 +03:00
|
|
|
<h3 className="typography-ui-header font-medium text-foreground">{t('settings.remoteInstances.page.section.portForwards')}</h3>
|
|
|
|
|
<p className="typography-meta text-muted-foreground">{t('settings.remoteInstances.page.section.portForwardsDescription')}</p>
|
2026-02-26 20:26:12 +02:00
|
|
|
</div>
|
|
|
|
|
<section className="px-2 pb-2 pt-0 space-y-2">
|
|
|
|
|
{draft.portForwards.length === 0 ? (
|
2026-04-26 14:03:39 +03:00
|
|
|
<p className="typography-micro text-muted-foreground/80">{t('settings.remoteInstances.page.empty.noExtraForwards')}</p>
|
2026-02-26 20:26:12 +02:00
|
|
|
) : null}
|
|
|
|
|
|
|
|
|
|
{draft.portForwards.map((forward, index) => {
|
|
|
|
|
const updateForward = (updater: (forward: DesktopSshPortForward) => DesktopSshPortForward) => {
|
|
|
|
|
updateDraft((current) => ({
|
|
|
|
|
...current,
|
|
|
|
|
portForwards: current.portForwards.map((item, itemIndex) =>
|
|
|
|
|
itemIndex === index ? updater(item) : item,
|
|
|
|
|
),
|
|
|
|
|
}));
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const localLabel = forward.type === 'remote' ? 'Local target' : 'Local listen';
|
|
|
|
|
const localHint = forward.type === 'remote'
|
|
|
|
|
? 'Local host and port on your machine that receives traffic from remote -R listener.'
|
|
|
|
|
: 'Local host and port where this forward listens on your machine.';
|
|
|
|
|
const remoteLabel = forward.type === 'remote' ? 'Remote listen' : 'Remote target';
|
|
|
|
|
const remoteHint = forward.type === 'remote'
|
|
|
|
|
? 'Remote host and port where SSH creates the -R listener.'
|
|
|
|
|
: 'Remote host and port that receives traffic from local -L listener.';
|
|
|
|
|
|
|
|
|
|
const localEndpoint = formatEndpoint(forward.localHost || 'localhost', forward.localPort);
|
|
|
|
|
const remoteEndpoint = formatEndpoint(forward.remoteHost || 'localhost', forward.remotePort);
|
|
|
|
|
const canOpenLocalEndpoint =
|
|
|
|
|
forward.type === 'local' && typeof forward.localPort === 'number' && forward.localPort > 0;
|
|
|
|
|
const localEndpointUrl = canOpenLocalEndpoint
|
|
|
|
|
? `http://${toBrowserHost(forward.localHost)}:${forward.localPort}`
|
|
|
|
|
: '';
|
|
|
|
|
|
|
|
|
|
const isForwardOpen = Boolean(expandedForwards[forward.id]);
|
|
|
|
|
|
2026-04-26 14:03:39 +03:00
|
|
|
const typeLabel = forward.type === 'local' ? t('settings.remoteInstances.page.forwardType.local') : forward.type === 'remote' ? t('settings.remoteInstances.page.forwardType.remote') : t('settings.remoteInstances.page.forwardType.dynamic');
|
2026-02-26 20:26:12 +02:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Collapsible
|
|
|
|
|
key={forward.id}
|
|
|
|
|
open={isForwardOpen}
|
|
|
|
|
onOpenChange={(open) => {
|
|
|
|
|
setExpandedForwards((current) => ({
|
|
|
|
|
...current,
|
|
|
|
|
[forward.id]: open,
|
|
|
|
|
}));
|
|
|
|
|
}}
|
|
|
|
|
className={`${index > 0 ? 'border-t border-[var(--surface-subtle)]' : ''} py-2`}
|
|
|
|
|
>
|
|
|
|
|
<div className="flex items-center justify-between gap-2">
|
|
|
|
|
<div className="min-w-0 flex items-center gap-2">
|
|
|
|
|
<CollapsibleTrigger className="flex items-center gap-2 group">
|
|
|
|
|
<RiArrowDownSLine className={`h-4 w-4 text-muted-foreground transition-transform ${isForwardOpen ? 'rotate-180' : ''}`} />
|
|
|
|
|
<span className="typography-ui-label text-foreground truncate">{buildForwardLabel(forward)}</span>
|
|
|
|
|
<span className="typography-micro text-muted-foreground/70 shrink-0">{typeLabel}</span>
|
|
|
|
|
</CollapsibleTrigger>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="flex items-center gap-2">
|
2026-04-26 14:03:39 +03:00
|
|
|
<Switch checked={forward.enabled} onCheckedChange={(checked) => updateForward((item) => ({ ...item, enabled: checked }))} aria-label={t('settings.remoteInstances.page.actions.enableForwardAria')} />
|
2026-03-20 01:01:03 +02:00
|
|
|
<Button
|
2026-02-26 20:26:12 +02:00
|
|
|
type="button"
|
|
|
|
|
variant="ghost"
|
|
|
|
|
size="xs"
|
|
|
|
|
className="!font-normal h-6 w-6 px-0 text-[var(--status-error)] hover:text-[var(--status-error)]"
|
|
|
|
|
onClick={() =>
|
|
|
|
|
updateDraft((current) => ({
|
|
|
|
|
...current,
|
|
|
|
|
portForwards: current.portForwards.filter((item) => item.id !== forward.id),
|
|
|
|
|
}))
|
|
|
|
|
}
|
|
|
|
|
>
|
|
|
|
|
<RiDeleteBinLine className="h-3.5 w-3.5" />
|
2026-03-20 01:01:03 +02:00
|
|
|
</Button>
|
2026-02-26 20:26:12 +02:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<CollapsibleContent className="pt-2">
|
|
|
|
|
<div className="space-y-0 pb-2">
|
2026-04-26 14:03:39 +03:00
|
|
|
<p className="typography-meta text-muted-foreground mb-3">{t(forwardTypeDescriptionKey(forward.type))}</p>
|
2026-02-26 20:26:12 +02:00
|
|
|
<div className="flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8">
|
|
|
|
|
<div className="w-56 shrink-0">
|
|
|
|
|
<HintLabel
|
2026-04-26 14:03:39 +03:00
|
|
|
label={t('settings.remoteInstances.page.field.forwardType')}
|
|
|
|
|
hint={t('settings.remoteInstances.page.field.forwardTypeHint')}
|
2026-02-26 20:26:12 +02:00
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
<Select
|
|
|
|
|
value={forward.type}
|
|
|
|
|
onValueChange={(value) =>
|
|
|
|
|
updateForward((item) => ({
|
|
|
|
|
...item,
|
|
|
|
|
type: (value === 'dynamic' || value === 'remote' ? value : 'local') as DesktopSshPortForwardType,
|
|
|
|
|
}))
|
|
|
|
|
}
|
|
|
|
|
>
|
|
|
|
|
<SelectTrigger className="h-7 w-fit min-w-[140px]">
|
2026-04-26 14:03:39 +03:00
|
|
|
<SelectValue placeholder={t('settings.remoteInstances.page.field.typePlaceholder')} />
|
2026-02-26 20:26:12 +02:00
|
|
|
</SelectTrigger>
|
|
|
|
|
<SelectContent>
|
2026-04-26 14:03:39 +03:00
|
|
|
<SelectItem value="local">{t('settings.remoteInstances.page.forwardType.local')}</SelectItem>
|
|
|
|
|
<SelectItem value="remote">{t('settings.remoteInstances.page.forwardType.remote')}</SelectItem>
|
|
|
|
|
<SelectItem value="dynamic">{t('settings.remoteInstances.page.forwardType.dynamic')}</SelectItem>
|
2026-02-26 20:26:12 +02:00
|
|
|
</SelectContent>
|
|
|
|
|
</Select>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8">
|
|
|
|
|
<div className="w-56 shrink-0">
|
|
|
|
|
<HintLabel label={localLabel} hint={localHint} />
|
|
|
|
|
</div>
|
|
|
|
|
<div className="flex items-center gap-1.5">
|
|
|
|
|
<Input
|
|
|
|
|
className="h-7 w-32"
|
|
|
|
|
value={forward.localHost || '127.0.0.1'}
|
|
|
|
|
onChange={(event) =>
|
|
|
|
|
updateForward((item) => ({
|
|
|
|
|
...item,
|
|
|
|
|
localHost: event.target.value,
|
|
|
|
|
}))
|
|
|
|
|
}
|
2026-04-26 14:03:39 +03:00
|
|
|
placeholder={t('settings.remoteInstances.page.field.localHostPlaceholder')}
|
2026-02-26 20:26:12 +02:00
|
|
|
/>
|
|
|
|
|
<span className="text-muted-foreground">:</span>
|
|
|
|
|
<NumberInput
|
|
|
|
|
containerClassName="w-fit"
|
|
|
|
|
min={1}
|
|
|
|
|
max={65535}
|
|
|
|
|
step={1}
|
|
|
|
|
className="w-16 tabular-nums"
|
|
|
|
|
value={forward.localPort}
|
|
|
|
|
onValueChange={(next) => {
|
|
|
|
|
updateForward((item) => ({
|
|
|
|
|
...item,
|
|
|
|
|
localPort: Number.isFinite(next) && next > 0 ? next : undefined,
|
|
|
|
|
}));
|
|
|
|
|
}}
|
|
|
|
|
onClear={() => {
|
|
|
|
|
updateForward((item) => ({
|
|
|
|
|
...item,
|
|
|
|
|
localPort: undefined,
|
|
|
|
|
}));
|
|
|
|
|
}}
|
2026-04-26 14:03:39 +03:00
|
|
|
emptyLabel={t('settings.remoteInstances.page.field.auto')}
|
2026-02-26 20:26:12 +02:00
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{forward.type !== 'dynamic' ? (
|
|
|
|
|
<div className="flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8">
|
|
|
|
|
<div className="w-56 shrink-0">
|
|
|
|
|
<HintLabel label={remoteLabel} hint={remoteHint} />
|
|
|
|
|
</div>
|
|
|
|
|
<div className="flex items-center gap-1.5">
|
|
|
|
|
<Input
|
|
|
|
|
className="h-7 w-32"
|
|
|
|
|
value={forward.remoteHost || ''}
|
|
|
|
|
onChange={(event) =>
|
|
|
|
|
updateForward((item) => ({
|
|
|
|
|
...item,
|
|
|
|
|
remoteHost: event.target.value,
|
|
|
|
|
}))
|
|
|
|
|
}
|
2026-04-26 14:03:39 +03:00
|
|
|
placeholder={t('settings.remoteInstances.page.field.remoteHostPlaceholder')}
|
2026-02-26 20:26:12 +02:00
|
|
|
/>
|
|
|
|
|
<span className="text-muted-foreground">:</span>
|
|
|
|
|
<NumberInput
|
|
|
|
|
containerClassName="w-fit"
|
|
|
|
|
min={1}
|
|
|
|
|
max={65535}
|
|
|
|
|
step={1}
|
|
|
|
|
className="w-16 tabular-nums"
|
|
|
|
|
value={forward.remotePort}
|
|
|
|
|
onValueChange={(next) => {
|
|
|
|
|
updateForward((item) => ({
|
|
|
|
|
...item,
|
|
|
|
|
remotePort: Number.isFinite(next) && next > 0 ? next : undefined,
|
|
|
|
|
}));
|
|
|
|
|
}}
|
|
|
|
|
onClear={() => {
|
|
|
|
|
updateForward((item) => ({
|
|
|
|
|
...item,
|
|
|
|
|
remotePort: undefined,
|
|
|
|
|
}));
|
|
|
|
|
}}
|
2026-04-26 14:03:39 +03:00
|
|
|
emptyLabel={t('settings.remoteInstances.page.field.auto')}
|
2026-02-26 20:26:12 +02:00
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
) : null}
|
|
|
|
|
|
|
|
|
|
<div className="mt-2 flex flex-wrap items-center justify-between gap-2 rounded-md bg-[var(--surface-subtle)] p-2">
|
|
|
|
|
<div className="flex flex-wrap items-center gap-1 typography-micro text-muted-foreground/80">
|
|
|
|
|
{forward.type === 'dynamic' ? (
|
|
|
|
|
<>
|
|
|
|
|
<RiComputerLine className="h-3.5 w-3.5" />
|
|
|
|
|
<span className="font-mono text-foreground">{localEndpoint}</span>
|
2026-04-26 14:03:39 +03:00
|
|
|
<span>{t('settings.remoteInstances.page.preview.localSocks5')}</span>
|
2026-02-26 20:26:12 +02:00
|
|
|
</>
|
|
|
|
|
) : forward.type === 'remote' ? (
|
|
|
|
|
<>
|
|
|
|
|
<RiServerLine className="h-3.5 w-3.5" />
|
|
|
|
|
<span className="font-mono text-foreground">{remoteEndpoint}</span>
|
2026-04-26 14:03:39 +03:00
|
|
|
<span>{t('settings.remoteInstances.page.preview.remote')}</span>
|
2026-02-26 20:26:12 +02:00
|
|
|
<RiArrowRightLine className="h-3.5 w-3.5" />
|
|
|
|
|
<RiComputerLine className="h-3.5 w-3.5" />
|
|
|
|
|
<span className="font-mono text-foreground">{localEndpoint}</span>
|
2026-04-26 14:03:39 +03:00
|
|
|
<span>{t('settings.remoteInstances.page.preview.local')}</span>
|
2026-02-26 20:26:12 +02:00
|
|
|
</>
|
|
|
|
|
) : (
|
|
|
|
|
<>
|
|
|
|
|
<RiComputerLine className="h-3.5 w-3.5" />
|
|
|
|
|
<span className="font-mono text-foreground">{localEndpoint}</span>
|
2026-04-26 14:03:39 +03:00
|
|
|
<span>{t('settings.remoteInstances.page.preview.local')}</span>
|
2026-02-26 20:26:12 +02:00
|
|
|
<RiArrowRightLine className="h-3.5 w-3.5" />
|
|
|
|
|
<RiServerLine className="h-3.5 w-3.5" />
|
|
|
|
|
<span className="font-mono text-foreground">{remoteEndpoint}</span>
|
2026-04-26 14:03:39 +03:00
|
|
|
<span>{t('settings.remoteInstances.page.preview.remote')}</span>
|
2026-02-26 20:26:12 +02:00
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{canOpenLocalEndpoint ? (
|
2026-03-20 01:01:03 +02:00
|
|
|
<Button
|
2026-02-26 20:26:12 +02:00
|
|
|
type="button"
|
|
|
|
|
variant="outline"
|
|
|
|
|
size="xs"
|
|
|
|
|
className="!font-normal"
|
|
|
|
|
onClick={() => {
|
|
|
|
|
void openExternalUrl(localEndpointUrl).then((opened) => {
|
|
|
|
|
if (!opened) {
|
2026-04-26 14:03:39 +03:00
|
|
|
toast.error(t('settings.remoteInstances.page.toast.openLocalEndpointFailed'));
|
2026-02-26 20:26:12 +02:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<RiExternalLinkLine className="h-3.5 w-3.5" />
|
2026-04-26 14:03:39 +03:00
|
|
|
{t('settings.remoteInstances.page.actions.openLocal')}
|
2026-03-20 01:01:03 +02:00
|
|
|
</Button>
|
2026-02-26 20:26:12 +02:00
|
|
|
) : null}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</CollapsibleContent>
|
|
|
|
|
</Collapsible>
|
|
|
|
|
);
|
|
|
|
|
})}
|
|
|
|
|
|
2026-03-20 01:01:03 +02:00
|
|
|
<Button
|
2026-02-26 20:26:12 +02:00
|
|
|
type="button"
|
|
|
|
|
variant="outline"
|
|
|
|
|
size="xs"
|
|
|
|
|
className="!font-normal mt-1"
|
|
|
|
|
onClick={() => {
|
|
|
|
|
const nextForward = makeForward();
|
|
|
|
|
updateDraft((current) => ({
|
|
|
|
|
...current,
|
|
|
|
|
portForwards: [...current.portForwards, nextForward],
|
|
|
|
|
}));
|
|
|
|
|
setExpandedForwards((current) => ({
|
|
|
|
|
...current,
|
|
|
|
|
[nextForward.id]: true,
|
|
|
|
|
}));
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<RiAddLine className="h-3.5 w-3.5" />
|
2026-04-26 14:03:39 +03:00
|
|
|
{t('settings.remoteInstances.page.actions.addForward')}
|
2026-03-20 01:01:03 +02:00
|
|
|
</Button>
|
2026-02-26 20:26:12 +02:00
|
|
|
</section>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="mb-8 border-t border-[var(--surface-subtle)] pt-8">
|
|
|
|
|
<div className="mb-1 px-1 space-y-0.5">
|
2026-04-26 14:03:39 +03:00
|
|
|
<h3 className="typography-ui-header font-medium text-foreground">{t('settings.remoteInstances.page.import.sectionTitle')}</h3>
|
2026-02-26 20:26:12 +02:00
|
|
|
</div>
|
|
|
|
|
<section className="px-2 pb-2 pt-0">
|
|
|
|
|
{isImportsLoading ? (
|
2026-04-26 14:03:39 +03:00
|
|
|
<p className="typography-meta text-muted-foreground">{t('settings.remoteInstances.page.import.loading')}</p>
|
2026-02-26 20:26:12 +02:00
|
|
|
) : importCandidates.length === 0 ? (
|
2026-04-26 14:03:39 +03:00
|
|
|
<p className="typography-meta text-muted-foreground">{t('settings.remoteInstances.page.import.noneAvailable')}</p>
|
2026-02-26 20:26:12 +02:00
|
|
|
) : (
|
|
|
|
|
<div>
|
|
|
|
|
{importCandidates.slice(0, 8).map((candidate, index) => (
|
|
|
|
|
<div
|
|
|
|
|
key={`${candidate.source}:${candidate.host}`}
|
|
|
|
|
className={`flex items-center justify-between gap-2 px-1 py-2 ${index > 0 ? 'border-t border-[var(--surface-subtle)]' : ''}`}
|
|
|
|
|
>
|
|
|
|
|
<div className="min-w-0">
|
|
|
|
|
<div className="typography-ui-label text-foreground truncate">
|
|
|
|
|
{candidate.host}
|
|
|
|
|
{candidate.pattern ? ' (pattern)' : ''}
|
|
|
|
|
</div>
|
|
|
|
|
<div className="typography-micro text-muted-foreground truncate">{candidate.sshCommand}</div>
|
|
|
|
|
</div>
|
2026-03-20 01:01:03 +02:00
|
|
|
<Button
|
2026-02-26 20:26:12 +02:00
|
|
|
type="button"
|
|
|
|
|
variant="outline"
|
|
|
|
|
size="xs"
|
|
|
|
|
className="!font-normal"
|
|
|
|
|
onClick={() => void handleImportCandidate(candidate.host, candidate.pattern)}
|
|
|
|
|
>
|
2026-04-26 14:03:39 +03:00
|
|
|
{t('settings.common.actions.import')}
|
2026-03-20 01:01:03 +02:00
|
|
|
</Button>
|
2026-02-26 20:26:12 +02:00
|
|
|
</div>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</section>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="sticky bottom-0 z-10 -mx-3 sm:-mx-6 bg-[var(--surface-background)] border-t border-[var(--interactive-border)] px-3 sm:px-6 py-3">
|
|
|
|
|
<div className="flex items-center gap-2">
|
2026-03-20 01:01:03 +02:00
|
|
|
<Button type="button" size="xs" className="!font-normal" onClick={() => void handleSave()} disabled={!hasChanges || isSaving}>
|
2026-04-26 14:03:39 +03:00
|
|
|
{t('settings.common.actions.saveChanges')}
|
2026-03-20 01:01:03 +02:00
|
|
|
</Button>
|
2026-02-26 20:26:12 +02:00
|
|
|
{status?.localUrl ? (
|
|
|
|
|
<>
|
2026-03-20 01:01:03 +02:00
|
|
|
<Button
|
2026-02-26 20:26:12 +02:00
|
|
|
type="button"
|
|
|
|
|
variant="outline"
|
|
|
|
|
size="xs"
|
|
|
|
|
className="!font-normal"
|
|
|
|
|
onClick={() => {
|
|
|
|
|
void copyTextToClipboard(status.localUrl || '').then((result) => {
|
|
|
|
|
if (result.ok) {
|
2026-04-26 14:03:39 +03:00
|
|
|
toast.success(t('settings.remoteInstances.page.toast.localUrlCopied'));
|
2026-02-26 20:26:12 +02:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<RiFileCopyLine className="h-3.5 w-3.5" />
|
2026-04-26 14:03:39 +03:00
|
|
|
{t('settings.remoteInstances.page.actions.copyLocalUrl')}
|
2026-03-20 01:01:03 +02:00
|
|
|
</Button>
|
|
|
|
|
<Button
|
2026-02-26 20:26:12 +02:00
|
|
|
type="button"
|
|
|
|
|
variant="outline"
|
|
|
|
|
size="xs"
|
|
|
|
|
className="!font-normal"
|
|
|
|
|
onClick={() => {
|
|
|
|
|
void handleOpenCurrentInstance();
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<RiExternalLinkLine className="h-3.5 w-3.5" />
|
2026-04-26 14:03:39 +03:00
|
|
|
{t('settings.remoteInstances.page.actions.open')}
|
2026-03-20 01:01:03 +02:00
|
|
|
</Button>
|
2026-02-26 20:26:12 +02:00
|
|
|
</>
|
|
|
|
|
) : null}
|
|
|
|
|
{error ? <div className="ml-auto typography-meta text-[var(--status-error)]">{error}</div> : null}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<Dialog open={logDialogOpen} onOpenChange={setLogDialogOpen}>
|
|
|
|
|
<DialogContent className="sm:max-w-2xl">
|
|
|
|
|
<DialogHeader>
|
2026-04-26 14:03:39 +03:00
|
|
|
<DialogTitle>{t('settings.remoteInstances.page.logsDialog.title')}</DialogTitle>
|
2026-02-26 20:26:12 +02:00
|
|
|
<DialogDescription>
|
2026-04-26 14:03:39 +03:00
|
|
|
{draft?.nickname?.trim() || draft?.sshParsed?.destination || draft?.id || t('settings.remoteInstances.page.logsDialog.selectedInstanceFallback')}
|
2026-02-26 20:26:12 +02:00
|
|
|
</DialogDescription>
|
|
|
|
|
</DialogHeader>
|
|
|
|
|
<div className="flex items-center justify-end gap-2">
|
2026-03-20 01:01:03 +02:00
|
|
|
<Button type="button" variant="outline" size="xs" className="!font-normal" onClick={handleCopyAllLogs} disabled={logDialogLoading || !logLinesText.trim()}>
|
2026-02-26 20:26:12 +02:00
|
|
|
<RiFileCopyLine className="h-3.5 w-3.5" />
|
2026-04-26 14:03:39 +03:00
|
|
|
{t('settings.common.actions.copyAll')}
|
2026-03-20 01:01:03 +02:00
|
|
|
</Button>
|
|
|
|
|
<Button type="button" variant="outline" size="xs" className="!font-normal" onClick={() => void handleClearLogs()} disabled={logDialogLoading}>
|
2026-02-26 20:26:12 +02:00
|
|
|
<RiDeleteBinLine className="h-3.5 w-3.5" />
|
2026-04-26 14:03:39 +03:00
|
|
|
{t('settings.common.actions.clear')}
|
2026-03-20 01:01:03 +02:00
|
|
|
</Button>
|
2026-02-26 20:26:12 +02:00
|
|
|
</div>
|
|
|
|
|
{logDialogLoading ? (
|
2026-04-26 14:03:39 +03:00
|
|
|
<div className="typography-meta text-muted-foreground">{t('settings.remoteInstances.page.logsDialog.loading')}</div>
|
2026-02-26 20:26:12 +02:00
|
|
|
) : logDialogError ? (
|
|
|
|
|
<div className="typography-meta text-[var(--status-error)]">{logDialogError}</div>
|
|
|
|
|
) : (
|
|
|
|
|
<pre className="max-h-[55vh] overflow-auto rounded-md border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-3 typography-micro text-foreground whitespace-pre-wrap break-words">
|
2026-04-26 14:03:39 +03:00
|
|
|
{logDialogLines.length > 0 ? logDialogLines.join('\n') : t('settings.remoteInstances.page.logsDialog.empty')}
|
2026-02-26 20:26:12 +02:00
|
|
|
</pre>
|
|
|
|
|
)}
|
|
|
|
|
</DialogContent>
|
|
|
|
|
</Dialog>
|
|
|
|
|
|
|
|
|
|
<Dialog
|
|
|
|
|
open={Boolean(patternHost)}
|
|
|
|
|
onOpenChange={(open) => {
|
|
|
|
|
if (!open) {
|
|
|
|
|
closePatternDialog();
|
|
|
|
|
}
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<DialogContent className="sm:max-w-md">
|
|
|
|
|
<DialogHeader>
|
2026-04-26 14:03:39 +03:00
|
|
|
<DialogTitle>{t('settings.remoteInstances.page.patternDialog.title')}</DialogTitle>
|
2026-02-26 20:26:12 +02:00
|
|
|
<DialogDescription>
|
2026-04-26 14:03:39 +03:00
|
|
|
{patternHost
|
|
|
|
|
? t('settings.remoteInstances.page.patternDialog.descriptionWithHost', { host: patternHost })
|
|
|
|
|
: t('settings.remoteInstances.page.patternDialog.description')}
|
2026-02-26 20:26:12 +02:00
|
|
|
</DialogDescription>
|
|
|
|
|
</DialogHeader>
|
|
|
|
|
<form
|
|
|
|
|
className="space-y-3"
|
|
|
|
|
onSubmit={(event) => {
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
handlePatternCreate();
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Input
|
|
|
|
|
value={patternDestination}
|
|
|
|
|
onChange={(event) => setPatternDestination(event.target.value)}
|
2026-04-26 14:03:39 +03:00
|
|
|
placeholder={t('settings.remoteInstances.page.patternDialog.destinationPlaceholder')}
|
2026-02-26 20:26:12 +02:00
|
|
|
autoFocus
|
|
|
|
|
/>
|
|
|
|
|
<div className="flex items-center justify-end gap-2">
|
2026-03-20 01:01:03 +02:00
|
|
|
<Button type="button" variant="outline" size="xs" className="!font-normal" onClick={closePatternDialog} disabled={patternCreating}>
|
2026-04-26 14:03:39 +03:00
|
|
|
{t('settings.common.actions.cancel')}
|
2026-03-20 01:01:03 +02:00
|
|
|
</Button>
|
|
|
|
|
<Button type="submit" size="xs" className="!font-normal" disabled={patternCreating}>
|
2026-04-26 14:03:39 +03:00
|
|
|
{t('settings.common.actions.create')}
|
2026-03-20 01:01:03 +02:00
|
|
|
</Button>
|
2026-02-26 20:26:12 +02:00
|
|
|
</div>
|
|
|
|
|
</form>
|
|
|
|
|
</DialogContent>
|
|
|
|
|
</Dialog>
|
|
|
|
|
</SettingsPageLayout>
|
|
|
|
|
);
|
|
|
|
|
};
|