From 5824cf089a2f6e47a757670642f0c13f5e0be0d8 Mon Sep 17 00:00:00 2001 From: stswangzhiping <59632378+stswangzhiping@users.noreply.github.com> Date: Thu, 19 Mar 2026 09:43:29 +0800 Subject: [PATCH] feat(ws): unified status_update handler, extract _applyStatus() Made-with: Cursor --- lib/client.js | 46 ++++++++++++++++++++++------------------------ 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/lib/client.js b/lib/client.js index 86ada82..ca0d03c 100644 --- a/lib/client.js +++ b/lib/client.js @@ -210,8 +210,8 @@ class ClawClient { break; case 'heartbeat_ack': break; - case 'activated': - this._onActivated(); + case 'status_update': + this._applyStatus(msg); break; case 'error': log.error('clawd', `服务器错误: ${msg.msg}`); @@ -243,24 +243,7 @@ class ClawClient { log.info('clawd', `注册成功!claw_id = ${msg.claw_id}`); } - if (msg.status === 'inactive') { - led.status.setSetup(); // 未激活 → SETUP 亮 - led.display.showPin(msg.pin); // 未激活 + 连网 → 显示 4 位 PIN - const id = String(msg.claw_id).padEnd(6); - const pin = String(msg.pin); - log.info('clawd', ''); - log.info('clawd', '╔════════════════════════════════════╗'); - log.info('clawd', `║ Claw ID : ${id} ║`); - log.info('clawd', `║ PIN 码 : ${pin} ║`); - log.info('clawd', '║ 请在网页前台「添加设备」中输入 ║'); - log.info('clawd', '╚════════════════════════════════════╝'); - log.info('clawd', ''); - log.info('clawd', '等待激活,心跳正常运行...'); - } else { - led.status.setApps(); // 已激活 → APPS 亮 - led.display.showTime(); // 已激活 → 显示时间 - log.info('clawd', `已激活 claw_id = ${msg.claw_id}`); - } + this._applyStatus(msg); if (msg.frp && msg.frp.server && msg.frp.auth_token) { this._frpc.start(msg.claw_id, msg.frp).catch(e => { @@ -271,10 +254,25 @@ class ClawClient { this._startHeartbeat(); } - _onActivated() { - log.info('clawd', '收到激活通知,切换至已激活状态'); - led.status.setApps(); - led.display.showTime(); + _applyStatus(msg) { + if (msg.status === 'inactive') { + led.status.setSetup(); + led.display.showPin(msg.pin); + const id = String(this._cfg.claw_id || '').padEnd(6); + const pin = String(msg.pin || ''); + log.info('clawd', ''); + log.info('clawd', '╔════════════════════════════════════╗'); + log.info('clawd', `║ Claw ID : ${id} ║`); + log.info('clawd', `║ PIN 码 : ${pin} ║`); + log.info('clawd', '║ 请在网页前台「添加设备」中输入 ║'); + log.info('clawd', '╚════════════════════════════════════╝'); + log.info('clawd', ''); + log.info('clawd', '等待激活,心跳正常运行...'); + } else { + led.status.setApps(); + led.display.showTime(); + log.info('clawd', `已激活 claw_id = ${this._cfg.claw_id}`); + } } // ── 心跳 ────────────────────────────────────────────────────────────────────