Skip to content

Commit 73d7d6e

Browse files
committed
fix: 修复 pairing required - 改用 openclaw-control-ui 客户端 ID 触发静默自动配对
上游源码分析发现根本原因: - 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 已写入,无需用户手动点击一键修复
1 parent 7a05625 commit 73d7d6e

3 files changed

Lines changed: 13 additions & 8 deletions

File tree

src-tauri/src/commands/device.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,10 @@ pub fn create_connect_frame(nonce: String, gateway_token: String) -> Result<Valu
101101

102102
let scopes_str = SCOPES.join(",");
103103
// v3 格式:v3|deviceId|clientId|clientMode|role|scopes|signedAt|token|nonce|platform|deviceFamily
104+
// 使用 openclaw-control-ui + ui 模式,使 Gateway 识别为 Control UI 客户端,
105+
// 本地连接时触发静默自动配对(shouldAllowSilentLocalPairing = true)
104106
let payload_str = format!(
105-
"v3|{device_id}|gateway-client|backend|operator|{scopes_str}|{signed_at}|{gateway_token}|{nonce}|{platform}|{device_family}"
107+
"v3|{device_id}|openclaw-control-ui|ui|operator|{scopes_str}|{signed_at}|{gateway_token}|{nonce}|{platform}|{device_family}"
106108
);
107109

108110
let signature = signing_key.sign(payload_str.as_bytes());
@@ -116,11 +118,11 @@ pub fn create_connect_frame(nonce: String, gateway_token: String) -> Result<Valu
116118
"minProtocol": 3,
117119
"maxProtocol": 3,
118120
"client": {
119-
"id": "gateway-client",
121+
"id": "openclaw-control-ui",
120122
"version": "1.0.0",
121123
"platform": platform,
122124
"deviceFamily": device_family,
123-
"mode": "backend"
125+
"mode": "ui"
124126
},
125127
"role": "operator",
126128
"scopes": SCOPES,

src-tauri/src/commands/pairing.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ pub fn auto_pair_device() -> Result<String, String> {
6262
"deviceId": device_id,
6363
"publicKey": public_key,
6464
"platform": "desktop",
65-
"clientId": "gateway-client",
66-
"clientMode": "backend",
65+
"clientId": "openclaw-control-ui",
66+
"clientMode": "ui",
6767
"role": "operator",
6868
"roles": ["operator"],
6969
"scopes": [

src/main.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,12 @@ async function autoConnectWebSocket() {
7878
const port = config?.gateway?.port || 18789
7979
const token = config?.gateway?.auth?.token || ''
8080

81-
if (!token) {
82-
console.warn('[main] Gateway token 未设置,跳过 WebSocket 连接')
83-
return
81+
// 启动前先确保设备已配对 + allowedOrigins 已写入,无需用户手动操作
82+
try {
83+
await api.autoPairDevice()
84+
console.log('[main] 设备配对 + origins 已就绪')
85+
} catch (pairErr) {
86+
console.warn('[main] autoPairDevice 失败(非致命):', pairErr)
8487
}
8588

8689
wsClient.connect(`127.0.0.1:${port}`, token)

0 commit comments

Comments
 (0)