From 02967ae5c3a2424e44eba31e4622d95d80962fac Mon Sep 17 00:00:00 2001 From: LukeMackin Date: Wed, 22 Jul 2026 17:53:44 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20Terminal=E9=98=BB=E5=A1=9E=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E2=80=94cmd=20state+onPress+fetch=20/tools/exec?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - IIFE内useState: cmd/out/running - Run按钮→POST /tools/exec→显示stdout/stderr - onSubmitEditing键盘发送 - loading disabled反馈 --- packages/client-android/App.tsx | 49 ++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/packages/client-android/App.tsx b/packages/client-android/App.tsx index 6065f75..bd41b79 100644 --- a/packages/client-android/App.tsx +++ b/packages/client-android/App.tsx @@ -130,25 +130,36 @@ export default function App() { {/* ── Terminal Tab ── */} {tab === 'terminal' && ( - - - - Execute remote commands via Gateway MCP.{'\n'}Type a shell command and press Execute.{'\n'} - - - - - - Run - - - + (() => { + const [cmd, setCmd] = useState(''); + const [out, setOut] = useState('Execute remote commands via Gateway MCP.\nType a shell command and press Execute.\n'); + const [running, setRunning] = useState(false); + const runCmd = async () => { + if (!cmd.trim() || running) return; + const c = cmd.trim(); setCmd(''); setRunning(true); + setOut(o => o + `$ ${c}\n`); + try { + const r = await fetch(`${gatewayUrl}/tools/exec`, { method:'POST', headers:{'Content-Type':'application/json'}, body:JSON.stringify({command:c}), signal:AbortSignal.timeout(30000) }); + if (!r.ok) throw new Error(`HTTP ${r.status}`); + const d = await r.json() as any; + setOut(o => o + (d.stdout||d.stderr||JSON.stringify(d)) + '\n'); + } catch(e:any) { setOut(o => o + `Error: ${e.message}\n`); } + finally { setRunning(false); } + }; + return ( + + + {out} + + + + + {running ? '...' : 'Run'} + + + + ); + })() )} {/* ── Settings Tab ── */}