From a6e2f7ab8f5bd5734cf035ae7333485748c3ea3f Mon Sep 17 00:00:00 2001 From: stswangzhiping <59632378+stswangzhiping@users.noreply.github.com> Date: Sun, 29 Mar 2026 08:20:08 +0800 Subject: [PATCH] fix(client): default off BtMonitor unless CLAWD_ENABLE_BT (no env line needed) --- install.sh | 5 +++-- lib/client.js | 33 ++++++++++++++++++++------------- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/install.sh b/install.sh index ef55e66..e1caa1d 100644 --- a/install.sh +++ b/install.sh @@ -167,8 +167,9 @@ CLAWD_LOG_LEVEL=info CLAWD_LOG_FILE=1 # 自定义服务器地址(留空则读 config.json) # CLAWD_SERVER=wss://claw.cutos.ai/ws -# 关闭 BtMonitor(不执行 bluetoothctl)。需要蓝牙状态灯时请注释掉下一行。 -CLAWD_DISABLE_BT=1 +# BtMonitor(bluetoothctl)默认在程序内关闭,无需在此写 CLAWD_DISABLE_BT。 +# 若产品需要蓝牙指示灯,取消下一行注释: +# CLAWD_ENABLE_BT=1 # OpenVFD sysfs 根路径(默认 /sys/class/leds/openvfd) # CLAWD_OPENVFD_PATH=/sys/class/leds/openvfd # 多网口/特殊板型可固定 LAN 灯监控的以太网口(默认由 clawd 自动锁定首次 carrier 口) diff --git a/lib/client.js b/lib/client.js index f330533..4d60fc1 100644 --- a/lib/client.js +++ b/lib/client.js @@ -30,12 +30,17 @@ function bluetoothAdapterPresent() { } } -/** 是否启动 BtMonitor(会周期性执行 bluetoothctl) */ +/** + * 是否启动 BtMonitor(会周期性执行 bluetoothctl)。 + * 默认关闭,仅拉代码即可与「不调 bluetoothctl」一致;需要蓝牙灯时设 CLAWD_ENABLE_BT=1。 + * CLAWD_DISABLE_BT=1 仍可强制关闭(优先于 ENABLE)。 + */ function btMonitorEnabled() { - const v = (process.env.CLAWD_DISABLE_BT || '').trim().toLowerCase(); - if (v === '1' || v === 'true' || v === 'yes') return false; - if (!bluetoothAdapterPresent()) return false; - return true; + const dis = (process.env.CLAWD_DISABLE_BT || '').trim().toLowerCase(); + if (dis === '1' || dis === 'true' || dis === 'yes') return false; + const en = (process.env.CLAWD_ENABLE_BT || '').trim().toLowerCase(); + if (!(en === '1' || en === 'true' || en === 'yes')) return false; + return bluetoothAdapterPresent(); } class ClawClient { @@ -102,19 +107,21 @@ class ClawClient { // RJ45 链路轮询(OpenVFD play),与 WS 无关,进程起来即开始 led.lan.start(); - // 蓝牙状态监控(bluetoothctl);CLAWD_DISABLE_BT=1 或无 hci 时不启动 + // 蓝牙状态监控(bluetoothctl);默认不启用,见 btMonitorEnabled() if (btMonitorEnabled()) { this._btMonitor = new BtMonitor(); this._btMonitor.start(); } else { const dis = (process.env.CLAWD_DISABLE_BT || '').trim().toLowerCase(); - const forced = dis === '1' || dis === 'true' || dis === 'yes'; - log.info( - 'clawd', - forced - ? '已跳过蓝牙监控(CLAWD_DISABLE_BT 已开启)' - : '已跳过蓝牙监控(未检测到 hci 适配器)', - ); + const en = (process.env.CLAWD_ENABLE_BT || '').trim().toLowerCase(); + const wantEn = en === '1' || en === 'true' || en === 'yes'; + const forcedDis = dis === '1' || dis === 'true' || dis === 'yes'; + let msg = '已跳过蓝牙监控(默认关闭;需要时请设 CLAWD_ENABLE_BT=1)'; + if (forcedDis) msg = '已跳过蓝牙监控(CLAWD_DISABLE_BT 已开启)'; + else if (wantEn && !bluetoothAdapterPresent()) { + msg = '已跳过蓝牙监控(已设 CLAWD_ENABLE_BT 但未检测到 hci 适配器)'; + } + log.info('clawd', msg); } // 启动 AP 配网管理器(等待已保存 WiFi 自动连接,超时再开 AP)