fix: turn off LEDs on service start, suppress Err0 before first WS success

Made-with: Cursor
This commit is contained in:
stswangzhiping
2026-03-19 23:27:42 +08:00
parent 9b4287db1d
commit 8f158eeeb2
2 changed files with 8 additions and 4 deletions

View File

@@ -41,6 +41,8 @@ class ClawClient {
// WS 连续失败计数open 时清零)
this._wsFailCount = 0;
// 是否曾经成功连接过(首次成功前不显示 Err0/AP
this._hasEverConnected = false;
// systemd watchdog
this._sdTimer = null;
@@ -125,7 +127,7 @@ class ClawClient {
_connect() {
if (this._stopped) return;
if (this._wsFailCount < 3) led.display.showConn();
if (!this._hasEverConnected || this._wsFailCount < 3) led.display.showConn();
log.info('clawd', `正在连接 ${this._cfg.server} ...`);
const ws = new WebSocket(this._cfg.server, {
handshakeTimeout: 10_000,
@@ -135,7 +137,8 @@ class ClawClient {
ws.on('open', () => {
log.info('clawd', 'WebSocket 已连接');
this._backoff = 1_000;
this._wsFailCount = 0; // 连接成功,重置失败计数
this._wsFailCount = 0; // 连接成功,重置失败计数
this._hasEverConnected = true; // 标记已成功连接过
this._sendConnect();
this._startPing();
// 显示由 _onConnected 根据 status 设置,不在此处提前 showTime
@@ -159,11 +162,11 @@ class ClawClient {
if (!this._stopped) {
this._wsFailCount++;
log.warn('clawd', `连接断开 (${code}),失败次数=${this._wsFailCount}${this._backoff / 1000}s 后重连...`);
if (this._wsFailCount >= 3) {
if (this._hasEverConnected && this._wsFailCount >= 3) {
if (hasInternet()) {
led.display.showErr0(); // 有网但 VPS 不可达
} else {
led.display.showAP(); // 无网AP 模式
led.display.showAP(); // 无网AP 模式
}
}
setTimeout(() => this._connect(), this._backoff);