From e969a0b1d0a8088e94bbaaa6ad7b107012e86d75 Mon Sep 17 00:00:00 2001 From: wusumac <736139669@qq.com> Date: Mon, 3 Aug 2026 00:09:04 +0800 Subject: [PATCH] revert(web,hub): drop the connection switch button, keep a read-only environment display --- hub/src/config/serverSettings.ts | 13 ------ hub/src/configuration.ts | 5 --- hub/src/web/server.ts | 11 +---- web/src/App.tsx | 13 +----- web/src/lib/app-context.tsx | 3 -- web/src/lib/locales/en.ts | 3 +- web/src/lib/locales/zh-CN.ts | 3 +- web/src/routes/settings/general.tsx | 64 +++++++++-------------------- 8 files changed, 24 insertions(+), 91 deletions(-) diff --git a/hub/src/config/serverSettings.ts b/hub/src/config/serverSettings.ts index 6b1b76d3..2057d8a0 100644 --- a/hub/src/config/serverSettings.ts +++ b/hub/src/config/serverSettings.ts @@ -21,7 +21,6 @@ export interface ServerSettings { listenPort: number publicUrl: string corsOrigins: string[] - lanUrl: string | null } export interface ServerSettingsResult { @@ -34,7 +33,6 @@ export interface ServerSettingsResult { listenHost: 'env' | 'file' | 'default' listenPort: 'env' | 'file' | 'default' publicUrl: 'env' | 'file' | 'default' - lanUrl: 'file' | 'default' corsOrigins: 'env' | 'file' | 'default' } savedToFile: boolean @@ -112,7 +110,6 @@ export async function loadServerSettings(dataDir: string): Promise file > null @@ -217,15 +214,6 @@ export async function loadServerSettings(dataDir: string): Promise file > derived from publicUrl let corsOrigins: string[] if (process.env.CORS_ORIGINS) { @@ -256,7 +244,6 @@ export async function loadServerSettings(dataDir: string): Promise { - try { - return [...new Set([...corsOrigins, new URL(configuration.lanUrl).origin])] - } catch { - return corsOrigins - } - })() - : corsOrigins - const corsOriginOption = mergedCorsOrigins.includes('*') ? '*' : mergedCorsOrigins + const corsOriginOption = corsOrigins.includes('*') ? '*' : corsOrigins const corsMiddleware = cors({ origin: corsOriginOption, allowMethods: ['GET', 'POST', 'PATCH', 'DELETE', 'OPTIONS'], diff --git a/web/src/App.tsx b/web/src/App.tsx index 66a34a48..2bccf74b 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -162,17 +162,6 @@ function AppInner() { queryClient.clear() }, [baseUrl, queryClient]) - // Self-heal: when authentication fails against a stored hub URL that is - // not the page's own origin (e.g. a LAN address that is no longer - // reachable), drop it so the app falls back to the page origin instead of - // being stuck on a dead endpoint. - const pageOrigin = typeof window !== 'undefined' ? window.location.origin : null - useEffect(() => { - if (authError && serverUrl && pageOrigin && serverUrl !== pageOrigin) { - clearServerUrl() - } - }, [authError, serverUrl, pageOrigin, clearServerUrl]) - // Clean up URL params after successful auth (for direct access links) useEffect(() => { if (!token || !api) return @@ -460,7 +449,7 @@ function AppInner() { } return ( - + ServerUrlResult } const AppContext = createContext(null) diff --git a/web/src/lib/locales/en.ts b/web/src/lib/locales/en.ts index 30c2540a..af81723f 100644 --- a/web/src/lib/locales/en.ts +++ b/web/src/lib/locales/en.ts @@ -78,10 +78,9 @@ export default { 'settings.connection.title': 'Connection', 'settings.connection.hint': 'When on the same network you can connect straight to the hub on your Mac for lower latency.', 'settings.connection.current': 'Current', + 'settings.connection.mode': 'Environment', 'settings.connection.lan': 'LAN direct', 'settings.connection.public': 'Public domain', - 'settings.connection.switchToLan': 'Switch to LAN (faster)', - 'settings.connection.switchToPublic': 'Switch to public domain', 'sessions.group.new': 'New session in this directory', 'sessions.machineFilter.label': 'Filter sessions by machine', 'sessions.machineFilter.all': 'All', diff --git a/web/src/lib/locales/zh-CN.ts b/web/src/lib/locales/zh-CN.ts index 0f9829f8..6bd32aa7 100644 --- a/web/src/lib/locales/zh-CN.ts +++ b/web/src/lib/locales/zh-CN.ts @@ -78,10 +78,9 @@ export default { 'settings.connection.title': '连接方式', 'settings.connection.hint': '同一局域网内可直连 Mac 上的 hub,速度更快。', 'settings.connection.current': '当前连接', + 'settings.connection.mode': '当前环境', 'settings.connection.lan': '局域网直连', 'settings.connection.public': '公网域名', - 'settings.connection.switchToLan': '切换到局域网直连(更快)', - 'settings.connection.switchToPublic': '切换到公网域名', 'sessions.group.new': '在此目录新建会话', 'sessions.machineFilter.label': '按机器筛选会话', 'sessions.machineFilter.all': '全部', diff --git a/web/src/routes/settings/general.tsx b/web/src/routes/settings/general.tsx index f6b50b0a..7bff8ee9 100644 --- a/web/src/routes/settings/general.tsx +++ b/web/src/routes/settings/general.tsx @@ -9,9 +9,9 @@ const locales: ReadonlyArray<{ value: Locale; label: string }> = [ { value: 'zh-CN', label: '简体中文' }, ] -function ConnectionSwitch() { +function ConnectionInfo() { const { t } = useTranslation() - const { api, baseUrl, setServerUrl } = useAppContext() + const { api, baseUrl } = useAppContext() const [info, setInfo] = useState<{ publicUrl: string | null; lanUrl: string | null } | null>(null) useEffect(() => { @@ -35,26 +35,19 @@ function ConnectionSwitch() { } }, [api]) - if (!info?.lanUrl) { - return null - } - let publicOrigin: string | null = null - try { - publicOrigin = info.publicUrl ? new URL(info.publicUrl).origin : null - } catch { - publicOrigin = null + if (info?.publicUrl) { + try { + publicOrigin = new URL(info.publicUrl).origin + } catch { + publicOrigin = null + } } // Anything other than the public domain counts as the alternative // (LAN) connection — this also covers IP-based access like // http://192.168.x.x:3006 even when the configured lanUrl uses a - // hostname. baseUrl is the hub the app is actually talking to — it - // updates in place after setServerUrl() without a page reload. + // hostname. baseUrl is the hub the app is actually talking to. const isOnLan = baseUrl !== '' && baseUrl !== publicOrigin - const target = isOnLan ? info.publicUrl : info.lanUrl - if (!target) { - return null - } return ( @@ -62,33 +55,16 @@ function ConnectionSwitch() { label={t('settings.connection.current')} trailing={{baseUrl}} /> - { - // Browsers block in-place requests from an HTTPS - // page to an HTTP hub (mixed content), so an - // HTTPS→HTTP switch must navigate instead. The - // loaded page is then HTTP same-origin and works. - const pageIsHttps = typeof window !== 'undefined' - && window.location.protocol === 'https:' - const targetIsHttps = target.startsWith('https://') - if (pageIsHttps && !targetIsHttps) { - window.location.href = target - return - } - // Otherwise switch the hub connection in place — - // the app reconnects without a full navigation. - setServerUrl(target) - }} - className="shrink-0 rounded-md border border-[var(--app-border)] bg-[var(--app-subtle-bg)] px-2 py-1.5 text-xs text-[var(--app-fg)] hover:bg-[var(--app-secondary-bg)]" - > - {isOnLan ? t('settings.connection.switchToPublic') : t('settings.connection.switchToLan')} - - } - /> + {info ? ( + + {isOnLan ? t('settings.connection.lan') : t('settings.connection.public')} + + } + /> + ) : null} ) } @@ -98,7 +74,7 @@ export default function SettingsGeneralPage() { const { baseUrl } = useAppContext() return ( - +