Fix review findings, add default flood scope, and address recent issues
Review fixes: - Keep stored message history beyond the 200-message window; stop messages leaking between radios; reset link/session state on disconnect - Accept firmware's 176-byte RX frames over USB/TCP - Hold APP_START during contact sync; contact-sync watchdog; replay DMs from not-yet-known senders; tombstone late command replies; finish channel sync on ERR_NOT_FOUND; fail region-scoped sends cleanly - DM retry watchdog when RESP_CODE_SENT never arrives; late repeater CLI replies; ACK hash collisions; UTF-8-safe name truncation - Image pipeline: delete-during-decode, lifecycle cancels, decoder memory release, entry cap, dead worker recovery, atomic model writes - Storage: deterministic reaction hash across web/native, Smaz double-decode, per-entry parsing, per-radio path history and regions, review-mode data isolation - UI: safe channel slot selection, byte-length name limits, double-send guard, mounted checks, localized hardcoded strings - Skip persisted-store reload on repeat SELF_INFO Features: - Radio default flood scope (firmware ver 11+) and explicit unscoped sends (ver 12+) - Scan for nearby nodes (#570) - Optional distinct first-hop repeater counting for channel resend (#589) - Optional region next to hop count (#580) Issues: - Message text follows system font size (#569) - Repeater/room password field accepts 20 chars (#576) - TCP auto-reconnect and keepalive (#571) - Order feeds by local receive time; flag future timestamps (#584) - Coding rate help text (#568), French "Favoris" (#575) - iOS/macOS app badge now clears Translations for all new strings in every locale.
This commit is contained in:
1 parent
a64a33d0c0
commit
25f197c979
120 files changed
+10424
-687
No files matched your search
@@ -628,6 +628,18 @@ class AppSettingsScreen extends StatelessWidget {
|
||||
},
|
||||
),
|
||||
const Divider(height: 1, indent: 16),
|
||||
SwitchListTile(
|
||||
contentPadding: const EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
vertical: 4,
|
||||
),
|
||||
secondary: const Icon(Icons.short_text, size: 20),
|
||||
title: Text(context.l10n.appSettings_regionOnHopsLine),
|
||||
subtitle: Text(context.l10n.appSettings_regionOnHopsLineSubtitle),
|
||||
value: settingsService.settings.regionOnHopsLine,
|
||||
onChanged: settingsService.setRegionOnHopsLine,
|
||||
),
|
||||
const Divider(height: 1, indent: 16),
|
||||
SwitchListTile(
|
||||
contentPadding: const EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
@@ -672,6 +684,21 @@ class AppSettingsScreen extends StatelessWidget {
|
||||
settingsService.setChannelMinHopsRetries(value.toInt()),
|
||||
),
|
||||
),
|
||||
SwitchListTile(
|
||||
contentPadding: const EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
vertical: 4,
|
||||
),
|
||||
secondary: const Icon(Icons.hub_outlined, size: 20),
|
||||
title: Text(context.l10n.appSettings_channelMinHopsCountRepeaters),
|
||||
subtitle: Text(
|
||||
context.l10n.appSettings_channelMinHopsCountRepeatersSubtitle(
|
||||
settingsService.settings.channelMinHops,
|
||||
),
|
||||
),
|
||||
value: settingsService.settings.channelMinHopsCountRepeaters,
|
||||
onChanged: settingsService.setChannelMinHopsCountRepeaters,
|
||||
),
|
||||
],
|
||||
const Divider(height: 1, indent: 16),
|
||||
_ScrollIntoViewOnce(
|
||||
@@ -854,11 +881,15 @@ class AppSettingsScreen extends StatelessWidget {
|
||||
ImageCodecModelSpec spec,
|
||||
) async {
|
||||
final messenger = ScaffoldMessenger.of(context);
|
||||
final failed = context.l10n.imageMessages_downloadFailed;
|
||||
final l10n = context.l10n;
|
||||
try {
|
||||
await codec.downloadPresetModel(spec);
|
||||
} on Exception catch (error) {
|
||||
messenger.showSnackBar(SnackBar(content: Text('$failed $error')));
|
||||
messenger.showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(l10n.imageMessages_downloadFailedWithError('$error')),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -52,6 +52,7 @@ import '../widgets/sync_progress_overlay.dart';
|
||||
import '../widgets/translated_message_content.dart';
|
||||
import '../widgets/unread_divider.dart';
|
||||
import '../theme/mesh_theme.dart';
|
||||
import '../widgets/future_timestamp_indicator.dart';
|
||||
import '../widgets/mesh_ui.dart';
|
||||
import 'app_settings_screen.dart';
|
||||
import 'channel_message_path_screen.dart';
|
||||
@@ -97,6 +98,9 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
|
||||
MeshCoreConnector? _connector;
|
||||
DateTime? _lastChannelSendAt;
|
||||
// True while a send is awaiting outgoing translation, so a second tap
|
||||
// can't send the same text again.
|
||||
bool _isSendingText = false;
|
||||
bool _channelSkipNextBottomSnap = false;
|
||||
String? _unreadDividerMessageId;
|
||||
|
||||
@@ -342,8 +346,14 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
final defaultSuffix = ownRegion.isEmpty
|
||||
? ' ${context.l10n.channels_regionDefaultSuffix}'
|
||||
: '';
|
||||
final radioDefault = connector.defaultFloodScopeName;
|
||||
final regionText = region.isNotEmpty
|
||||
? ' • ${context.l10n.channels_regionSetTo(region)}$defaultSuffix'
|
||||
: radioDefault != null &&
|
||||
connector.channelUsesRadioDefaultScope(
|
||||
widget.channel.index,
|
||||
)
|
||||
? ' • ${context.l10n.channels_regionSetTo(radioDefault)} ${context.l10n.channels_regionRadioDefaultSuffix}'
|
||||
: '';
|
||||
return Text(
|
||||
'$privacy$regionText',
|
||||
@@ -600,6 +610,7 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
) {
|
||||
final settingsService = context.watch<AppSettingsService>();
|
||||
final enableTracing = settingsService.settings.enableMessageTracing;
|
||||
final regionOnHopsLine = settingsService.settings.regionOnHopsLine;
|
||||
final isOutgoing = message.isOutgoing;
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
final gifId = GifHelper.parseGif(message.text);
|
||||
@@ -851,9 +862,8 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
_RouteRegionChips(
|
||||
sameLine: regionOnHopsLine,
|
||||
children: [
|
||||
RouteChip(
|
||||
isDirect: (message.pathLength ?? -1) >= 0,
|
||||
@@ -861,7 +871,9 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
),
|
||||
if (message.region?.isNotEmpty ?? false)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 2),
|
||||
padding: regionOnHopsLine
|
||||
? EdgeInsets.zero
|
||||
: const EdgeInsets.only(top: 2),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 6,
|
||||
@@ -929,6 +941,10 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
color: metaColor,
|
||||
),
|
||||
),
|
||||
if (message.hasFutureTimestamp) ...[
|
||||
const SizedBox(width: 4),
|
||||
FutureTimestampIndicator(size: 16 * textScale),
|
||||
],
|
||||
if (enableTracing &&
|
||||
!isOutgoing &&
|
||||
message.repeatCount > 0) ...[
|
||||
@@ -1552,6 +1568,7 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
previewPng: previewPng,
|
||||
rate: aeicRatePointForUi(result.rate),
|
||||
chunkCount: chunkSet.dataChunkCount,
|
||||
aspectCode: await _aspectCodeOf(sourceBytes),
|
||||
);
|
||||
} on Exception catch (error) {
|
||||
debugPrint('outgoing image registration failed: $error');
|
||||
@@ -2237,8 +2254,22 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
}
|
||||
|
||||
Future<void> _sendMessage() async {
|
||||
if (_isSendingText) return;
|
||||
_isSendingText = true;
|
||||
try {
|
||||
await _sendMessageInner();
|
||||
} finally {
|
||||
_isSendingText = false;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _sendMessageInner() async {
|
||||
final text = _textController.text.trim();
|
||||
if (text.isEmpty) return;
|
||||
// Capture the reply target now; the user may change it while the
|
||||
// outgoing translation runs.
|
||||
final replyTo = _replyingToMessage;
|
||||
final replyRegion = _useReplyRegion ? replyTo?.region : null;
|
||||
|
||||
final now = DateTime.now();
|
||||
if (_lastChannelSendAt != null &&
|
||||
@@ -2282,10 +2313,9 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (_replyingToMessage != null) {
|
||||
messageText = '@[${_replyingToMessage!.senderName}] $messageText';
|
||||
if (replyTo != null) {
|
||||
messageText = '@[${replyTo.senderName}] $messageText';
|
||||
}
|
||||
final replyRegion = _useReplyRegion ? _replyingToMessage?.region : null;
|
||||
|
||||
final maxBytes = maxChannelMessageBytes(connector.selfName);
|
||||
final outboundText = connector.prepareChannelOutboundText(
|
||||
@@ -2309,9 +2339,13 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
}
|
||||
// end transform
|
||||
|
||||
final replyTo = _replyingToMessage;
|
||||
_textController.clear();
|
||||
_cancelReply();
|
||||
// Keep anything the user typed or a new reply picked during translation.
|
||||
if (_textController.text.trim() == text) {
|
||||
_textController.clear();
|
||||
}
|
||||
if (identical(_replyingToMessage, replyTo)) {
|
||||
_cancelReply();
|
||||
}
|
||||
_textFieldFocusNode.requestFocus();
|
||||
connector.sendChannelMessage(
|
||||
widget.channel,
|
||||
@@ -2575,6 +2609,62 @@ class _RegionSelectDialog extends StatefulWidget {
|
||||
class _RegionSelectDialogState extends State<_RegionSelectDialog> {
|
||||
final RegionStore regionStore = RegionStore();
|
||||
|
||||
bool _canForceUnscoped(BuildContext context) =>
|
||||
context.read<MeshCoreConnector>().supportsExplicitUnscopedFlood;
|
||||
|
||||
bool _hasOwnAssignment(BuildContext context) {
|
||||
final connector = context.read<MeshCoreConnector>();
|
||||
final index = widget.channel.index;
|
||||
return connector.hasChannelRegion(index) ||
|
||||
connector.isChannelExplicitlyUnscoped(index);
|
||||
}
|
||||
|
||||
/// On firmware that cannot force an unscoped flood, explain that floods
|
||||
/// without a region still use the radio's default region.
|
||||
List<Widget> _buildRadioDefaultNote(BuildContext context) {
|
||||
final connector = context.read<MeshCoreConnector>();
|
||||
final radioDefault = connector.defaultFloodScopeName;
|
||||
if (radioDefault == null || connector.supportsExplicitUnscopedFlood) {
|
||||
return const [];
|
||||
}
|
||||
return [
|
||||
const SizedBox(height: 8),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
child: Text(
|
||||
context.l10n.channels_regionRadioDefaultApplies(radioDefault),
|
||||
style: Theme.of(context).textTheme.bodyMedium,
|
||||
),
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
Widget _buildUnscopedTile(BuildContext context) {
|
||||
final connector = context.read<MeshCoreConnector>();
|
||||
final selected = connector.isChannelExplicitlyUnscoped(
|
||||
widget.channel.index,
|
||||
);
|
||||
return ListTile(
|
||||
leading: Icon(
|
||||
Icons.public_off,
|
||||
color: selected ? MeshPalette.blue : null,
|
||||
),
|
||||
title: Text(context.l10n.settings_regionNoRegion),
|
||||
trailing: selected
|
||||
? const Icon(Icons.check, color: MeshPalette.blue)
|
||||
: null,
|
||||
tileColor: selected ? MeshPalette.blueBg : null,
|
||||
onTap: () {
|
||||
// Tapping the already-selected option clears it back to the default.
|
||||
connector.setChannelRegion(
|
||||
widget.channel.index,
|
||||
selected ? '' : kUnscopedRegion,
|
||||
);
|
||||
Navigator.pop(context);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
List<Region> regions = [];
|
||||
int selectedIndex = -1;
|
||||
|
||||
@@ -2615,7 +2705,9 @@ class _RegionSelectDialogState extends State<_RegionSelectDialog> {
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
),
|
||||
),
|
||||
..._buildRadioDefaultNote(context),
|
||||
const SizedBox(height: 8),
|
||||
if (_canForceUnscoped(context)) _buildUnscopedTile(context),
|
||||
if (regions.isEmpty)
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(24),
|
||||
@@ -2653,11 +2745,7 @@ class _RegionSelectDialogState extends State<_RegionSelectDialog> {
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
TextButton(
|
||||
onPressed:
|
||||
context
|
||||
.read<MeshCoreConnector>()
|
||||
.getChannelRegion(widget.channel.index)
|
||||
.isEmpty
|
||||
onPressed: !_hasOwnAssignment(context)
|
||||
? null
|
||||
: () {
|
||||
context.read<MeshCoreConnector>().setChannelRegion(
|
||||
@@ -2861,7 +2949,9 @@ class _ChannelChatRow {
|
||||
|
||||
const _ChannelChatRow({this.message, this.image});
|
||||
|
||||
DateTime get timestamp => message?.timestamp ?? image!.firstSeen;
|
||||
/// Local arrival time, used for ordering and day separators so a sender
|
||||
/// clock running ahead cannot pin a row to the bottom (#584).
|
||||
DateTime get timestamp => message?.receivedAt ?? image!.firstSeen;
|
||||
|
||||
/// Stable identity for the scroll-to-message [GlobalKey] map. The `aeic:`
|
||||
/// prefix keeps a stream id from ever colliding with a message id.
|
||||
@@ -2890,3 +2980,33 @@ ReceivedImageStrings _receivedImageStrings(BuildContext context) {
|
||||
openSettings: l10n.receivedImage_openSettings,
|
||||
);
|
||||
}
|
||||
|
||||
/// A message's route chip and region chip: stacked by default, or side by
|
||||
/// side (wrapping on narrow bubbles) when "Region next to hop count" is on.
|
||||
class _RouteRegionChips extends StatelessWidget {
|
||||
const _RouteRegionChips({required this.sameLine, required this.children});
|
||||
|
||||
final bool sameLine;
|
||||
final List<Widget> children;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (sameLine) {
|
||||
// Flexible bounds the Wrap's width inside the bubble's Row so a long
|
||||
// region name wraps under the hop chip instead of overflowing.
|
||||
return Flexible(
|
||||
child: Wrap(
|
||||
spacing: 4,
|
||||
runSpacing: 2,
|
||||
crossAxisAlignment: WrapCrossAlignment.center,
|
||||
children: children,
|
||||
),
|
||||
);
|
||||
}
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: children,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -30,6 +30,7 @@ import '../widgets/sync_progress_overlay.dart';
|
||||
import '../widgets/unread_badge.dart';
|
||||
import '../helpers/gif_helper.dart';
|
||||
import '../helpers/snack_bar_builder.dart';
|
||||
import '../helpers/utf8_length_limiter.dart';
|
||||
import 'channel_chat_screen.dart';
|
||||
import 'community_qr_scanner_screen.dart';
|
||||
import 'contacts_screen.dart';
|
||||
@@ -399,6 +400,9 @@ class _ChannelsScreenState extends State<ChannelsScreen>
|
||||
? context.l10n.channels_regionSetTo(
|
||||
connector.getChannelRegion(channel.index),
|
||||
)
|
||||
: connector.isChannelExplicitlyUnscoped(channel.index) &&
|
||||
connector.supportsExplicitUnscopedFlood
|
||||
? context.l10n.channels_regionNotSet
|
||||
: '';
|
||||
switch (channelType) {
|
||||
case ChannelType.communityPublic:
|
||||
@@ -836,17 +840,7 @@ class _ChannelsScreenState extends State<ChannelsScreen>
|
||||
|
||||
void _showAddChannelDialog(BuildContext context) {
|
||||
final connector = context.read<MeshCoreConnector>();
|
||||
final nextIndex = _findNextAvailableIndex(
|
||||
connector.channels,
|
||||
connector.maxChannels,
|
||||
);
|
||||
if (nextIndex == null) {
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(context.l10n.channels_noFreeSlots),
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (_resolveFreeChannelSlot(context, connector) == null) return;
|
||||
final hasPublicChannel = connector.channels.any((c) => c.isPublicChannel);
|
||||
int? selectedOption;
|
||||
final nameController = TextEditingController();
|
||||
@@ -958,7 +952,11 @@ class _ChannelsScreenState extends State<ChannelsScreen>
|
||||
labelText: sheetContext.l10n.channels_channelName,
|
||||
border: const OutlineInputBorder(),
|
||||
),
|
||||
maxLength: 31,
|
||||
inputFormatters: const [
|
||||
Utf8LengthLimitingTextInputFormatter(
|
||||
maxRadioNameBytes,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
@@ -980,6 +978,11 @@ class _ChannelsScreenState extends State<ChannelsScreen>
|
||||
);
|
||||
return;
|
||||
}
|
||||
final nextIndex = _resolveFreeChannelSlot(
|
||||
context,
|
||||
connector,
|
||||
);
|
||||
if (nextIndex == null) return;
|
||||
final psk = randomBytes(16);
|
||||
Navigator.pop(sheetContext);
|
||||
await connector.setChannel(
|
||||
@@ -1023,7 +1026,11 @@ class _ChannelsScreenState extends State<ChannelsScreen>
|
||||
labelText: sheetContext.l10n.channels_channelName,
|
||||
border: const OutlineInputBorder(),
|
||||
),
|
||||
maxLength: 31,
|
||||
inputFormatters: const [
|
||||
Utf8LengthLimitingTextInputFormatter(
|
||||
maxRadioNameBytes,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
@@ -1071,6 +1078,11 @@ class _ChannelsScreenState extends State<ChannelsScreen>
|
||||
);
|
||||
return;
|
||||
}
|
||||
final nextIndex = _resolveFreeChannelSlot(
|
||||
context,
|
||||
connector,
|
||||
);
|
||||
if (nextIndex == null) return;
|
||||
Navigator.pop(sheetContext);
|
||||
connector.setChannel(nextIndex, name, psk);
|
||||
if (context.mounted) {
|
||||
@@ -1103,6 +1115,11 @@ class _ChannelsScreenState extends State<ChannelsScreen>
|
||||
Expanded(
|
||||
child: FilledButton(
|
||||
onPressed: () {
|
||||
final nextIndex = _resolveFreeChannelSlot(
|
||||
context,
|
||||
connector,
|
||||
);
|
||||
if (nextIndex == null) return;
|
||||
final psk = Channel.parsePskHex(
|
||||
Channel.publicChannelPsk,
|
||||
);
|
||||
@@ -1214,7 +1231,21 @@ class _ChannelsScreenState extends State<ChannelsScreen>
|
||||
border: const OutlineInputBorder(),
|
||||
prefixIcon: const Icon(Icons.tag),
|
||||
),
|
||||
maxLength: 31,
|
||||
inputFormatters: [
|
||||
Utf8LengthLimitingTextInputFormatter(
|
||||
maxRadioNameBytes,
|
||||
encoder: (text) {
|
||||
final tag = text.trim().startsWith('#')
|
||||
? text.trim().substring(1)
|
||||
: text.trim();
|
||||
if (!isRegularHashtag &&
|
||||
selectedCommunity != null) {
|
||||
return '${selectedCommunity!.name} #$tag';
|
||||
}
|
||||
return '#$tag';
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
// Privacy hint for community hashtags
|
||||
@@ -1259,6 +1290,27 @@ class _ChannelsScreenState extends State<ChannelsScreen>
|
||||
if (hashtag.startsWith('#')) {
|
||||
hashtag = hashtag.substring(1);
|
||||
}
|
||||
if (!isRegularHashtag &&
|
||||
selectedCommunity != null &&
|
||||
utf8ByteLength(
|
||||
'${selectedCommunity!.name} #$hashtag',
|
||||
) >
|
||||
maxRadioNameBytes) {
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(
|
||||
sheetContext.l10n.channels_nameTooLong(
|
||||
maxRadioNameBytes,
|
||||
),
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
final nextIndex = _resolveFreeChannelSlot(
|
||||
context,
|
||||
connector,
|
||||
);
|
||||
if (nextIndex == null) return;
|
||||
final String channelName;
|
||||
|
||||
final Uint8List psk;
|
||||
@@ -1369,7 +1421,13 @@ class _ChannelsScreenState extends State<ChannelsScreen>
|
||||
border: const OutlineInputBorder(),
|
||||
prefixIcon: const Icon(Icons.groups),
|
||||
),
|
||||
maxLength: 31,
|
||||
inputFormatters: [
|
||||
Utf8LengthLimitingTextInputFormatter(
|
||||
maxRadioNameBytes,
|
||||
encoder: (text) =>
|
||||
'$text ${sheetContext.l10n.channels_public}',
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
CheckboxListTile(
|
||||
@@ -1408,6 +1466,16 @@ class _ChannelsScreenState extends State<ChannelsScreen>
|
||||
return;
|
||||
}
|
||||
|
||||
final nextIndex = addPublicChannel
|
||||
? _resolveFreeChannelSlot(
|
||||
context,
|
||||
connector,
|
||||
)
|
||||
: null;
|
||||
if (addPublicChannel && nextIndex == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Create community with random secret
|
||||
final community = Community.create(
|
||||
id: const Uuid().v4(),
|
||||
@@ -1418,11 +1486,13 @@ class _ChannelsScreenState extends State<ChannelsScreen>
|
||||
await _communityStore.addCommunity(community);
|
||||
|
||||
// Optionally add the community public channel to the device
|
||||
if (addPublicChannel) {
|
||||
if (nextIndex != null) {
|
||||
final psk = community
|
||||
.deriveCommunityPublicPsk();
|
||||
final channelName =
|
||||
'${community.name} $publicLabel';
|
||||
final channelName = fitRadioName(
|
||||
community.name,
|
||||
publicLabel,
|
||||
);
|
||||
connector.setChannel(
|
||||
nextIndex,
|
||||
channelName,
|
||||
@@ -1602,7 +1672,9 @@ class _ChannelsScreenState extends State<ChannelsScreen>
|
||||
labelText: sheetContext.l10n.channels_channelName,
|
||||
border: const OutlineInputBorder(),
|
||||
),
|
||||
maxLength: 31,
|
||||
inputFormatters: const [
|
||||
Utf8LengthLimitingTextInputFormatter(maxRadioNameBytes),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
TextField(
|
||||
@@ -1835,17 +1907,52 @@ class _ChannelsScreenState extends State<ChannelsScreen>
|
||||
);
|
||||
}
|
||||
|
||||
/// Picks a free channel slot at the moment the user commits, or shows why
|
||||
/// none can be used. Slots are only trusted after a complete channel sync:
|
||||
/// while syncing, a slot that hasn't been fetched yet looks empty and
|
||||
/// writing to it would overwrite the channel stored on the radio.
|
||||
int? _resolveFreeChannelSlot(
|
||||
BuildContext context,
|
||||
MeshCoreConnector connector,
|
||||
) {
|
||||
if (connector.isSyncingChannels || !connector.hasLoadedChannels) {
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(context.l10n.channels_waitForSync),
|
||||
);
|
||||
return null;
|
||||
}
|
||||
final index = _findNextAvailableIndex(
|
||||
connector.channels,
|
||||
connector.maxChannels,
|
||||
connector.unconfirmedChannelSlots,
|
||||
);
|
||||
if (index == null) {
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(context.l10n.channels_noFreeSlots),
|
||||
);
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
void _addPublicChannel(BuildContext context, MeshCoreConnector connector) {
|
||||
final index = _resolveFreeChannelSlot(context, connector);
|
||||
if (index == null) return;
|
||||
final psk = Channel.parsePskHex(Channel.publicChannelPsk);
|
||||
connector.setChannel(0, context.l10n.channels_public, psk);
|
||||
connector.setChannel(index, context.l10n.channels_public, psk);
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(context.l10n.channels_publicChannelAdded),
|
||||
);
|
||||
}
|
||||
|
||||
int? _findNextAvailableIndex(List<Channel> channels, int maxChannels) {
|
||||
final usedIndices = channels.map((c) => c.index).toSet();
|
||||
int? _findNextAvailableIndex(
|
||||
List<Channel> channels,
|
||||
int maxChannels,
|
||||
Set<int> unconfirmedSlots,
|
||||
) {
|
||||
final usedIndices = {...channels.map((c) => c.index), ...unconfirmedSlots};
|
||||
for (int i = 0; i < maxChannels; i++) {
|
||||
if (!usedIndices.contains(i)) return i;
|
||||
}
|
||||
|
||||
@@ -47,6 +47,7 @@ import '../l10n/l10n.dart';
|
||||
import '../helpers/snack_bar_builder.dart';
|
||||
import '../widgets/unread_divider.dart';
|
||||
import '../theme/mesh_theme.dart';
|
||||
import '../widgets/future_timestamp_indicator.dart';
|
||||
import '../widgets/mesh_ui.dart';
|
||||
import 'telemetry_screen.dart';
|
||||
|
||||
@@ -82,6 +83,9 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
Message? _pendingUnreadScrollTarget;
|
||||
String? _unreadDividerMessageId;
|
||||
DateTime? _lastTextSendAt;
|
||||
// True while a send is awaiting outgoing translation, so a second tap
|
||||
// can't send the same text again.
|
||||
bool _isSendingText = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -435,14 +439,15 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
final startsDay =
|
||||
messageIndex == reversedMessages.length - 1 ||
|
||||
!isSameChatDay(
|
||||
reversedMessages[messageIndex + 1].timestamp,
|
||||
message.timestamp,
|
||||
reversedMessages[messageIndex + 1].receivedAt,
|
||||
message.receivedAt,
|
||||
);
|
||||
final child = isUnreadAnchor || startsDay
|
||||
? Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
if (startsDay) ChatDaySeparator(day: message.timestamp),
|
||||
if (startsDay)
|
||||
ChatDaySeparator(day: message.receivedAt),
|
||||
if (isUnreadAnchor) const UnreadDivider(),
|
||||
bubble,
|
||||
],
|
||||
@@ -663,6 +668,16 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
}
|
||||
|
||||
Future<void> _sendMessage(MeshCoreConnector connector) async {
|
||||
if (_isSendingText) return;
|
||||
_isSendingText = true;
|
||||
try {
|
||||
await _sendMessageInner(connector);
|
||||
} finally {
|
||||
_isSendingText = false;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _sendMessageInner(MeshCoreConnector connector) async {
|
||||
final text = _textController.text.trim();
|
||||
if (text.isEmpty) return;
|
||||
|
||||
@@ -731,7 +746,10 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
}
|
||||
// end transform
|
||||
|
||||
_textController.clear();
|
||||
// Keep anything the user typed while translation was running.
|
||||
if (_textController.text.trim() == text) {
|
||||
_textController.clear();
|
||||
}
|
||||
_textFieldFocusNode.requestFocus();
|
||||
connector.sendMessage(
|
||||
_resolveContact(connector),
|
||||
@@ -1644,6 +1662,10 @@ class _MessageBubble extends StatelessWidget {
|
||||
color: metaColor,
|
||||
),
|
||||
),
|
||||
if (message.hasFutureTimestamp)
|
||||
FutureTimestampIndicator(
|
||||
size: 16 * textScale,
|
||||
),
|
||||
if (isOutgoing) ...[
|
||||
const SizedBox(width: 2),
|
||||
MessageStatusIcon(
|
||||
|
||||
@@ -6,6 +6,7 @@ import 'package:uuid/uuid.dart';
|
||||
|
||||
import '../connector/meshcore_connector.dart';
|
||||
import '../helpers/snack_bar_builder.dart';
|
||||
import '../helpers/utf8_length_limiter.dart';
|
||||
import '../l10n/l10n.dart';
|
||||
import '../models/community.dart';
|
||||
import '../storage/community_store.dart';
|
||||
@@ -369,15 +370,33 @@ class _CommunityQrScannerScreenState extends State<CommunityQrScannerScreen> {
|
||||
_communityStore.setPublicKeyHex = connector.selfPublicKeyHex;
|
||||
await _communityStore.addCommunity(community);
|
||||
|
||||
// Optionally add the community public channel to the device
|
||||
// Optionally add the community public channel to the device. Only trust
|
||||
// free slots after a complete channel sync; mid-sync, unfetched slots
|
||||
// look empty and writing one would overwrite an existing channel.
|
||||
if (addPublicChannel && context.mounted) {
|
||||
final connector = context.read<MeshCoreConnector>();
|
||||
final nextIndex = _findNextAvailableChannelIndex(connector);
|
||||
final slotsKnown =
|
||||
connector.hasLoadedChannels && !connector.isSyncingChannels;
|
||||
final nextIndex = slotsKnown
|
||||
? _findNextAvailableChannelIndex(connector)
|
||||
: null;
|
||||
|
||||
if (nextIndex != null) {
|
||||
final psk = community.deriveCommunityPublicPsk();
|
||||
final channelName = '${community.name} Public';
|
||||
final channelName = fitRadioName(
|
||||
community.name,
|
||||
context.l10n.channels_public,
|
||||
);
|
||||
connector.setChannel(nextIndex, channelName, psk);
|
||||
} else {
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(
|
||||
slotsKnown
|
||||
? context.l10n.channels_noFreeSlots
|
||||
: context.l10n.channels_waitForSync,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -394,7 +413,10 @@ class _CommunityQrScannerScreenState extends State<CommunityQrScannerScreen> {
|
||||
}
|
||||
|
||||
int? _findNextAvailableChannelIndex(MeshCoreConnector connector) {
|
||||
final usedIndices = connector.channels.map((c) => c.index).toSet();
|
||||
final usedIndices = {
|
||||
...connector.channels.map((c) => c.index),
|
||||
...connector.unconfirmedChannelSlots,
|
||||
};
|
||||
for (int i = 0; i < connector.maxChannels; i++) {
|
||||
if (!usedIndices.contains(i)) return i;
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import '../utils/platform_info.dart';
|
||||
import '../widgets/app_bar.dart';
|
||||
import '../widgets/list_filter_widget.dart';
|
||||
import '../widgets/mesh_ui.dart';
|
||||
import '../widgets/node_scan_sheet.dart';
|
||||
import '../helpers/snack_bar_builder.dart';
|
||||
|
||||
enum DiscoverySortOption { lastSeen, name, type }
|
||||
@@ -105,6 +106,12 @@ class _DiscoveryScreenState extends State<DiscoveryScreen> {
|
||||
),
|
||||
centerTitle: true,
|
||||
actions: [
|
||||
if (connector.isConnected && connector.supportsNodeDiscover)
|
||||
IconButton(
|
||||
tooltip: l10n.discoveredContacts_scan,
|
||||
icon: const Icon(Icons.radar),
|
||||
onPressed: () => showNodeScanSheet(context, connector),
|
||||
),
|
||||
PopupMenuButton(
|
||||
itemBuilder: (context) => [
|
||||
PopupMenuItem(
|
||||
|
||||
@@ -650,7 +650,7 @@ class _LineOfSightMapScreenState extends State<LineOfSightMapScreen> {
|
||||
? LosPalette.selected
|
||||
: LosPalette.textMuted,
|
||||
icon: const Icon(Icons.layers_outlined),
|
||||
tooltip: 'Map detail',
|
||||
tooltip: context.l10n.losMapDetailTooltip,
|
||||
onPressed: () =>
|
||||
setState(() => _showTerrainLayer = !_showTerrainLayer),
|
||||
),
|
||||
@@ -664,7 +664,7 @@ class _LineOfSightMapScreenState extends State<LineOfSightMapScreen> {
|
||||
fontWeight: FontWeight.w800,
|
||||
),
|
||||
),
|
||||
tooltip: 'Units',
|
||||
tooltip: context.l10n.losUnitsTooltip,
|
||||
onPressed: () => context.read<AppSettingsService>().setUnitSystem(
|
||||
isImperial ? UnitSystem.metric : UnitSystem.imperial,
|
||||
),
|
||||
@@ -736,21 +736,25 @@ class _LineOfSightMapScreenState extends State<LineOfSightMapScreen> {
|
||||
Row(
|
||||
children: [
|
||||
_summaryMetric(
|
||||
'Distance',
|
||||
context.l10n.losDistance,
|
||||
segment == null
|
||||
? '--'
|
||||
: '${_formatDistanceValue(segment.totalDistanceMeters, isImperial)} $distanceUnit',
|
||||
),
|
||||
_summaryMetric(
|
||||
segment?.isClear == true ? 'Clearance' : 'Blocked by',
|
||||
segment?.isClear == true
|
||||
? context.l10n.losClearance
|
||||
: context.l10n.losBlockedBy,
|
||||
amount,
|
||||
valueColor: color,
|
||||
),
|
||||
_summaryMetric(
|
||||
'Obstruction',
|
||||
context.l10n.losObstruction,
|
||||
worst == null
|
||||
? '--'
|
||||
: '${_formatDistanceValue(worst.distanceMeters, isImperial)} $distanceUnit from A',
|
||||
: context.l10n.losDistanceFromA(
|
||||
'${_formatDistanceValue(worst.distanceMeters, isImperial)} $distanceUnit',
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -840,18 +844,18 @@ class _LineOfSightMapScreenState extends State<LineOfSightMapScreen> {
|
||||
if (isWorst)
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 5,
|
||||
horizontal: 7,
|
||||
vertical: 2,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: LosPalette.blocked,
|
||||
borderRadius: BorderRadius.circular(99),
|
||||
),
|
||||
child: const Text(
|
||||
'WORST',
|
||||
child: Text(
|
||||
context.l10n.losWorstBadge,
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 8,
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w900,
|
||||
),
|
||||
),
|
||||
@@ -860,7 +864,9 @@ class _LineOfSightMapScreenState extends State<LineOfSightMapScreen> {
|
||||
),
|
||||
const Spacer(),
|
||||
Text(
|
||||
'Blocked ${_formatHeightValue(obstruction.obstructionMeters, isImperial)} $heightUnit',
|
||||
context.l10n.losBlockedAmount(
|
||||
'${_formatHeightValue(obstruction.obstructionMeters, isImperial)} $heightUnit',
|
||||
),
|
||||
style: const TextStyle(
|
||||
color: LosPalette.textMuted,
|
||||
fontSize: 11,
|
||||
@@ -890,9 +896,9 @@ class _LineOfSightMapScreenState extends State<LineOfSightMapScreen> {
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text(
|
||||
'Selected obstruction',
|
||||
style: TextStyle(
|
||||
Text(
|
||||
context.l10n.losSelectedObstructionTitle,
|
||||
style: const TextStyle(
|
||||
color: LosPalette.text,
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w800,
|
||||
@@ -904,19 +910,19 @@ class _LineOfSightMapScreenState extends State<LineOfSightMapScreen> {
|
||||
runSpacing: 10,
|
||||
children: [
|
||||
_detailValue(
|
||||
'Blocked by',
|
||||
context.l10n.losBlockedBy,
|
||||
'${_formatHeightValue(obstruction.obstructionMeters, isImperial)} $heightUnit',
|
||||
),
|
||||
_detailValue(
|
||||
'From A',
|
||||
context.l10n.losFromA,
|
||||
'${_formatDistanceValue(obstruction.distanceMeters, isImperial)} $distanceUnit',
|
||||
),
|
||||
_detailValue(
|
||||
'From B',
|
||||
context.l10n.losFromB,
|
||||
'${_formatDistanceValue(segment.totalDistanceMeters - obstruction.distanceMeters, isImperial)} $distanceUnit',
|
||||
),
|
||||
_detailValue(
|
||||
'Elevation',
|
||||
context.l10n.losElevation,
|
||||
'${_formatHeightValue(obstruction.terrainMeters, isImperial)} $heightUnit',
|
||||
),
|
||||
],
|
||||
@@ -927,7 +933,7 @@ class _LineOfSightMapScreenState extends State<LineOfSightMapScreen> {
|
||||
child: OutlinedButton.icon(
|
||||
onPressed: () => _centerOnObstruction(obstruction),
|
||||
icon: const Icon(Icons.center_focus_strong, size: 17),
|
||||
label: const Text('Center on map'),
|
||||
label: Text(context.l10n.losCenterOnMap),
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -1368,6 +1374,7 @@ class _LineOfSightMapScreenState extends State<LineOfSightMapScreen> {
|
||||
terrainLabel: context.l10n.losLegendTerrain,
|
||||
losBeamLabel: context.l10n.losLegendLosBeam,
|
||||
radioHorizonLabel: context.l10n.losLegendRadioHorizon,
|
||||
selectedLabel: context.l10n.losSelectedPill,
|
||||
selectedSampleIndex: _selectedObstruction?.sampleIndex,
|
||||
),
|
||||
),
|
||||
@@ -1406,6 +1413,7 @@ class _LineOfSightMapScreenState extends State<LineOfSightMapScreen> {
|
||||
terrainLabel: context.l10n.losLegendTerrain,
|
||||
losBeamLabel: context.l10n.losLegendLosBeam,
|
||||
radioHorizonLabel: context.l10n.losLegendRadioHorizon,
|
||||
selectedLabel: context.l10n.losSelectedPill,
|
||||
selectedSampleIndex: _selectedObstruction?.sampleIndex,
|
||||
),
|
||||
),
|
||||
@@ -1675,13 +1683,15 @@ class _LineOfSightMapScreenState extends State<LineOfSightMapScreen> {
|
||||
String _statusLabel(_LosDisplayStatus status) {
|
||||
switch (status) {
|
||||
case _LosDisplayStatus.clear:
|
||||
return 'Clear';
|
||||
return context.l10n.losStatusClear;
|
||||
case _LosDisplayStatus.marginal:
|
||||
return 'Marginal';
|
||||
return context.l10n.losStatusMarginal;
|
||||
case _LosDisplayStatus.blocked:
|
||||
return 'Blocked';
|
||||
return context.l10n.losStatusBlocked;
|
||||
case _LosDisplayStatus.unknown:
|
||||
return _loading ? 'Checking' : 'No result';
|
||||
return _loading
|
||||
? context.l10n.losStatusCheckingShort
|
||||
: context.l10n.losStatusNoResult;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1832,6 +1842,7 @@ class _LosProfilePainter extends CustomPainter {
|
||||
final String terrainLabel;
|
||||
final String losBeamLabel;
|
||||
final String radioHorizonLabel;
|
||||
final String selectedLabel;
|
||||
final int? selectedSampleIndex;
|
||||
|
||||
const _LosProfilePainter({
|
||||
@@ -1842,6 +1853,7 @@ class _LosProfilePainter extends CustomPainter {
|
||||
required this.terrainLabel,
|
||||
required this.losBeamLabel,
|
||||
required this.radioHorizonLabel,
|
||||
required this.selectedLabel,
|
||||
this.selectedSampleIndex,
|
||||
});
|
||||
|
||||
@@ -2128,7 +2140,7 @@ class _LosProfilePainter extends CustomPainter {
|
||||
final labelY = math.max(topPadding + 2, selectedPoint.dy - 27);
|
||||
_paintPill(
|
||||
canvas,
|
||||
'Selected',
|
||||
selectedLabel,
|
||||
Offset(
|
||||
selectedPoint.dx.clamp(42.0, size.width - 42).toDouble(),
|
||||
labelY,
|
||||
@@ -2216,6 +2228,7 @@ class _LosProfilePainter extends CustomPainter {
|
||||
oldDelegate.terrainLabel != terrainLabel ||
|
||||
oldDelegate.losBeamLabel != losBeamLabel ||
|
||||
oldDelegate.radioHorizonLabel != radioHorizonLabel ||
|
||||
oldDelegate.selectedLabel != selectedLabel ||
|
||||
oldDelegate.selectedSampleIndex != selectedSampleIndex;
|
||||
}
|
||||
|
||||
@@ -2259,7 +2272,7 @@ class _LosLegend extends StatelessWidget {
|
||||
_LegendEntry(terrainLabel, LosPalette.terrain),
|
||||
_LegendEntry(losBeamLabel, LosPalette.beam),
|
||||
_LegendEntry(radioHorizonLabel, LosPalette.horizon),
|
||||
const _LegendEntry('Blocked', LosPalette.blocked),
|
||||
_LegendEntry(context.l10n.losStatusBlocked, LosPalette.blocked),
|
||||
];
|
||||
|
||||
const swatchSize = 12.0;
|
||||
|
||||
@@ -139,6 +139,7 @@ class _MapCacheScreenState extends State<MapCacheScreen> {
|
||||
}
|
||||
|
||||
void _updateEstimate() {
|
||||
if (!mounted) return;
|
||||
if (_selectedBounds == null) {
|
||||
setState(() {
|
||||
_estimatedTiles = 0;
|
||||
|
||||
@@ -40,6 +40,7 @@ import '../widgets/repeater_login_dialog.dart';
|
||||
import '../widgets/room_login_dialog.dart';
|
||||
import '../helpers/guessed_location_estimator.dart';
|
||||
import '../helpers/snack_bar_builder.dart';
|
||||
import '../helpers/utf8_length_limiter.dart';
|
||||
import 'repeater_hub_screen.dart';
|
||||
import 'settings_screen.dart';
|
||||
import 'line_of_sight_map_screen.dart';
|
||||
@@ -2639,7 +2640,7 @@ class _MapScreenState extends State<MapScreen> with DisconnectNavigationMixin {
|
||||
flags: payload.flags,
|
||||
fromName: message.senderName,
|
||||
sourceLabel: channel.name.isEmpty
|
||||
? 'Channel ${channel.index}'
|
||||
? context.l10n.channels_channelIndex(channel.index)
|
||||
: channel.name,
|
||||
timestamp: message.timestamp,
|
||||
isChannel: true,
|
||||
@@ -3119,7 +3120,22 @@ class _MapScreenState extends State<MapScreen> with DisconnectNavigationMixin {
|
||||
return;
|
||||
}
|
||||
|
||||
final label = await _promptForLabel(context, defaultLabel);
|
||||
// The whole `m:lat,lon|label|flags` text must fit in one message to
|
||||
// either a contact or a channel, so the label gets what's left.
|
||||
final maxMessageBytes = min(
|
||||
maxContactMessageBytes(),
|
||||
maxChannelMessageBytes(connector.selfName),
|
||||
);
|
||||
final label = await _promptForLabel(
|
||||
context,
|
||||
defaultLabel,
|
||||
maxBytes: maxMessageBytes,
|
||||
encode: (text) => _formatMarkerMessage(
|
||||
position,
|
||||
text.trim().replaceAll('|', '/'),
|
||||
flags,
|
||||
),
|
||||
);
|
||||
if (label == null || !mounted) return;
|
||||
|
||||
final markerText = _formatMarkerMessage(position, label, flags);
|
||||
@@ -3135,9 +3151,13 @@ class _MapScreenState extends State<MapScreen> with DisconnectNavigationMixin {
|
||||
|
||||
Future<String?> _promptForLabel(
|
||||
BuildContext context,
|
||||
String defaultLabel,
|
||||
) async {
|
||||
final controller = TextEditingController(text: defaultLabel);
|
||||
String defaultLabel, {
|
||||
required int maxBytes,
|
||||
required String Function(String label) encode,
|
||||
}) async {
|
||||
final fixedBytes = utf8ByteLength(encode(''));
|
||||
final fittedDefault = truncateUtf8(defaultLabel, maxBytes - fixedBytes);
|
||||
final controller = TextEditingController(text: fittedDefault);
|
||||
controller.selection = TextSelection(
|
||||
baseOffset: 0,
|
||||
extentOffset: controller.text.length,
|
||||
@@ -3152,6 +3172,9 @@ class _MapScreenState extends State<MapScreen> with DisconnectNavigationMixin {
|
||||
hintText: context.l10n.map_label,
|
||||
border: const OutlineInputBorder(),
|
||||
),
|
||||
inputFormatters: [
|
||||
Utf8LengthLimitingTextInputFormatter(maxBytes, encoder: encode),
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
@@ -3163,7 +3186,7 @@ class _MapScreenState extends State<MapScreen> with DisconnectNavigationMixin {
|
||||
final label = controller.text.trim().replaceAll('|', '/');
|
||||
Navigator.pop(
|
||||
dialogContext,
|
||||
label.isEmpty ? defaultLabel : label,
|
||||
label.isEmpty ? fittedDefault : label,
|
||||
);
|
||||
},
|
||||
child: Text(context.l10n.common_continue),
|
||||
@@ -3173,6 +3196,15 @@ class _MapScreenState extends State<MapScreen> with DisconnectNavigationMixin {
|
||||
);
|
||||
}
|
||||
|
||||
bool _markerFits(BuildContext context, String markerText, int maxBytes) {
|
||||
if (utf8ByteLength(markerText) <= maxBytes) return true;
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(context.l10n.chat_messageTooLong(maxBytes)),
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
String _formatMarkerMessage(LatLng position, String label, String flags) {
|
||||
final lat = position.latitude.toStringAsFixed(6);
|
||||
final lon = position.longitude.toStringAsFixed(6);
|
||||
@@ -3249,6 +3281,13 @@ class _MapScreenState extends State<MapScreen> with DisconnectNavigationMixin {
|
||||
title: Text(contact.name),
|
||||
onTap: () {
|
||||
Navigator.pop(sheetContext);
|
||||
if (!_markerFits(
|
||||
context,
|
||||
markerText,
|
||||
maxContactMessageBytes(),
|
||||
)) {
|
||||
return;
|
||||
}
|
||||
liveConnector.sendMessage(contact, markerText);
|
||||
},
|
||||
);
|
||||
@@ -3284,7 +3323,9 @@ class _MapScreenState extends State<MapScreen> with DisconnectNavigationMixin {
|
||||
) {
|
||||
final isPublic = _isPublicChannel(channel);
|
||||
final label = channel.name.isEmpty
|
||||
? 'Channel ${channel.index}'
|
||||
? context.l10n.channels_channelIndex(
|
||||
channel.index,
|
||||
)
|
||||
: channel.name;
|
||||
return ListTile(
|
||||
leading: Icon(
|
||||
@@ -3299,7 +3340,15 @@ class _MapScreenState extends State<MapScreen> with DisconnectNavigationMixin {
|
||||
final canSend = isPublic
|
||||
? await _confirmPublicShare(context, label)
|
||||
: true;
|
||||
if (canSend) {
|
||||
if (canSend &&
|
||||
context.mounted &&
|
||||
_markerFits(
|
||||
context,
|
||||
markerText,
|
||||
maxChannelMessageBytes(
|
||||
liveConnector.selfName,
|
||||
),
|
||||
)) {
|
||||
liveConnector.sendChannelMessage(
|
||||
channel,
|
||||
markerText,
|
||||
|
||||
@@ -110,6 +110,9 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen>
|
||||
bool _showNodeLabels = true;
|
||||
Contact? _targetContact;
|
||||
Uint8List? _sentTagBytes;
|
||||
// Tag the radio reported in RESP_CODE_SENT for the current trace; reset
|
||||
// on every new trace so a late reply to an earlier one isn't accepted.
|
||||
Uint8List? _sentAckTag;
|
||||
// Live path resolved at trace time; used by the response handler for
|
||||
// endpoint inference so it matches the path that was actually traced.
|
||||
Uint8List _tracedPath = Uint8List(0);
|
||||
@@ -449,6 +452,7 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen>
|
||||
);
|
||||
|
||||
final sentTag = DateTime.now().millisecondsSinceEpoch ~/ 1000;
|
||||
_sentAckTag = null;
|
||||
_sentTagBytes = Uint8List(4)
|
||||
..[0] = sentTag & 0xFF
|
||||
..[1] = (sentTag >> 8) & 0xFF
|
||||
@@ -470,7 +474,6 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen>
|
||||
|
||||
void _setupFrameListener() {
|
||||
final connector = Provider.of<MeshCoreConnector>(context, listen: false);
|
||||
Uint8List tagData = Uint8List(4);
|
||||
// Listen for incoming text messages from the repeater
|
||||
_frameSubscription = connector.receivedFrames.listen((frame) {
|
||||
if (frame.isEmpty) return;
|
||||
@@ -481,7 +484,7 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen>
|
||||
if (code == respCodeSent && _awaitingTraceSent) {
|
||||
_awaitingTraceSent = false;
|
||||
frameBuffer.skipBytes(1); //reserved
|
||||
tagData = frameBuffer.readBytes(4);
|
||||
_sentAckTag = frameBuffer.readBytes(4);
|
||||
final timeoutMilliseconds = frameBuffer.readUInt32LE();
|
||||
|
||||
// Start timeout timer for trace response
|
||||
@@ -512,7 +515,7 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen>
|
||||
if (frame.length >= 12 &&
|
||||
code == pushCodeTraceData &&
|
||||
(listEquals(frame.sublist(4, 8), _sentTagBytes) ||
|
||||
listEquals(frame.sublist(4, 8), tagData))) {
|
||||
listEquals(frame.sublist(4, 8), _sentAckTag))) {
|
||||
_timeoutTimer?.cancel();
|
||||
if (!mounted) return;
|
||||
_handleTraceResponse(frame);
|
||||
|
||||
@@ -5,6 +5,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:meshcore_open/connector/meshcore_connector.dart';
|
||||
import 'package:meshcore_open/connector/meshcore_protocol.dart';
|
||||
import 'package:meshcore_open/helpers/snack_bar_builder.dart';
|
||||
import 'package:meshcore_open/l10n/l10n.dart';
|
||||
import 'package:meshcore_open/models/contact.dart';
|
||||
import 'package:meshcore_open/storage/region_store.dart';
|
||||
@@ -89,7 +90,15 @@ class _RegionManagementScreenState extends State<RegionManagementScreen> {
|
||||
),
|
||||
itemCount: _regions.length + 1,
|
||||
itemBuilder: (context, index) {
|
||||
if (index == 0) return _buildDefaultRegionTile(context);
|
||||
if (index == 0) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
_buildDefaultRegionTile(context),
|
||||
_buildRadioDefaultRegionTile(context),
|
||||
],
|
||||
);
|
||||
}
|
||||
return _buildRegionTile(context, _regions[index - 1]);
|
||||
},
|
||||
),
|
||||
@@ -99,11 +108,16 @@ class _RegionManagementScreenState extends State<RegionManagementScreen> {
|
||||
Widget _buildEmptyState(BuildContext context) {
|
||||
final l10n = context.l10n;
|
||||
return Center(
|
||||
child: Padding(
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
// The radio may hold a default region set by firmware or another
|
||||
// client even when this app's list is empty; keep it clearable.
|
||||
_buildRadioDefaultRegionTile(context),
|
||||
const SizedBox(height: 16),
|
||||
const Icon(Icons.landscape, size: 48, color: MeshPalette.blue),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
@@ -132,9 +146,16 @@ class _RegionManagementScreenState extends State<RegionManagementScreen> {
|
||||
Widget _buildDefaultRegionTile(BuildContext context) {
|
||||
final l10n = context.l10n;
|
||||
final connector = context.watch<MeshCoreConnector>();
|
||||
final current = _regions.contains(connector.defaultRegion)
|
||||
? connector.defaultRegion
|
||||
final canForceUnscoped = connector.supportsExplicitUnscopedFlood;
|
||||
final appDefault = connector.defaultRegion;
|
||||
final current =
|
||||
_regions.contains(appDefault) ||
|
||||
(appDefault == kUnscopedRegion && canForceUnscoped)
|
||||
? appDefault
|
||||
: '';
|
||||
final radioDefault = connector.supportsDefaultFloodScope
|
||||
? connector.defaultFloodScopeName
|
||||
: null;
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 8),
|
||||
child: DropdownButtonFormField<Region>(
|
||||
@@ -148,8 +169,17 @@ class _RegionManagementScreenState extends State<RegionManagementScreen> {
|
||||
items: [
|
||||
DropdownMenuItem(
|
||||
value: '',
|
||||
child: Text(l10n.settings_regionDefaultNone),
|
||||
child: Text(
|
||||
radioDefault == null
|
||||
? l10n.settings_regionDefaultNone
|
||||
: l10n.settings_regionUseRadioDefault(radioDefault),
|
||||
),
|
||||
),
|
||||
if (canForceUnscoped)
|
||||
DropdownMenuItem(
|
||||
value: kUnscopedRegion,
|
||||
child: Text(l10n.settings_regionNoRegion),
|
||||
),
|
||||
for (final region in _regions)
|
||||
DropdownMenuItem(value: region, child: Text(region)),
|
||||
],
|
||||
@@ -158,6 +188,63 @@ class _RegionManagementScreenState extends State<RegionManagementScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
/// The radio's own default flood scope (firmware ver 11+). Hidden on older
|
||||
/// firmware, which has no such setting.
|
||||
Widget _buildRadioDefaultRegionTile(BuildContext context) {
|
||||
final l10n = context.l10n;
|
||||
final connector = context.watch<MeshCoreConnector>();
|
||||
if (!connector.supportsDefaultFloodScope) return const SizedBox.shrink();
|
||||
final radioDefault = connector.defaultFloodScopeName ?? '';
|
||||
final options = <Region>[
|
||||
..._regions,
|
||||
if (radioDefault.isNotEmpty && !_regions.contains(radioDefault))
|
||||
radioDefault,
|
||||
];
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(top: 8, bottom: 8),
|
||||
child: DropdownButtonFormField<Region>(
|
||||
key: ValueKey('radio-default-$radioDefault'),
|
||||
initialValue: radioDefault,
|
||||
decoration: InputDecoration(
|
||||
labelText: l10n.settings_regionRadioDefault,
|
||||
helperText: l10n.settings_regionRadioDefaultSubtitle,
|
||||
helperMaxLines: 3,
|
||||
border: const OutlineInputBorder(),
|
||||
),
|
||||
items: [
|
||||
DropdownMenuItem(
|
||||
value: '',
|
||||
child: Text(l10n.settings_regionDefaultNone),
|
||||
),
|
||||
for (final region in options)
|
||||
DropdownMenuItem(value: region, child: Text(region)),
|
||||
],
|
||||
onChanged: (value) => _setRadioDefaultRegion(connector, value ?? ''),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _setRadioDefaultRegion(
|
||||
MeshCoreConnector connector,
|
||||
Region region,
|
||||
) async {
|
||||
final l10n = context.l10n;
|
||||
try {
|
||||
await connector.setDefaultFloodScope(region);
|
||||
if (!mounted) return;
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(l10n.settings_regionRadioDefaultUpdated),
|
||||
);
|
||||
} catch (_) {
|
||||
if (!mounted) return;
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(l10n.settings_regionRadioDefaultFailed),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void _showAddRegionDialog(BuildContext context) {
|
||||
final l10n = context.l10n;
|
||||
final controller = TextEditingController();
|
||||
|
||||
@@ -127,6 +127,18 @@ class _RepeaterCliScreenState extends State<RepeaterCliScreen> {
|
||||
'text': command,
|
||||
'timestamp': DateTime.now().toString(),
|
||||
});
|
||||
// The repeater enters load mode as soon as it receives the command, and
|
||||
// its reply may take a full timeout (or be lost). Switch modes now so
|
||||
// lines typed meanwhile go out verbatim instead of as `XX|` commands; a
|
||||
// blank line always ends it safely.
|
||||
if (startsRegionLoad) {
|
||||
_regionLoadActive = true;
|
||||
_commandHistory.add({
|
||||
'type': 'response',
|
||||
'text': context.l10n.repeater_cliRegionLoadActive,
|
||||
'timestamp': DateTime.now().toString(),
|
||||
});
|
||||
}
|
||||
});
|
||||
_commandController.clear();
|
||||
_historyIndex = -1;
|
||||
@@ -178,19 +190,6 @@ class _RepeaterCliScreenState extends State<RepeaterCliScreen> {
|
||||
}
|
||||
}
|
||||
|
||||
// The reply to `region load` may be lost even though the repeater entered
|
||||
// load mode, so enter it regardless; a blank line always ends it safely.
|
||||
if (startsRegionLoad && mounted) {
|
||||
setState(() {
|
||||
_regionLoadActive = true;
|
||||
_commandHistory.add({
|
||||
'type': 'response',
|
||||
'text': context.l10n.repeater_cliRegionLoadActive,
|
||||
'timestamp': DateTime.now().toString(),
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
_scrollToBottom();
|
||||
}
|
||||
|
||||
|
||||
@@ -92,6 +92,7 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
bool _isLoading = false;
|
||||
bool _hasChanges = false;
|
||||
final Set<_SettingField> _dirtyFields = {};
|
||||
final Set<_SettingField> _editedDuringSave = {};
|
||||
bool _refreshingBasic = false;
|
||||
bool _refreshingRadio = false;
|
||||
bool _refreshingTxPower = false;
|
||||
@@ -826,6 +827,61 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
retainDirty.add(field);
|
||||
}
|
||||
|
||||
// Fields whose edits this save attempts. Anything edited while the
|
||||
// commands are in flight stays dirty afterwards (see _markChanged).
|
||||
final savingFields = Set<_SettingField>.of(_dirtyFields);
|
||||
_editedDuringSave.clear();
|
||||
|
||||
// A changed text field that was emptied has nothing to send; report it
|
||||
// instead of silently skipping it and claiming the save succeeded.
|
||||
void requireText(
|
||||
_SettingField field,
|
||||
TextEditingController controller,
|
||||
String label,
|
||||
) {
|
||||
if (_dirtyFields.contains(field) && controller.text.trim().isEmpty) {
|
||||
reject(field, l10n.repeater_valueRequired(label));
|
||||
}
|
||||
}
|
||||
|
||||
requireText(
|
||||
_SettingField.name,
|
||||
_nameController,
|
||||
l10n.repeater_repeaterName,
|
||||
);
|
||||
requireText(
|
||||
_SettingField.radio,
|
||||
_freqController,
|
||||
l10n.repeater_frequencyMhz,
|
||||
);
|
||||
requireText(
|
||||
_SettingField.txPower,
|
||||
_txPowerController,
|
||||
l10n.repeater_txPower,
|
||||
);
|
||||
requireText(_SettingField.lat, _latController, l10n.repeater_latitude);
|
||||
requireText(_SettingField.lon, _lonController, l10n.repeater_longitude);
|
||||
requireText(
|
||||
_SettingField.prvKey,
|
||||
_prvKeyController,
|
||||
l10n.repeater_prvKey,
|
||||
);
|
||||
requireText(
|
||||
_SettingField.txDelay,
|
||||
_txDelayController,
|
||||
l10n.repeater_txDelay,
|
||||
);
|
||||
requireText(
|
||||
_SettingField.directTxDelay,
|
||||
_directTxDelayController,
|
||||
l10n.repeater_directTxDelay,
|
||||
);
|
||||
requireText(
|
||||
_SettingField.intThresh,
|
||||
_intThreshController,
|
||||
l10n.repeater_intThresh,
|
||||
);
|
||||
|
||||
if (_dirtyFields.contains(_SettingField.name) &&
|
||||
_nameController.text.isNotEmpty) {
|
||||
pending.add((
|
||||
@@ -1098,9 +1154,13 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
}
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
// Only drop fields that were actually sent successfully; keep failed
|
||||
// ones and anything edited while the save was running.
|
||||
_dirtyFields
|
||||
..clear()
|
||||
..addAll(retainDirty);
|
||||
..removeAll(savingFields)
|
||||
..addAll(retainDirty)
|
||||
..addAll(_editedDuringSave);
|
||||
_editedDuringSave.clear();
|
||||
_hasChanges = _dirtyFields.isNotEmpty || passwordsFailed;
|
||||
});
|
||||
|
||||
@@ -1144,6 +1204,7 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
|
||||
void _markChanged(_SettingField field) {
|
||||
_dirtyFields.add(field);
|
||||
if (_isLoading) _editedDuringSave.add(field);
|
||||
_flagHasChanges();
|
||||
}
|
||||
|
||||
|
||||
@@ -46,7 +46,10 @@ class _ScannerScreenState extends State<ScannerScreen> {
|
||||
if (_connector.state == MeshCoreConnectionState.disconnected) {
|
||||
_changedNavigation = false;
|
||||
} else if (_connector.state == MeshCoreConnectionState.connected &&
|
||||
_connector.activeTransport == MeshCoreTransportType.bluetooth &&
|
||||
// TCP lands here after an auto-reconnect: a dropped link popped
|
||||
// back to this screen, and the TCP screen is no longer on the stack.
|
||||
(_connector.activeTransport == MeshCoreTransportType.bluetooth ||
|
||||
_connector.activeTransport == MeshCoreTransportType.tcp) &&
|
||||
isCurrentRoute &&
|
||||
!_changedNavigation) {
|
||||
_changedNavigation = true;
|
||||
|
||||
@@ -15,6 +15,7 @@ import '../services/app_debug_log_service.dart';
|
||||
import '../theme/mesh_theme.dart';
|
||||
import '../widgets/app_bar.dart';
|
||||
import '../helpers/snack_bar_builder.dart';
|
||||
import '../helpers/utf8_length_limiter.dart';
|
||||
import '../widgets/mesh_ui.dart';
|
||||
import 'app_settings_screen.dart';
|
||||
import 'app_debug_log_screen.dart';
|
||||
@@ -796,6 +797,9 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
|
||||
void _editNodeName(BuildContext context, MeshCoreConnector connector) {
|
||||
final l10n = context.l10n;
|
||||
// The dialog's own context is gone after it pops, so report back
|
||||
// through the screen's context.
|
||||
final screenContext = context;
|
||||
final controller = TextEditingController(text: connector.selfName ?? '');
|
||||
showDialog(
|
||||
context: context,
|
||||
@@ -807,7 +811,9 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
hintText: l10n.settings_nodeNameHint,
|
||||
border: const OutlineInputBorder(),
|
||||
),
|
||||
maxLength: 31,
|
||||
inputFormatters: const [
|
||||
Utf8LengthLimitingTextInputFormatter(maxRadioNameBytes),
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
@@ -825,9 +831,9 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
Navigator.pop(context);
|
||||
await connector.setNodeName(name);
|
||||
await connector.refreshDeviceInfo();
|
||||
if (!context.mounted) return;
|
||||
if (!screenContext.mounted) return;
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
screenContext,
|
||||
content: Text(l10n.settings_nodeNameUpdated),
|
||||
);
|
||||
},
|
||||
@@ -936,7 +942,8 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
// Safe access to custom vars - may be null before device responds
|
||||
final customVars = connector.currentCustomVars ?? {};
|
||||
final bool hasGPS = customVars.containsKey("gps");
|
||||
bool isGPSEnabled = customVars["gps"] == "1";
|
||||
final bool initialGPSEnabled = customVars["gps"] == "1";
|
||||
bool isGPSEnabled = initialGPSEnabled;
|
||||
|
||||
final currentInterval = settingsService.resolvedGpsIntervalSeconds(
|
||||
customVars,
|
||||
@@ -944,6 +951,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
intervalController.text = currentInterval.toString();
|
||||
|
||||
String? intervalError;
|
||||
String? locationError;
|
||||
|
||||
showDialog(
|
||||
context: context,
|
||||
@@ -967,9 +975,16 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
const SizedBox(height: 16),
|
||||
TextField(
|
||||
controller: lonController,
|
||||
onChanged: (_) {
|
||||
if (locationError != null) {
|
||||
setDialogState(() => locationError = null);
|
||||
}
|
||||
},
|
||||
decoration: InputDecoration(
|
||||
labelText: l10n.settings_longitude,
|
||||
border: const OutlineInputBorder(),
|
||||
errorText: locationError,
|
||||
errorMaxLines: 2,
|
||||
),
|
||||
keyboardType: const TextInputType.numberWithOptions(
|
||||
decimal: true,
|
||||
@@ -1000,14 +1015,9 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
title: l10n.settings_locationGPSEnable,
|
||||
subtitle: l10n.settings_locationGPSEnableSubtitle,
|
||||
value: isGPSEnabled,
|
||||
onChanged: (value) async {
|
||||
setDialogState(() => isGPSEnabled = value);
|
||||
if (value) {
|
||||
await connector.setCustomVar("gps:1");
|
||||
} else {
|
||||
await connector.setCustomVar("gps:0");
|
||||
}
|
||||
},
|
||||
// Applied on Save so Cancel leaves the device untouched.
|
||||
onChanged: (value) =>
|
||||
setDialogState(() => isGPSEnabled = value),
|
||||
),
|
||||
],
|
||||
],
|
||||
@@ -1019,6 +1029,8 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
// Validate every field before closing so a typo doesn't
|
||||
// discard the input or leave half the changes applied.
|
||||
int? interval;
|
||||
if (hasGPS) {
|
||||
final intervalText = intervalController.text.trim();
|
||||
@@ -1035,54 +1047,53 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
}
|
||||
}
|
||||
|
||||
final latText = latController.text.trim();
|
||||
final lonText = lonController.text.trim();
|
||||
double? lat;
|
||||
double? lon;
|
||||
if (latText.isNotEmpty || lonText.isNotEmpty) {
|
||||
lat = latText.isNotEmpty
|
||||
? double.tryParse(latText)
|
||||
: connector.selfLatitude;
|
||||
lon = lonText.isNotEmpty
|
||||
? double.tryParse(lonText)
|
||||
: connector.selfLongitude;
|
||||
if (lat == null || lon == null) {
|
||||
setDialogState(() {
|
||||
locationError = l10n.settings_locationBothRequired;
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (lat < -90 || lat > 90 || lon < -180 || lon > 180) {
|
||||
setDialogState(() {
|
||||
locationError = l10n.settings_locationInvalid;
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Navigator.pop(dialogContext);
|
||||
|
||||
var changed = false;
|
||||
if (hasGPS && isGPSEnabled != initialGPSEnabled) {
|
||||
await connector.setCustomVar(
|
||||
isGPSEnabled ? "gps:1" : "gps:0",
|
||||
);
|
||||
changed = true;
|
||||
}
|
||||
if (interval != null) {
|
||||
await settingsService.setGpsIntervalSeconds(
|
||||
interval,
|
||||
writeToDevice: (value) =>
|
||||
connector.setCustomVar("gps_interval:$value"),
|
||||
);
|
||||
await connector.refreshDeviceInfo();
|
||||
if (!context.mounted) return;
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(l10n.settings_locationUpdated),
|
||||
);
|
||||
changed = true;
|
||||
}
|
||||
|
||||
final latText = latController.text.trim();
|
||||
final lonText = lonController.text.trim();
|
||||
if (latText.isEmpty && lonText.isEmpty) {
|
||||
return;
|
||||
if (lat != null && lon != null) {
|
||||
await connector.setNodeLocation(lat: lat, lon: lon);
|
||||
changed = true;
|
||||
}
|
||||
|
||||
final currentLat = connector.selfLatitude;
|
||||
final currentLon = connector.selfLongitude;
|
||||
final lat = latText.isNotEmpty
|
||||
? double.tryParse(latText)
|
||||
: currentLat;
|
||||
final lon = lonText.isNotEmpty
|
||||
? double.tryParse(lonText)
|
||||
: currentLon;
|
||||
if (lat == null || lon == null) {
|
||||
if (!context.mounted) return;
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(l10n.settings_locationBothRequired),
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (lat < -90 || lat > 90 || lon < -180 || lon > 180) {
|
||||
if (!context.mounted) return;
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(l10n.settings_locationInvalid),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
await connector.setNodeLocation(lat: lat, lon: lon);
|
||||
if (!changed) return;
|
||||
await connector.refreshDeviceInfo();
|
||||
if (!context.mounted) return;
|
||||
showDismissibleSnackBar(
|
||||
|
||||
Reference in new issue
Block a user