Skip to content

Commit b6734b9

Browse files
authored
Show auto-detected mosh path (#858)
1 parent fb44354 commit b6734b9

3 files changed

Lines changed: 32 additions & 6 deletions

File tree

application/i18n/locales/en.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,7 @@ const en: Messages = {
387387
'settings.terminal.mosh.client.notAbsolute': 'Path must be absolute. Use Browse… to pick the binary, leave the field empty to auto-detect, or enter a full path.',
388388
'settings.terminal.mosh.detect': 'Detect',
389389
'settings.terminal.mosh.browse': 'Browse…',
390+
'settings.terminal.mosh.autoDetected': 'Auto-detected',
390391
'settings.terminal.mosh.detected': 'Detected at',
391392
'settings.terminal.mosh.notDetected': 'Mosh not found in:',
392393
'settings.terminal.section.serverStats': 'Server Stats (Linux)',

application/i18n/locales/zh-CN.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1471,6 +1471,7 @@ const zhCN: Messages = {
14711471
'settings.terminal.mosh.client.notAbsolute': '路径必须为绝对路径。请使用 浏览… 选择二进制、留空以自动探测,或输入完整路径。',
14721472
'settings.terminal.mosh.detect': '探测',
14731473
'settings.terminal.mosh.browse': '浏览…',
1474+
'settings.terminal.mosh.autoDetected': '自动检测到',
14741475
'settings.terminal.mosh.detected': '已找到',
14751476
'settings.terminal.mosh.notDetected': '在以下位置未找到 mosh:',
14761477
'settings.terminal.section.serverStats': '服务器状态(Linux)',

components/settings/tabs/SettingsTerminalTab.tsx

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ export default function SettingsTerminalTab(props: {
308308
| { kind: "found"; path: string }
309309
| { kind: "not-found"; searchedPaths: string[] }
310310
>({ kind: "idle" });
311+
const [autoDetectedMoshPath, setAutoDetectedMoshPath] = useState<string | null>(null);
311312

312313
const discoveredShells = useDiscoveredShells();
313314
const [showCustomShellInput, setShowCustomShellInput] = useState(() => {
@@ -513,6 +514,24 @@ export default function SettingsTerminalTab(props: {
513514
return () => clearTimeout(timeoutId);
514515
}, [terminalSettings.moshClientPath, t]);
515516

517+
useEffect(() => {
518+
const bridge = (window as unknown as { netcatty?: NetcattyBridge }).netcatty;
519+
if (!bridge?.detectMoshClient) return;
520+
let canceled = false;
521+
bridge.detectMoshClient()
522+
.then((result) => {
523+
if (!canceled) {
524+
setAutoDetectedMoshPath(result.found && result.path ? result.path : null);
525+
}
526+
})
527+
.catch(() => {
528+
if (!canceled) setAutoDetectedMoshPath(null);
529+
});
530+
return () => {
531+
canceled = true;
532+
};
533+
}, []);
534+
516535
const handleDetectMosh = useCallback(async () => {
517536
const bridge = (window as unknown as { netcatty?: NetcattyBridge }).netcatty;
518537
if (!bridge?.detectMoshClient) return;
@@ -1143,8 +1162,8 @@ export default function SettingsTerminalTab(props: {
11431162
label={t("settings.terminal.mosh.client")}
11441163
description={t("settings.terminal.mosh.client.desc")}
11451164
>
1146-
<div className="flex flex-col gap-1 w-72">
1147-
<div className="flex gap-2">
1165+
<div className="flex max-w-full flex-col gap-1.5" style={{ width: "min(420px, 100%)" }}>
1166+
<div className="grid grid-cols-[minmax(220px,1fr)_auto_auto] gap-2">
11481167
<Input
11491168
value={terminalSettings.moshClientPath}
11501169
placeholder={t("settings.terminal.mosh.client.placeholder")}
@@ -1172,6 +1191,11 @@ export default function SettingsTerminalTab(props: {
11721191
{t("settings.terminal.mosh.browse")}
11731192
</Button>
11741193
</div>
1194+
{!terminalSettings.moshClientPath && autoDetectedMoshPath && moshDetectStatus.kind !== "found" && (
1195+
<span className="text-xs text-muted-foreground">
1196+
{t("settings.terminal.mosh.autoDetected")}: <span className="break-all font-mono">{autoDetectedMoshPath}</span>
1197+
</span>
1198+
)}
11751199
{moshValidation && !moshValidation.valid && moshValidation.message && (
11761200
<span className="text-xs text-destructive flex items-center gap-1">
11771201
<AlertCircle size={12} />
@@ -1180,7 +1204,7 @@ export default function SettingsTerminalTab(props: {
11801204
)}
11811205
{moshDetectStatus.kind === "found" && (
11821206
<span className="text-xs text-muted-foreground">
1183-
{t("settings.terminal.mosh.detected")}: {moshDetectStatus.path}
1207+
{t("settings.terminal.mosh.detected")}: <span className="break-all font-mono">{moshDetectStatus.path}</span>
11841208
</span>
11851209
)}
11861210
{moshDetectStatus.kind === "not-found" && (
@@ -1198,9 +1222,9 @@ export default function SettingsTerminalTab(props: {
11981222
</>
11991223
)}
12001224
</span>
1201-
</span>
1202-
)}
1203-
</div>
1225+
</span>
1226+
)}
1227+
</div>
12041228
</SettingRow>
12051229
</div>
12061230

0 commit comments

Comments
 (0)