feat(wifi): enable wifi settings entry point and add debug logging

This commit is contained in:
2026-04-21 17:59:39 +02:00
parent 90048ac159
commit 9d6953dbf5
2 changed files with 36 additions and 17 deletions

View File

@@ -4,6 +4,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:legacy_ui/legacy_ui.dart';
import 'package:navigation/navigation.dart';
import 'package:sf_localizations/sf_localizations.dart';
import 'package:sf_shared/sf_shared.dart';
import 'package:utils/utils.dart';
class SettingsScreen extends ConsumerWidget {
@@ -14,12 +15,11 @@ class SettingsScreen extends ConsumerWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
final color = context.sfColors.legacyPrimary;
// final hasWifi = ref.watch(
// selectedDeviceProvider.select((d) {
// final types = d.value?.capabilities?.commands;
// return types?.types.contains('WIFI_SEARCH') ?? false;
// }),
// );
final hasWifi = ref.watch(
selectedDeviceProvider.select((d) {
return d.value?.capabilities?.wifi?.enabled ?? false;
}),
);
return LegacyPageLayout(
title: context.translate(I18n.deviceSettingsTitle),
@@ -113,15 +113,15 @@ class SettingsScreen extends ConsumerWidget {
text: I18n.sound,
color: color,
),
// if (hasWifi)
// _item(
// context,
// onPressed: () =>
// navigationContract.pushTo(AppRoutes.wifiSettings),
// icon: Icons.wifi_find_outlined,
// text: I18n.wifiSettings,
// color: color,
// ),
if (hasWifi)
_item(
context,
onPressed: () =>
navigationContract.pushTo(AppRoutes.wifiSettings),
icon: Icons.wifi_find_outlined,
text: I18n.wifiSettings,
color: color,
),
// _item(
// context,
// onPressed: () =>

View File

@@ -1,5 +1,6 @@
import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:get_it/get_it.dart';
import 'package:legacy_device_state/legacy_device_state.dart';
@@ -54,6 +55,7 @@ class WifiSettingsViewModel extends Notifier<WifiSettingsViewState> {
void _onWebSocketEvent(WebSocketEvent event) {
switch (event) {
case WifiEvent():
debugPrint('[WiFi] WS received WIFI_CURRENT: ssid=${event.ssid} bssid=${event.bssid}');
_currentNetworkTimeout?.cancel();
final network = WifiNetworkEntity(
id: '',
@@ -67,6 +69,7 @@ class WifiSettingsViewModel extends Notifier<WifiSettingsViewState> {
isLoadingCurrentNetwork: false,
);
case WifiSearchEvent():
debugPrint('[WiFi] WS received WIFI_SEARCH: ${event.wifis.length} networks');
_scanCountdown?.cancel();
final networks = event.wifis
.map(
@@ -95,10 +98,12 @@ class WifiSettingsViewModel extends Notifier<WifiSettingsViewState> {
}
try {
debugPrint('[WiFi] loading saved networks for $identificator');
final networks = await _repository.getWifiNetworks(
deviceIdentificator: identificator,
);
if (!ref.mounted) return;
debugPrint('[WiFi] loaded ${networks.length} saved networks');
state = state.copyWith(
savedNetworks: networks,
@@ -106,6 +111,7 @@ class WifiSettingsViewModel extends Notifier<WifiSettingsViewState> {
isLoadingCurrentNetwork: true,
);
debugPrint('[WiFi] sending WIFI_CURRENT command');
unawaited(
_commands
.send(
@@ -115,6 +121,7 @@ class WifiSettingsViewModel extends Notifier<WifiSettingsViewState> {
),
)
.catchError((_) {
debugPrint('[WiFi] WIFI_CURRENT command failed');
if (ref.mounted) {
state = state.copyWith(isLoadingCurrentNetwork: false);
}
@@ -148,12 +155,14 @@ class WifiSettingsViewModel extends Notifier<WifiSettingsViewState> {
);
try {
debugPrint('[WiFi] sending WIFI_SEARCH command');
await _commands.send(
request: SendCommandRequestModel(
device: identificator,
command: DeviceCommand.wifiSearch,
),
);
debugPrint('[WiFi] WIFI_SEARCH sent, waiting for WS response (${_scanDurationSeconds}s timeout)');
_scanCountdown?.cancel();
@@ -198,6 +207,7 @@ class WifiSettingsViewModel extends Notifier<WifiSettingsViewState> {
state = state.copyWith(isConnecting: true, error: null, success: null);
try {
debugPrint('[WiFi] connecting to $ssid ($bssid)');
await _commands.send(
request: SendCommandRequestModel(
device: identificator,
@@ -205,6 +215,7 @@ class WifiSettingsViewModel extends Notifier<WifiSettingsViewState> {
data: {'ssid': ssid, 'bssid': bssid, 'password': password},
),
);
debugPrint('[WiFi] SET_WIFI sent, saving network');
final id = const Uuid().v4();
await _repository.createWifiNetwork(
@@ -221,6 +232,7 @@ class WifiSettingsViewModel extends Notifier<WifiSettingsViewState> {
);
if (!ref.mounted) return;
debugPrint('[WiFi] network saved, total: ${networks.length}');
unawaited(_tracking.legacySettingsWifiAdded(totalCount: networks.length));
state = state.copyWith(
@@ -228,7 +240,8 @@ class WifiSettingsViewModel extends Notifier<WifiSettingsViewState> {
isConnecting: false,
success: WifiSettingsSuccess.networkSaved,
);
} catch (_) {
} catch (e) {
debugPrint('[WiFi] connectAndSave failed: $e');
if (!ref.mounted) return;
state = state.copyWith(
isConnecting: false,
@@ -244,6 +257,7 @@ class WifiSettingsViewModel extends Notifier<WifiSettingsViewState> {
state = state.copyWith(isSaving: true, error: null, success: null);
try {
debugPrint('[WiFi] deleting network $networkId');
await _repository.deleteWifiNetwork(networkId: networkId);
if (!ref.mounted) return;
@@ -252,6 +266,7 @@ class WifiSettingsViewModel extends Notifier<WifiSettingsViewState> {
);
if (!ref.mounted) return;
debugPrint('[WiFi] network deleted, remaining: ${networks.length}');
unawaited(
_tracking.legacySettingsWifiRemoved(totalCount: networks.length),
);
@@ -261,7 +276,8 @@ class WifiSettingsViewModel extends Notifier<WifiSettingsViewState> {
isSaving: false,
success: WifiSettingsSuccess.networkDeleted,
);
} catch (_) {
} catch (e) {
debugPrint('[WiFi] delete failed: $e');
if (!ref.mounted) return;
state = state.copyWith(
isSaving: false,
@@ -277,6 +293,7 @@ class WifiSettingsViewModel extends Notifier<WifiSettingsViewState> {
state = state.copyWith(isConnecting: true, error: null, success: null);
try {
debugPrint('[WiFi] setting saved network: ${network.ssid} (${network.bssid})');
await _commands.send(
request: SendCommandRequestModel(
device: identificator,
@@ -289,6 +306,7 @@ class WifiSettingsViewModel extends Notifier<WifiSettingsViewState> {
),
);
if (!ref.mounted) return;
debugPrint('[WiFi] SET_WIFI sent, requesting WIFI_CURRENT');
state = state.copyWith(
isConnecting: false,
@@ -305,6 +323,7 @@ class WifiSettingsViewModel extends Notifier<WifiSettingsViewState> {
),
)
.catchError((_) {
debugPrint('[WiFi] WIFI_CURRENT after set failed');
if (ref.mounted) {
state = state.copyWith(isLoadingCurrentNetwork: false);
}