fix(client): default off BtMonitor unless CLAWD_ENABLE_BT (no env line needed)
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user