From 73d7d6e7f5254f9799fa67d9c5820377cd3d13e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=99=B4=E5=A4=A9?= Date: Wed, 4 Mar 2026 14:39:48 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20pairing=20required?= =?UTF-8?q?=20-=20=E6=94=B9=E7=94=A8=20openclaw-control-ui=20=E5=AE=A2?= =?UTF-8?q?=E6=88=B7=E7=AB=AF=20ID=20=E8=A7=A6=E5=8F=91=E9=9D=99=E9=BB=98?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E9=85=8D=E5=AF=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 上游源码分析发现根本原因: - Gateway 的 shouldAllowSilentLocalPairing 需要 isControlUi=true 才能在本地连接时静默自动批准设备配对 - 我们之前用 gateway-client+backend,isControlUi=false,加上 Tauri WebView 会发 Origin 头(hasBrowserOriginHeader=true), 导致 shouldAllowSilentLocalPairing 返回 false → 'pairing required' 修复内容: - device.rs: client.id 改为 openclaw-control-ui,mode 改为 ui, v3 签名 payload 同步更新,本地连接触发静默自动配对 - pairing.rs: paired.json 的 clientId/clientMode 同步更新 - main.js: 启动时自动调用 autoPairDevice(),确保 device 已配对 + allowedOrigins 已写入,无需用户手动点击一键修复 --- src-tauri/src/commands/device.rs | 8 +++++--- src-tauri/src/commands/pairing.rs | 4 ++-- src/main.js | 9 ++++++--- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src-tauri/src/commands/device.rs b/src-tauri/src/commands/device.rs index 5f338f3..e646539 100644 --- a/src-tauri/src/commands/device.rs +++ b/src-tauri/src/commands/device.rs @@ -101,8 +101,10 @@ pub fn create_connect_frame(nonce: String, gateway_token: String) -> Result Result Result { "deviceId": device_id, "publicKey": public_key, "platform": "desktop", - "clientId": "gateway-client", - "clientMode": "backend", + "clientId": "openclaw-control-ui", + "clientMode": "ui", "role": "operator", "roles": ["operator"], "scopes": [ diff --git a/src/main.js b/src/main.js index 25a4ec1..03d5875 100644 --- a/src/main.js +++ b/src/main.js @@ -78,9 +78,12 @@ async function autoConnectWebSocket() { const port = config?.gateway?.port || 18789 const token = config?.gateway?.auth?.token || '' - if (!token) { - console.warn('[main] Gateway token 未设置,跳过 WebSocket 连接') - return + // 启动前先确保设备已配对 + allowedOrigins 已写入,无需用户手动操作 + try { + await api.autoPairDevice() + console.log('[main] 设备配对 + origins 已就绪') + } catch (pairErr) { + console.warn('[main] autoPairDevice 失败(非致命):', pairErr) } wsClient.connect(`127.0.0.1:${port}`, token)