feat: M1.1 完成 + M1.2 启动 — 全量更新
M1.1 收尾: - 24项 P0/P1/P2 bug 修复 (Rust 107 tests + Flutter 15 tests) - Flutter App v0.3: cupertino_icons 修复, 单元测试, 调试面板, APK 52.6MB - 示例插件完善: manifest.json + 请求/响应示范 + 7个测试 - API 文档重写 (以 routes.rs 为唯一权威) - MILESTONES.md 更新至 100% M1.2 启动: - P0: 插件管理 API 闭环 (handle_manager_message Custom 分支 + broadcast_plugin_states) - ServiceManager 集成测试 8/8 (tests/m1_2_service_manager.rs) - M1.2 测试计划 (docs/M1.2_TEST_PLAN.md, 18个E2E场景) - 动态插件系统: auto_rollback + version_manager GC + 路径穿越防护 总计: Rust 115/115 测试, Flutter 15/15 测试, 零 warning Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -6,21 +6,26 @@ import '../models/wifi_network.dart';
|
||||
import '../models/wifi_status.dart';
|
||||
import '../services/http_api_service.dart';
|
||||
import '../services/web_socket_service.dart';
|
||||
import 'debug_provider.dart';
|
||||
|
||||
class WifiProvider extends ChangeNotifier {
|
||||
WifiProvider({
|
||||
required HttpApiService httpApiService,
|
||||
required WebSocketService webSocketService,
|
||||
required DebugProvider debugProvider,
|
||||
}) : _httpApiService = httpApiService,
|
||||
_webSocketService = webSocketService {
|
||||
_webSocketService = webSocketService,
|
||||
_debugProvider = debugProvider {
|
||||
_wifiSubscription = _webSocketService.onWifiUpdate.listen((payload) {
|
||||
_status = WifiStatus.fromJson(payload);
|
||||
_debugProvider.addWsLog('Wifi provider update', details: payload);
|
||||
notifyListeners();
|
||||
});
|
||||
}
|
||||
|
||||
final HttpApiService _httpApiService;
|
||||
final WebSocketService _webSocketService;
|
||||
final DebugProvider _debugProvider;
|
||||
late final StreamSubscription<Map<String, dynamic>> _wifiSubscription;
|
||||
|
||||
WifiStatus _status = WifiStatus.disconnected();
|
||||
@@ -37,6 +42,7 @@ class WifiProvider extends ChangeNotifier {
|
||||
|
||||
Future<void> bootstrap() async {
|
||||
_setLoading(true);
|
||||
_debugProvider.addHttpLog('Bootstrap WiFi provider');
|
||||
try {
|
||||
final results = await Future.wait<dynamic>([
|
||||
_httpApiService.getWifiStatus(),
|
||||
@@ -45,30 +51,44 @@ class WifiProvider extends ChangeNotifier {
|
||||
_status = results[0] as WifiStatus;
|
||||
_networks = results[1] as List<WifiNetwork>;
|
||||
_errorMessage = null;
|
||||
_debugProvider.addHttpLog(
|
||||
'WiFi provider bootstrapped',
|
||||
details: <String, Object>{'networks': _networks.length},
|
||||
);
|
||||
} catch (error) {
|
||||
_errorMessage = error.toString();
|
||||
_debugProvider.addHttpLog('Bootstrap WiFi provider failed', details: error);
|
||||
} finally {
|
||||
_setLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> refreshStatus() async {
|
||||
_debugProvider.addHttpLog('Refresh WiFi status');
|
||||
try {
|
||||
_status = await _httpApiService.getWifiStatus();
|
||||
_debugProvider.addHttpLog('WiFi status refreshed');
|
||||
notifyListeners();
|
||||
} catch (error) {
|
||||
_errorMessage = error.toString();
|
||||
_debugProvider.addHttpLog('Refresh WiFi status failed', details: error);
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> scanNetworks() async {
|
||||
_setLoading(true);
|
||||
_debugProvider.addHttpLog('Scan WiFi networks');
|
||||
try {
|
||||
_networks = await _httpApiService.scanWifi();
|
||||
_errorMessage = null;
|
||||
_debugProvider.addHttpLog(
|
||||
'WiFi scan completed',
|
||||
details: <String, Object>{'networks': _networks.length},
|
||||
);
|
||||
} catch (error) {
|
||||
_errorMessage = error.toString();
|
||||
_debugProvider.addHttpLog('WiFi scan failed', details: error);
|
||||
} finally {
|
||||
_setLoading(false);
|
||||
}
|
||||
@@ -76,13 +96,19 @@ class WifiProvider extends ChangeNotifier {
|
||||
|
||||
Future<void> connect({required String ssid, required String password}) async {
|
||||
_setLoading(true);
|
||||
_debugProvider.addHttpLog(
|
||||
'Connect WiFi network',
|
||||
details: <String, Object>{'ssid': ssid},
|
||||
);
|
||||
try {
|
||||
await _httpApiService.connectWifi(ssid, password);
|
||||
await refreshStatus();
|
||||
_hotspotEnabled = false;
|
||||
_errorMessage = null;
|
||||
_debugProvider.addHttpLog('WiFi connected', details: <String, Object>{'ssid': ssid});
|
||||
} catch (error) {
|
||||
_errorMessage = error.toString();
|
||||
_debugProvider.addHttpLog('Connect WiFi failed', details: error);
|
||||
notifyListeners();
|
||||
} finally {
|
||||
_setLoading(false);
|
||||
@@ -91,13 +117,19 @@ class WifiProvider extends ChangeNotifier {
|
||||
|
||||
Future<void> startHotspot({String? ssid, String? password}) async {
|
||||
_setLoading(true);
|
||||
_debugProvider.addHttpLog(
|
||||
'Start hotspot',
|
||||
details: <String, Object?>{'ssid': ssid},
|
||||
);
|
||||
try {
|
||||
await _httpApiService.startAP(ssid, password);
|
||||
_hotspotEnabled = true;
|
||||
_errorMessage = null;
|
||||
_debugProvider.addHttpLog('Hotspot started');
|
||||
notifyListeners();
|
||||
} catch (error) {
|
||||
_errorMessage = error.toString();
|
||||
_debugProvider.addHttpLog('Start hotspot failed', details: error);
|
||||
notifyListeners();
|
||||
} finally {
|
||||
_setLoading(false);
|
||||
@@ -106,13 +138,16 @@ class WifiProvider extends ChangeNotifier {
|
||||
|
||||
Future<void> stopHotspot() async {
|
||||
_setLoading(true);
|
||||
_debugProvider.addHttpLog('Stop hotspot');
|
||||
try {
|
||||
await _httpApiService.stopAP();
|
||||
_hotspotEnabled = false;
|
||||
_errorMessage = null;
|
||||
_debugProvider.addHttpLog('Hotspot stopped');
|
||||
notifyListeners();
|
||||
} catch (error) {
|
||||
_errorMessage = error.toString();
|
||||
_debugProvider.addHttpLog('Stop hotspot failed', details: error);
|
||||
notifyListeners();
|
||||
} finally {
|
||||
_setLoading(false);
|
||||
|
||||
Reference in New Issue
Block a user