feat: skip WS in AP+no-internet, poll every 5s until network available

Made-with: Cursor
This commit is contained in:
stswangzhiping
2026-03-20 07:43:51 +08:00
parent c13ed3ba6d
commit 08fa4eefaa
2 changed files with 11 additions and 1 deletions

View File

@@ -127,6 +127,16 @@ class ClawClient {
_connect() {
if (this._stopped) return;
// AP 模式 + 无网:不建立 WS5s 后重新检查网络
if (this._provisionMgr && this._provisionMgr.isApMode() && !hasInternet()) {
led.display.showAP();
log.info('clawd', 'AP 模式无网络5s 后重新检查...');
this._backoff = 1_000; // 有网时立即快速重连
this._wsFailCount = 0; // 不计入失败
setTimeout(() => this._connect(), 5_000);
return;
}
if (!this._hasEverConnected || this._wsFailCount < 3) led.display.showConn();
log.info('clawd', `正在连接 ${this._cfg.server} ...`);
const ws = new WebSocket(this._cfg.server, {

View File

@@ -112,7 +112,7 @@ class ProvisionManager extends EventEmitter {
if (this._state === 'ap') return;
led.off(); // AP 模式WiFi 未连接,灭灯
led.display.showAP(); // AP 模式VFD 显示 AP
if (!hasInternet()) led.display.showAP(); // 无网时立即显示 AP有线时等 WS 连接后再定
try {
// AP 模式下无法扫描 WiFi必须在开 AP 之前扫描并缓存