fix(client): default off BtMonitor unless CLAWD_ENABLE_BT (no env line needed)

This commit is contained in:
stswangzhiping
2026-03-29 08:20:08 +08:00
parent aa9561f946
commit a6e2f7ab8f
2 changed files with 23 additions and 15 deletions

View File

@@ -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();
// 蓝牙状态监控bluetoothctlCLAWD_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