fix(docker): typeInInstance 卡 ~2s 根因——xclip 未重定向 fd

xclip -i 会 daemon 化常驻持有剪贴板选区,并继承 docker exec 的 stdout/stderr,
导致 exec 要等这俩 fd 关闭、每次中文转发卡 ~2.1s。给 xclip 重定向 >/dev/null 2>&1
后整条链路降到 ~0.08s(实测 26× 提速)。中文输入条与无感模式都受益。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Gloridust
2026-06-14 16:57:33 +08:00
Unverified
parent dfaa64ad39
commit 659d26ce68
+3 -1
View File
@@ -576,7 +576,9 @@ export async function typeInInstance(inst: Instance, text: string): Promise<void
'export DISPLAY="${display:-:1}"', 'export DISPLAY="${display:-:1}"',
'command -v xclip >/dev/null 2>&1 || { echo "xclip not installed in instance image" >&2; exit 127; }', 'command -v xclip >/dev/null 2>&1 || { echo "xclip not installed in instance image" >&2; exit 127; }',
'command -v xdotool >/dev/null 2>&1 || { echo "xdotool not installed in instance image" >&2; exit 127; }', 'command -v xdotool >/dev/null 2>&1 || { echo "xdotool not installed in instance image" >&2; exit 127; }',
`echo '${b64}' | base64 -d | xclip -selection clipboard -i`, // xclip -i 会 daemon 化常驻持有剪贴板选区,并继承 exec 的 stdout/stderr;不重定向的话 docker exec
// 要等这俩 fd 关闭,实测每次卡 ~2s。重定向到 /dev/null 后台后,整条链路从 ~2.1s 降到 ~0.08s。
`echo '${b64}' | base64 -d | xclip -selection clipboard -i >/dev/null 2>&1`,
'xdotool key --clearmodifiers ctrl+v', 'xdotool key --clearmodifiers ctrl+v',
].join('; '); ].join('; ');
await execCapture(inst, ['bash', '-c', cmd]); await execCapture(inst, ['bash', '-c', cmd]);