mirror of
https://github.com/zjs81/meshcore-open.git
synced 2026-06-14 22:55:12 +10:00
add TCP server address and port settings to AppSettings and update TcpScreen
This commit is contained in:
@@ -40,6 +40,8 @@ class AppSettings {
|
|||||||
final UnitSystem unitSystem;
|
final UnitSystem unitSystem;
|
||||||
final Set<String> mutedChannels;
|
final Set<String> mutedChannels;
|
||||||
final bool mapShowDiscoveryContacts;
|
final bool mapShowDiscoveryContacts;
|
||||||
|
final String tcpServerAddress;
|
||||||
|
final int tcpServerPort;
|
||||||
|
|
||||||
AppSettings({
|
AppSettings({
|
||||||
this.clearPathOnMaxRetry = false,
|
this.clearPathOnMaxRetry = false,
|
||||||
@@ -68,6 +70,8 @@ class AppSettings {
|
|||||||
this.unitSystem = UnitSystem.metric,
|
this.unitSystem = UnitSystem.metric,
|
||||||
Set<String>? mutedChannels,
|
Set<String>? mutedChannels,
|
||||||
this.mapShowDiscoveryContacts = true,
|
this.mapShowDiscoveryContacts = true,
|
||||||
|
this.tcpServerAddress = '',
|
||||||
|
this.tcpServerPort = 0,
|
||||||
}) : batteryChemistryByDeviceId = batteryChemistryByDeviceId ?? {},
|
}) : batteryChemistryByDeviceId = batteryChemistryByDeviceId ?? {},
|
||||||
batteryChemistryByRepeaterId = batteryChemistryByRepeaterId ?? {},
|
batteryChemistryByRepeaterId = batteryChemistryByRepeaterId ?? {},
|
||||||
mutedChannels = mutedChannels ?? {};
|
mutedChannels = mutedChannels ?? {};
|
||||||
@@ -100,6 +104,8 @@ class AppSettings {
|
|||||||
'unit_system': unitSystem.value,
|
'unit_system': unitSystem.value,
|
||||||
'muted_channels': mutedChannels.toList(),
|
'muted_channels': mutedChannels.toList(),
|
||||||
'map_show_discovery_contacts': mapShowDiscoveryContacts,
|
'map_show_discovery_contacts': mapShowDiscoveryContacts,
|
||||||
|
'tcp_server_address': tcpServerAddress,
|
||||||
|
'tcp_server_port': tcpServerPort,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -157,6 +163,8 @@ class AppSettings {
|
|||||||
{},
|
{},
|
||||||
mapShowDiscoveryContacts:
|
mapShowDiscoveryContacts:
|
||||||
json['map_show_discovery_contacts'] as bool? ?? true,
|
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,
|
UnitSystem? unitSystem,
|
||||||
Set<String>? mutedChannels,
|
Set<String>? mutedChannels,
|
||||||
bool? mapShowDiscoveryContacts,
|
bool? mapShowDiscoveryContacts,
|
||||||
|
String? tcpServerAddress,
|
||||||
|
int? tcpServerPort,
|
||||||
}) {
|
}) {
|
||||||
return AppSettings(
|
return AppSettings(
|
||||||
clearPathOnMaxRetry: clearPathOnMaxRetry ?? this.clearPathOnMaxRetry,
|
clearPathOnMaxRetry: clearPathOnMaxRetry ?? this.clearPathOnMaxRetry,
|
||||||
@@ -225,6 +235,8 @@ class AppSettings {
|
|||||||
mutedChannels: mutedChannels ?? this.mutedChannels,
|
mutedChannels: mutedChannels ?? this.mutedChannels,
|
||||||
mapShowDiscoveryContacts:
|
mapShowDiscoveryContacts:
|
||||||
mapShowDiscoveryContacts ?? this.mapShowDiscoveryContacts,
|
mapShowDiscoveryContacts ?? this.mapShowDiscoveryContacts,
|
||||||
|
tcpServerAddress: tcpServerAddress ?? this.tcpServerAddress,
|
||||||
|
tcpServerPort: tcpServerPort ?? this.tcpServerPort,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:meshcore_open/models/app_settings.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
import '../connector/meshcore_connector.dart';
|
import '../connector/meshcore_connector.dart';
|
||||||
import '../l10n/l10n.dart';
|
import '../l10n/l10n.dart';
|
||||||
|
import '../services/app_settings_service.dart';
|
||||||
import '../utils/platform_info.dart';
|
import '../utils/platform_info.dart';
|
||||||
import '../widgets/adaptive_app_bar_title.dart';
|
import '../widgets/adaptive_app_bar_title.dart';
|
||||||
import 'contacts_screen.dart';
|
import 'contacts_screen.dart';
|
||||||
@@ -27,8 +29,14 @@ class _TcpScreenState extends State<TcpScreen> {
|
|||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
_hostController = TextEditingController();
|
_hostController = TextEditingController(
|
||||||
_portController = TextEditingController(text: '5000');
|
text: context.read<AppSettingsService>().settings.tcpServerAddress,
|
||||||
|
);
|
||||||
|
_portController = TextEditingController(
|
||||||
|
text: context.read<AppSettingsService>().settings.tcpServerPort > 0
|
||||||
|
? context.read<AppSettingsService>().settings.tcpServerPort.toString()
|
||||||
|
: '',
|
||||||
|
);
|
||||||
_connector = context.read<MeshCoreConnector>();
|
_connector = context.read<MeshCoreConnector>();
|
||||||
|
|
||||||
_connectionListener = () {
|
_connectionListener = () {
|
||||||
@@ -39,6 +47,12 @@ class _TcpScreenState extends State<TcpScreen> {
|
|||||||
if (_connector.state == MeshCoreConnectionState.connected &&
|
if (_connector.state == MeshCoreConnectionState.connected &&
|
||||||
_connector.isTcpTransportConnected &&
|
_connector.isTcpTransportConnected &&
|
||||||
!_navigatedToContacts) {
|
!_navigatedToContacts) {
|
||||||
|
context.read<AppSettingsService>().setTcpServerAddress(
|
||||||
|
_hostController.text,
|
||||||
|
);
|
||||||
|
context.read<AppSettingsService>().setTcpServerPort(
|
||||||
|
int.tryParse(_portController.text) ?? 0,
|
||||||
|
);
|
||||||
_navigatedToContacts = true;
|
_navigatedToContacts = true;
|
||||||
Navigator.of(context).pushReplacement(
|
Navigator.of(context).pushReplacement(
|
||||||
MaterialPageRoute(builder: (_) => const ContactsScreen()),
|
MaterialPageRoute(builder: (_) => const ContactsScreen()),
|
||||||
|
|||||||
@@ -182,4 +182,12 @@ class AppSettingsService extends ChangeNotifier {
|
|||||||
..remove(channelName);
|
..remove(channelName);
|
||||||
await updateSettings(_settings.copyWith(mutedChannels: updated));
|
await updateSettings(_settings.copyWith(mutedChannels: updated));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> setTcpServerAddress(String value) async {
|
||||||
|
await updateSettings(_settings.copyWith(tcpServerAddress: value));
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> setTcpServerPort(int value) async {
|
||||||
|
await updateSettings(_settings.copyWith(tcpServerPort: value));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user