From 24fa78741b2fb8094be33dbabea974e801f2eee9 Mon Sep 17 00:00:00 2001 From: Winston Lowe Date: Sat, 14 Mar 2026 11:46:05 -0700 Subject: [PATCH] add TCP server address and port settings to AppSettings and update TcpScreen --- lib/models/app_settings.dart | 12 ++++++++++++ lib/screens/tcp_screen.dart | 18 ++++++++++++++++-- lib/services/app_settings_service.dart | 8 ++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/lib/models/app_settings.dart b/lib/models/app_settings.dart index c89ac27..fc84851 100644 --- a/lib/models/app_settings.dart +++ b/lib/models/app_settings.dart @@ -40,6 +40,8 @@ class AppSettings { final UnitSystem unitSystem; final Set mutedChannels; final bool mapShowDiscoveryContacts; + final String tcpServerAddress; + final int tcpServerPort; AppSettings({ this.clearPathOnMaxRetry = false, @@ -68,6 +70,8 @@ class AppSettings { this.unitSystem = UnitSystem.metric, Set? mutedChannels, this.mapShowDiscoveryContacts = true, + this.tcpServerAddress = '', + this.tcpServerPort = 0, }) : batteryChemistryByDeviceId = batteryChemistryByDeviceId ?? {}, batteryChemistryByRepeaterId = batteryChemistryByRepeaterId ?? {}, mutedChannels = mutedChannels ?? {}; @@ -100,6 +104,8 @@ class AppSettings { 'unit_system': unitSystem.value, 'muted_channels': mutedChannels.toList(), 'map_show_discovery_contacts': mapShowDiscoveryContacts, + 'tcp_server_address': tcpServerAddress, + 'tcp_server_port': tcpServerPort, }; } @@ -157,6 +163,8 @@ class AppSettings { {}, mapShowDiscoveryContacts: json['map_show_discovery_contacts'] as bool? ?? true, + tcpServerAddress: json['tcp_server_address'] as String? ?? '', + tcpServerPort: json['tcp_server_port'] as int? ?? 0, ); } @@ -187,6 +195,8 @@ class AppSettings { UnitSystem? unitSystem, Set? mutedChannels, bool? mapShowDiscoveryContacts, + String? tcpServerAddress, + int? tcpServerPort, }) { return AppSettings( clearPathOnMaxRetry: clearPathOnMaxRetry ?? this.clearPathOnMaxRetry, @@ -225,6 +235,8 @@ class AppSettings { mutedChannels: mutedChannels ?? this.mutedChannels, mapShowDiscoveryContacts: mapShowDiscoveryContacts ?? this.mapShowDiscoveryContacts, + tcpServerAddress: tcpServerAddress ?? this.tcpServerAddress, + tcpServerPort: tcpServerPort ?? this.tcpServerPort, ); } } diff --git a/lib/screens/tcp_screen.dart b/lib/screens/tcp_screen.dart index cf87382..02b9b5a 100644 --- a/lib/screens/tcp_screen.dart +++ b/lib/screens/tcp_screen.dart @@ -1,10 +1,12 @@ import 'dart:async'; import 'package:flutter/material.dart'; +import 'package:meshcore_open/models/app_settings.dart'; import 'package:provider/provider.dart'; import '../connector/meshcore_connector.dart'; import '../l10n/l10n.dart'; +import '../services/app_settings_service.dart'; import '../utils/platform_info.dart'; import '../widgets/adaptive_app_bar_title.dart'; import 'contacts_screen.dart'; @@ -27,8 +29,14 @@ class _TcpScreenState extends State { @override void initState() { super.initState(); - _hostController = TextEditingController(); - _portController = TextEditingController(text: '5000'); + _hostController = TextEditingController( + text: context.read().settings.tcpServerAddress, + ); + _portController = TextEditingController( + text: context.read().settings.tcpServerPort > 0 + ? context.read().settings.tcpServerPort.toString() + : '', + ); _connector = context.read(); _connectionListener = () { @@ -39,6 +47,12 @@ class _TcpScreenState extends State { if (_connector.state == MeshCoreConnectionState.connected && _connector.isTcpTransportConnected && !_navigatedToContacts) { + context.read().setTcpServerAddress( + _hostController.text, + ); + context.read().setTcpServerPort( + int.tryParse(_portController.text) ?? 0, + ); _navigatedToContacts = true; Navigator.of(context).pushReplacement( MaterialPageRoute(builder: (_) => const ContactsScreen()), diff --git a/lib/services/app_settings_service.dart b/lib/services/app_settings_service.dart index a52e364..88c1f81 100644 --- a/lib/services/app_settings_service.dart +++ b/lib/services/app_settings_service.dart @@ -182,4 +182,12 @@ class AppSettingsService extends ChangeNotifier { ..remove(channelName); await updateSettings(_settings.copyWith(mutedChannels: updated)); } + + Future setTcpServerAddress(String value) async { + await updateSettings(_settings.copyWith(tcpServerAddress: value)); + } + + Future setTcpServerPort(int value) async { + await updateSettings(_settings.copyWith(tcpServerPort: value)); + } }