feat: upgrade codemirror to 6.39.13 and enhance host switching
This commit is contained in:
@@ -31,6 +31,7 @@ import {
|
||||
RiDeleteBinLine,
|
||||
} from '@remixicon/react';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { toast } from '@/components/ui';
|
||||
import { isTauriShell, isDesktopShell } from '@/lib/desktop';
|
||||
import {
|
||||
desktopHostProbe,
|
||||
@@ -160,6 +161,7 @@ export function DesktopHostSwitcherDialog({
|
||||
const [isLoading, setIsLoading] = React.useState(false);
|
||||
const [isProbing, setIsProbing] = React.useState(false);
|
||||
const [isSaving, setIsSaving] = React.useState(false);
|
||||
const [switchingHostId, setSwitchingHostId] = React.useState<string | null>(null);
|
||||
const [error, setError] = React.useState<string>('');
|
||||
|
||||
const [editingId, setEditingId] = React.useState<string | null>(null);
|
||||
@@ -262,9 +264,25 @@ export function DesktopHostSwitcherDialog({
|
||||
void probeAll(allHosts);
|
||||
}, [open, allHosts, probeAll]);
|
||||
|
||||
const handleSwitch = React.useCallback((host: DesktopHost) => {
|
||||
const handleSwitch = React.useCallback(async (host: DesktopHost) => {
|
||||
const origin = host.id === LOCAL_HOST_ID ? getLocalOrigin() : (normalizeHostUrl(host.url) || '');
|
||||
if (!origin) return;
|
||||
|
||||
if (host.id !== LOCAL_HOST_ID && isTauriShell()) {
|
||||
setSwitchingHostId(host.id);
|
||||
const probe = await desktopHostProbe(origin).catch((): HostProbeResult => ({ status: 'unreachable', latencyMs: 0 }));
|
||||
setStatusById((prev) => ({
|
||||
...prev,
|
||||
[host.id]: { status: probe.status, latencyMs: probe.latencyMs },
|
||||
}));
|
||||
|
||||
if (probe.status === 'unreachable') {
|
||||
toast.error(`Instance "${host.label}" is unreachable`);
|
||||
setSwitchingHostId(null);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const target = toNavigationUrl(origin);
|
||||
onHostSwitched?.();
|
||||
|
||||
@@ -440,7 +458,8 @@ export function DesktopHostSwitcherDialog({
|
||||
'flex items-center gap-2 flex-1 min-w-0 text-left',
|
||||
isEditing && 'pointer-events-none opacity-70'
|
||||
)}
|
||||
onClick={() => handleSwitch(host)}
|
||||
onClick={() => void handleSwitch(host)}
|
||||
disabled={switchingHostId === host.id}
|
||||
aria-label={`Switch to ${host.label}`}
|
||||
>
|
||||
<span className={cn('h-2 w-2 rounded-full flex-shrink-0', statusDotClass(status?.status ?? null))} />
|
||||
|
||||
Reference in New Issue
Block a user