fix: pre-scan WiFi before entering AP mode
wlan0 cannot scan while in AP mode (hardware limitation). Now scan nearby networks before starting hotspot and cache the results for the captive portal page. Made-with: Cursor
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
const EventEmitter = require('events');
|
||||
const log = require('./logger');
|
||||
const { hasInternet, hasSavedWifiConnection, isWifiStaConnected, startAP, stopAP, connectWifi, AP_IP } = require('./network');
|
||||
const { hasInternet, hasSavedWifiConnection, isWifiStaConnected, scanWifi, startAP, stopAP, connectWifi, AP_IP } = require('./network');
|
||||
const { DnsHijack } = require('./dns-hijack');
|
||||
const { CaptiveServer } = require('./captive-server');
|
||||
|
||||
@@ -98,8 +98,12 @@ class ProvisionManager extends EventEmitter {
|
||||
if (this._state === 'ap') return;
|
||||
|
||||
try {
|
||||
// 先写 DNS 劫持配置,再启动 AP
|
||||
// NM 启动热点时会加载 dnsmasq-shared.d/ 下的配置
|
||||
// AP 模式下无法扫描 WiFi,必须在开 AP 之前扫描并缓存
|
||||
log.info('provision', '扫描周边 WiFi...');
|
||||
this._cachedWifiList = scanWifi();
|
||||
log.info('provision', `扫描到 ${this._cachedWifiList.length} 个网络`);
|
||||
|
||||
// 写 DNS 劫持配置(NM 启动热点时加载)
|
||||
this._dns = new DnsHijack();
|
||||
this._dns.start('wlan0', AP_IP);
|
||||
|
||||
@@ -107,6 +111,7 @@ class ProvisionManager extends EventEmitter {
|
||||
|
||||
this._server = new CaptiveServer({
|
||||
clawId: this._clawId,
|
||||
cachedWifiList: this._cachedWifiList,
|
||||
onConnect: (ssid, password) => this._handleWifiConnect(ssid, password),
|
||||
});
|
||||
this._server.startListening();
|
||||
|
||||
Reference in New Issue
Block a user