Merge branch 'dev' into ez_disable_discoveredContact_eviction_PR
This commit is contained in:
195 files changed
+26503
-6523
No files matched your search
@@ -9,11 +9,13 @@ import '../models/app_settings.dart';
|
||||
import '../models/image_codec_support.dart';
|
||||
import '../models/translation_support.dart';
|
||||
import '../services/app_settings_service.dart';
|
||||
import '../services/background_service.dart';
|
||||
import '../services/image_codec_service.dart';
|
||||
import '../services/map_tile_cache_service.dart';
|
||||
import '../services/notification_service.dart';
|
||||
import '../services/translation_service.dart';
|
||||
import '../theme/mesh_theme.dart';
|
||||
import '../utils/platform_info.dart';
|
||||
import '../widgets/adaptive_app_bar_title.dart';
|
||||
import '../widgets/mesh_ui.dart';
|
||||
import '../widgets/sync_progress_overlay.dart';
|
||||
@@ -320,6 +322,22 @@ class AppSettingsScreen extends StatelessWidget {
|
||||
? (value) => settingsService.setNotifyOnNewMessage(value)
|
||||
: null,
|
||||
),
|
||||
if (PlatformInfo.isAndroid) ...[
|
||||
const Divider(height: 1, indent: 16),
|
||||
ListTile(
|
||||
contentPadding: const EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
vertical: 4,
|
||||
),
|
||||
leading: const Icon(Icons.battery_saver_outlined, size: 20),
|
||||
title: Text(context.l10n.appSettings_batteryOptimization),
|
||||
subtitle: Text(
|
||||
context.l10n.appSettings_batteryOptimizationSubtitle,
|
||||
),
|
||||
trailing: const Icon(Icons.open_in_new, size: 18),
|
||||
onTap: BackgroundService.openBatteryOptimizationSettings,
|
||||
),
|
||||
],
|
||||
const Divider(height: 1, indent: 16),
|
||||
SwitchListTile(
|
||||
contentPadding: const EdgeInsets.symmetric(
|
||||
@@ -610,6 +628,52 @@ class AppSettingsScreen extends StatelessWidget {
|
||||
},
|
||||
),
|
||||
const Divider(height: 1, indent: 16),
|
||||
SwitchListTile(
|
||||
contentPadding: const EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
vertical: 4,
|
||||
),
|
||||
secondary: const Icon(Icons.cell_tower, size: 20),
|
||||
title: Text(context.l10n.appSettings_channelMinHops),
|
||||
subtitle: Text(context.l10n.appSettings_channelMinHopsSubtitle),
|
||||
value: settingsService.settings.channelMinHopsEnabled,
|
||||
onChanged: settingsService.setChannelMinHopsEnabled,
|
||||
),
|
||||
if (settingsService.settings.channelMinHopsEnabled) ...[
|
||||
ListTile(
|
||||
title: Text(
|
||||
context.l10n.appSettings_channelMinHopsCount(
|
||||
settingsService.settings.channelMinHops,
|
||||
),
|
||||
),
|
||||
subtitle: Slider(
|
||||
value: settingsService.settings.channelMinHops.toDouble(),
|
||||
min: 1,
|
||||
max: 8,
|
||||
divisions: 7,
|
||||
label: settingsService.settings.channelMinHops.toString(),
|
||||
onChanged: (value) =>
|
||||
settingsService.setChannelMinHops(value.toInt()),
|
||||
),
|
||||
),
|
||||
ListTile(
|
||||
title: Text(
|
||||
context.l10n.appSettings_channelMinHopsRetries(
|
||||
settingsService.settings.channelMinHopsRetries,
|
||||
),
|
||||
),
|
||||
subtitle: Slider(
|
||||
value: settingsService.settings.channelMinHopsRetries.toDouble(),
|
||||
min: 1,
|
||||
max: 5,
|
||||
divisions: 4,
|
||||
label: settingsService.settings.channelMinHopsRetries.toString(),
|
||||
onChanged: (value) =>
|
||||
settingsService.setChannelMinHopsRetries(value.toInt()),
|
||||
),
|
||||
),
|
||||
],
|
||||
const Divider(height: 1, indent: 16),
|
||||
_ScrollIntoViewOnce(
|
||||
enabled: focusImageMessages,
|
||||
child: SwitchListTile(
|
||||
@@ -1557,7 +1621,11 @@ class AppSettingsScreen extends StatelessWidget {
|
||||
for (final model in settings.translationDownloadedModels)
|
||||
DropdownMenuItem(
|
||||
value: model.id,
|
||||
child: Text(translationModelFriendlyName(model)),
|
||||
child: Text(
|
||||
translationModelFriendlyName(model),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
],
|
||||
onChanged: settings.translationDownloadedModels.isEmpty
|
||||
@@ -1580,7 +1648,11 @@ class AppSettingsScreen extends StatelessWidget {
|
||||
for (final preset in translationPresetModels)
|
||||
DropdownMenuItem(
|
||||
value: preset.sourceUrl,
|
||||
child: Text(translationModelFriendlyName(preset)),
|
||||
child: Text(
|
||||
translationModelFriendlyName(preset),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
],
|
||||
onChanged: translationService.isBusy
|
||||
@@ -1741,6 +1813,7 @@ class AppSettingsScreen extends StatelessWidget {
|
||||
const SizedBox(height: 8),
|
||||
DropdownButtonFormField<String>(
|
||||
initialValue: settingsService.settings.selectedCyr2latProfileId,
|
||||
isExpanded: true,
|
||||
decoration: InputDecoration(
|
||||
labelText: context.l10n.channels_cyr2latSettingsSubheading,
|
||||
border: const OutlineInputBorder(),
|
||||
@@ -1748,7 +1821,11 @@ class AppSettingsScreen extends StatelessWidget {
|
||||
items: settingsService.settings.cyr2latProfiles.map((profile) {
|
||||
return DropdownMenuItem(
|
||||
value: profile.id,
|
||||
child: Text(profile.name),
|
||||
child: Text(
|
||||
profile.name,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
onChanged: (value) {
|
||||
|
||||
@@ -7,7 +7,6 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter/scheduler.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'package:intl/intl.dart' hide TextDirection;
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../connector/meshcore_connector.dart';
|
||||
@@ -33,9 +32,11 @@ import '../services/image_chunk_transport.dart';
|
||||
import '../services/image_codec_service.dart';
|
||||
import '../services/received_image_store.dart';
|
||||
import '../services/translation_service.dart';
|
||||
import '../utils/image_save.dart';
|
||||
import '../utils/lora_airtime.dart';
|
||||
import '../widgets/received_image_message.dart';
|
||||
import '../widgets/byte_count_input.dart';
|
||||
import '../widgets/chat_day_separator.dart';
|
||||
import '../widgets/empty_state.dart';
|
||||
import '../widgets/chat_zoom_wrapper.dart';
|
||||
import '../widgets/emoji_picker.dart';
|
||||
@@ -77,6 +78,7 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
final ChatScrollController _scrollController = ChatScrollController();
|
||||
final FocusNode _textFieldFocusNode = FocusNode();
|
||||
ChannelMessage? _replyingToMessage;
|
||||
bool _useReplyRegion = false;
|
||||
final CommunityStore _communityStore = CommunityStore();
|
||||
final CommunityPskIndex _communityIndex = CommunityPskIndex();
|
||||
final Map<String, GlobalKey> _messageKeys = {};
|
||||
@@ -98,10 +100,6 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
bool _channelSkipNextBottomSnap = false;
|
||||
String? _unreadDividerMessageId;
|
||||
|
||||
String? _cachedFormatLocale;
|
||||
late DateFormat _hmFormat;
|
||||
late DateFormat _mdFormat;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@@ -210,12 +208,14 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
void _setReplyingTo(ChannelMessage message) {
|
||||
setState(() {
|
||||
_replyingToMessage = message;
|
||||
_useReplyRegion = message.region?.isNotEmpty ?? false;
|
||||
});
|
||||
}
|
||||
|
||||
void _cancelReply() {
|
||||
setState(() {
|
||||
_replyingToMessage = null;
|
||||
_useReplyRegion = false;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -321,21 +321,32 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
),
|
||||
Consumer<MeshCoreConnector>(
|
||||
builder: (context, connector, _) {
|
||||
final unreadCount = connector
|
||||
.getUnreadCountForChannelIndex(
|
||||
widget.channel.index,
|
||||
);
|
||||
final privacy = widget.channel.isPublicChannel
|
||||
? context.l10n.channels_public
|
||||
: context.l10n.channels_private;
|
||||
final region = connector.getChannelRegion(
|
||||
final privacy = switch (Channel.getChannelType(
|
||||
widget.channel,
|
||||
_communityIndex,
|
||||
)) {
|
||||
ChannelType.public => context.l10n.channels_public,
|
||||
ChannelType.hashtag => context.l10n.channels_hashtag,
|
||||
ChannelType.private => context.l10n.channels_private,
|
||||
ChannelType.communityPublic =>
|
||||
context.l10n.community_publicChannel,
|
||||
ChannelType.communityHashtag =>
|
||||
context.l10n.community_hashtagChannel,
|
||||
};
|
||||
final ownRegion = connector.getChannelRegion(
|
||||
widget.channel.index,
|
||||
);
|
||||
final region = connector.getEffectiveChannelRegion(
|
||||
widget.channel.index,
|
||||
);
|
||||
final defaultSuffix = ownRegion.isEmpty
|
||||
? ' ${context.l10n.channels_regionDefaultSuffix}'
|
||||
: '';
|
||||
final regionText = region.isNotEmpty
|
||||
? ' • ${context.l10n.channels_regionSetTo(region)}'
|
||||
? ' • ${context.l10n.channels_regionSetTo(region)}$defaultSuffix'
|
||||
: '';
|
||||
return Text(
|
||||
'$privacy • ${context.l10n.chat_unread(unreadCount)}$regionText',
|
||||
'$privacy$regionText',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(fontSize: 12),
|
||||
);
|
||||
@@ -350,6 +361,25 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
centerTitle: false,
|
||||
bottom: const SyncProgressAppBarBottom(),
|
||||
actions: [
|
||||
Consumer<AppSettingsService>(
|
||||
builder: (context, settings, _) {
|
||||
final muteKey = widget.channel.muteKey;
|
||||
final muted = settings.isChannelMuted(muteKey);
|
||||
return IconButton(
|
||||
tooltip: muted
|
||||
? context.l10n.channels_unmuteChannel
|
||||
: context.l10n.channels_muteChannel,
|
||||
icon: Icon(
|
||||
muted
|
||||
? Icons.notifications_off_outlined
|
||||
: Icons.notifications_outlined,
|
||||
),
|
||||
onPressed: () => muted
|
||||
? settings.unmuteChannel(muteKey)
|
||||
: settings.muteChannel(muteKey),
|
||||
);
|
||||
},
|
||||
),
|
||||
IconButton(
|
||||
tooltip: context.l10n.channels_regionSelect_Title,
|
||||
icon: const Icon(Icons.landscape),
|
||||
@@ -513,10 +543,22 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
row.image!,
|
||||
textScale,
|
||||
);
|
||||
if (isUnreadAnchor) {
|
||||
final startsDay =
|
||||
index == reversedRows.length - 1 ||
|
||||
!isSameChatDay(
|
||||
reversedRows[index + 1].timestamp,
|
||||
row.timestamp,
|
||||
);
|
||||
if (isUnreadAnchor || startsDay) {
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [const UnreadDivider(), bubble],
|
||||
children: [
|
||||
if (startsDay)
|
||||
ChatDaySeparator(day: row.timestamp),
|
||||
if (isUnreadAnchor)
|
||||
const UnreadDivider(),
|
||||
bubble,
|
||||
],
|
||||
);
|
||||
}
|
||||
return bubble;
|
||||
@@ -799,7 +841,7 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
buildTextContent(),
|
||||
],
|
||||
),
|
||||
if (enableTracing && displayPath.isNotEmpty) ...[
|
||||
if (displayPath.isNotEmpty) ...[
|
||||
const SizedBox(height: 3),
|
||||
Padding(
|
||||
padding: gifId != null
|
||||
@@ -809,25 +851,61 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
RouteChip(
|
||||
isDirect: (message.pathLength ?? -1) >= 0,
|
||||
hops: displayHopCount,
|
||||
Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
RouteChip(
|
||||
isDirect: (message.pathLength ?? -1) >= 0,
|
||||
hops: displayHopCount,
|
||||
),
|
||||
if (message.region?.isNotEmpty ?? false)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 2),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 6,
|
||||
vertical: 2,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: scheme.surfaceContainerHigh,
|
||||
borderRadius: BorderRadius.circular(
|
||||
MeshRadii.xs,
|
||||
),
|
||||
border: Border.all(
|
||||
color: scheme.outlineVariant,
|
||||
),
|
||||
),
|
||||
child: Text(
|
||||
_displayRegion(message.region!),
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 8.5 * textScale,
|
||||
color: metaColor,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Flexible(
|
||||
child: Text(
|
||||
context.l10n.channels_via(
|
||||
_formatPathPrefixes(
|
||||
displayPath,
|
||||
displayPathHashWidth,
|
||||
if (enableTracing) ...[
|
||||
const SizedBox(width: 4),
|
||||
Flexible(
|
||||
child: Text(
|
||||
context.l10n.channels_via(
|
||||
_formatPathPrefixes(
|
||||
displayPath,
|
||||
displayPathHashWidth,
|
||||
),
|
||||
),
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 9.5 * textScale,
|
||||
color: metaColor,
|
||||
),
|
||||
),
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 9.5 * textScale,
|
||||
color: metaColor,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -845,13 +923,15 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
_formatTime(context, message.timestamp),
|
||||
formatChatTime(context, message.timestamp),
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 10 * textScale,
|
||||
fontSize: 12 * textScale,
|
||||
color: metaColor,
|
||||
),
|
||||
),
|
||||
if (enableTracing && message.repeatCount > 0) ...[
|
||||
if (enableTracing &&
|
||||
!isOutgoing &&
|
||||
message.repeatCount > 0) ...[
|
||||
const SizedBox(width: 6),
|
||||
Icon(
|
||||
Icons.repeat,
|
||||
@@ -862,7 +942,7 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
Text(
|
||||
'${message.repeatCount}',
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 10 * textScale,
|
||||
fontSize: 12 * textScale,
|
||||
color: metaColor,
|
||||
),
|
||||
),
|
||||
@@ -870,13 +950,16 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
if (isOutgoing) ...[
|
||||
const SizedBox(width: 4),
|
||||
MessageStatusIcon(
|
||||
isAcked:
|
||||
message.status ==
|
||||
ChannelMessageStatus.sent,
|
||||
isRepeated:
|
||||
message.status ==
|
||||
ChannelMessageStatus.sent &&
|
||||
displayPath.isNotEmpty,
|
||||
size: 16 * textScale,
|
||||
isAcked: false,
|
||||
isChannel: true,
|
||||
repeatCount: message.repeatCount,
|
||||
resendProgress: context
|
||||
.read<MeshCoreConnector>()
|
||||
.channelResendProgress(message.messageId),
|
||||
hopShortfall: context
|
||||
.read<MeshCoreConnector>()
|
||||
.channelHopShortfall(message.messageId),
|
||||
isPending:
|
||||
message.status ==
|
||||
ChannelMessageStatus.pending,
|
||||
@@ -1224,16 +1307,37 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether the image codec model is currently downloading.
|
||||
///
|
||||
/// This must be read while [context] is building; popup item builders run
|
||||
/// from an overlay and cannot listen to a provider.
|
||||
bool _isImageCodecDownloading(BuildContext context) {
|
||||
try {
|
||||
return context.watch<ImageCodecService>().isDownloading;
|
||||
} on ProviderNotFoundException {
|
||||
return false;
|
||||
void _explainImageCodecNotReady(ImageCodecService codec) {
|
||||
final l10n = context.l10n;
|
||||
final availability = codec.availability;
|
||||
final String message;
|
||||
switch (availability) {
|
||||
case ImageCodecAvailability.downloading:
|
||||
message = l10n.imageSend_codecDownloading;
|
||||
case ImageCodecAvailability.unavailable:
|
||||
message = codec.unavailableReason ?? l10n.imageSend_codecUnavailable;
|
||||
case ImageCodecAvailability.disabled:
|
||||
message = codec.needsModelDownload
|
||||
? l10n.imageSend_modelNotDownloaded
|
||||
: codec.statusReason ?? l10n.imageSend_codecDisabled;
|
||||
case ImageCodecAvailability.ready:
|
||||
return;
|
||||
}
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(message),
|
||||
action: availability == ImageCodecAvailability.disabled
|
||||
? SnackBarAction(
|
||||
label: l10n.receivedImage_openSettings,
|
||||
onPressed: () => Navigator.of(context).push(
|
||||
MaterialPageRoute<void>(
|
||||
builder: (_) =>
|
||||
const AppSettingsScreen(focusImageMessages: true),
|
||||
),
|
||||
),
|
||||
)
|
||||
: null,
|
||||
);
|
||||
}
|
||||
|
||||
/// Takes no [BuildContext]: it uses the [State]'s own, so the `mounted`
|
||||
@@ -1241,6 +1345,10 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
Future<void> _showImageSendPreview() async {
|
||||
final codec = _imageCodec;
|
||||
if (codec == null) return;
|
||||
if (codec.availability != ImageCodecAvailability.ready) {
|
||||
_explainImageCodecNotReady(codec);
|
||||
return;
|
||||
}
|
||||
final connector = context.read<MeshCoreConnector>();
|
||||
|
||||
// The picked bytes are kept past the preview on purpose: the sender's own
|
||||
@@ -1545,7 +1653,7 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
final textColor = isOutgoing ? MeshPalette.meInk : scheme.onSurface;
|
||||
final metaColor = textColor.withValues(alpha: 0.65);
|
||||
|
||||
return Padding(
|
||||
final bubble = Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 3),
|
||||
child: Row(
|
||||
mainAxisAlignment: isOutgoing
|
||||
@@ -1612,9 +1720,9 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
bottom: 4,
|
||||
),
|
||||
child: Text(
|
||||
_formatTime(context, entry.firstSeen),
|
||||
formatChatTime(context, entry.firstSeen),
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 10 * textScale,
|
||||
fontSize: 12 * textScale,
|
||||
color: metaColor,
|
||||
),
|
||||
),
|
||||
@@ -1626,6 +1734,123 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
],
|
||||
),
|
||||
);
|
||||
return GestureDetector(
|
||||
onLongPress: () => _showImageActions(entry),
|
||||
onSecondaryTap: () => _showImageActions(entry),
|
||||
child: bubble,
|
||||
);
|
||||
}
|
||||
|
||||
void _showImageActions(ReceivedImageEntry entry) {
|
||||
final l10n = context.l10n;
|
||||
final canSave = entry.state == ReceivedImageState.decoded;
|
||||
showMeshSheet(
|
||||
context,
|
||||
builder: (sheetContext) => SafeArea(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
BottomSheetHeader(
|
||||
title: l10n.receivedImage_awaiting(
|
||||
entry.bitstreamByteCount,
|
||||
entry.totalChunks,
|
||||
),
|
||||
subtitle: _imageSenderLabel(entry),
|
||||
),
|
||||
if (canSave)
|
||||
ListTile(
|
||||
leading: const Icon(Icons.save_alt),
|
||||
title: Text(l10n.receivedImage_save),
|
||||
onTap: () {
|
||||
Navigator.pop(sheetContext);
|
||||
_saveImage(entry);
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.info_outline),
|
||||
title: Text(l10n.receivedImage_packetInfo),
|
||||
onTap: () {
|
||||
Navigator.pop(sheetContext);
|
||||
_showImagePacketInfo(entry);
|
||||
},
|
||||
),
|
||||
const Divider(height: 1),
|
||||
ListTile(
|
||||
leading: Icon(
|
||||
Icons.delete_outline,
|
||||
color: Theme.of(context).colorScheme.error,
|
||||
),
|
||||
title: Text(
|
||||
l10n.common_delete,
|
||||
style: TextStyle(color: Theme.of(context).colorScheme.error),
|
||||
),
|
||||
onTap: () async {
|
||||
Navigator.pop(sheetContext);
|
||||
await context.read<ReceivedImageStore>().deleteImage(
|
||||
entry.streamId,
|
||||
);
|
||||
if (!mounted) return;
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(l10n.chat_messageDeleted),
|
||||
);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _saveImage(ReceivedImageEntry entry) async {
|
||||
final l10n = context.l10n;
|
||||
final png = await context.read<ReceivedImageStore>().ensurePng(
|
||||
entry.streamId,
|
||||
);
|
||||
if (!mounted) return;
|
||||
final shareText = l10n.receivedImage_shareCaption(entry.bitstreamByteCount);
|
||||
if (png == null || !await saveImagePng(png, entry, shareText: shareText)) {
|
||||
if (!mounted) return;
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(l10n.receivedImage_saveFailed),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void _showImagePacketInfo(ReceivedImageEntry entry) {
|
||||
final l10n = context.l10n;
|
||||
final decodeMs = entry.decodeMs;
|
||||
showDialog<void>(
|
||||
context: context,
|
||||
builder: (dialogContext) => AlertDialog(
|
||||
title: Text(l10n.receivedImage_packetInfo),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(_imageSenderLabel(entry)),
|
||||
Text(formatChatTime(context, entry.firstSeen)),
|
||||
Text(
|
||||
l10n.receivedImage_awaiting(
|
||||
entry.bitstreamByteCount,
|
||||
entry.totalChunks,
|
||||
),
|
||||
),
|
||||
if (entry.recoveredWithParity)
|
||||
Text(l10n.receivedImage_parityRecovered),
|
||||
if (decodeMs != null) Text(l10n.receivedImage_decodeTime(decodeMs)),
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(dialogContext),
|
||||
child: Text(l10n.common_close),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// GRP_DATA carries no sender name — only the 2-byte public-key prefix the
|
||||
@@ -1670,6 +1895,7 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
Widget _buildReplyBanner(double textScale) {
|
||||
final message = _replyingToMessage!;
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
final replyRegion = message.region;
|
||||
return Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
||||
@@ -1707,8 +1933,43 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
],
|
||||
),
|
||||
),
|
||||
if (replyRegion?.isNotEmpty ?? false)
|
||||
InkWell(
|
||||
borderRadius: BorderRadius.circular(MeshRadii.xs),
|
||||
onTap: () => setState(() => _useReplyRegion = !_useReplyRegion),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 3),
|
||||
decoration: BoxDecoration(
|
||||
color: _useReplyRegion
|
||||
? scheme.primaryContainer
|
||||
: scheme.surfaceContainerHighest,
|
||||
borderRadius: BorderRadius.circular(MeshRadii.xs),
|
||||
border: Border.all(
|
||||
color: _useReplyRegion
|
||||
? scheme.primary
|
||||
: scheme.outlineVariant,
|
||||
),
|
||||
),
|
||||
child: Text(
|
||||
context.l10n.channels_regionSetTo(replyRegion!),
|
||||
style:
|
||||
MeshTheme.mono(
|
||||
fontSize: 10 * textScale,
|
||||
color: _useReplyRegion
|
||||
? scheme.onPrimaryContainer
|
||||
: scheme.onSurfaceVariant,
|
||||
).copyWith(
|
||||
decoration: _useReplyRegion
|
||||
? null
|
||||
: TextDecoration.lineThrough,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.close, size: 18),
|
||||
tooltip: context.l10n.chat_cancelReply,
|
||||
onPressed: _cancelReply,
|
||||
color: scheme.onSurfaceVariant,
|
||||
constraints: const BoxConstraints(minWidth: 44, minHeight: 44),
|
||||
@@ -1753,9 +2014,7 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
final connector = context.watch<MeshCoreConnector>();
|
||||
final maxBytes = maxChannelMessageBytes(connector.selfName);
|
||||
final settings = context.watch<AppSettingsService>().settings;
|
||||
final imageCodecDownloading = _isImageCodecDownloading(context);
|
||||
final showImageAction =
|
||||
settings.imageMessagesEnabled && !imageCodecDownloading;
|
||||
final showImageAction = settings.imageMessagesEnabled;
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
@@ -1811,13 +2070,6 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
if (showImageAction)
|
||||
PopupMenuItem(
|
||||
value: 'meshcore-image',
|
||||
// Gated on the codec, not just the setting. The preview
|
||||
// sheet explains why a send is impossible, but a fully
|
||||
// live button in a build that cannot encode invites the
|
||||
// tap that produces that explanation.
|
||||
enabled:
|
||||
_imageCodec?.availability ==
|
||||
ImageCodecAvailability.ready,
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.image_outlined),
|
||||
@@ -1872,6 +2124,7 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
const SizedBox(width: 8),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.close),
|
||||
tooltip: context.l10n.chat_removeGif,
|
||||
onPressed: () {
|
||||
_textController.clear();
|
||||
_textFieldFocusNode.requestFocus();
|
||||
@@ -2032,6 +2285,7 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
if (_replyingToMessage != null) {
|
||||
messageText = '@[${_replyingToMessage!.senderName}] $messageText';
|
||||
}
|
||||
final replyRegion = _useReplyRegion ? _replyingToMessage?.region : null;
|
||||
|
||||
final maxBytes = maxChannelMessageBytes(connector.selfName);
|
||||
final outboundText = connector.prepareChannelOutboundText(
|
||||
@@ -2055,6 +2309,7 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
}
|
||||
// end transform
|
||||
|
||||
final replyTo = _replyingToMessage;
|
||||
_textController.clear();
|
||||
_cancelReply();
|
||||
_textFieldFocusNode.requestFocus();
|
||||
@@ -2064,27 +2319,11 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
originalText: originalText,
|
||||
translatedLanguageCode: translatedLanguageCode,
|
||||
translationModelId: translationModelId,
|
||||
region: replyRegion,
|
||||
replyTo: replyTo,
|
||||
);
|
||||
}
|
||||
|
||||
String _formatTime(BuildContext context, DateTime time) {
|
||||
final now = DateTime.now();
|
||||
final diff = now.difference(time);
|
||||
final locale = Localizations.localeOf(context).toString();
|
||||
if (locale != _cachedFormatLocale) {
|
||||
_cachedFormatLocale = locale;
|
||||
_hmFormat = DateFormat.Hm(locale);
|
||||
_mdFormat = DateFormat.Md(locale);
|
||||
}
|
||||
final hm = _hmFormat.format(time);
|
||||
|
||||
if (diff.inDays > 0) {
|
||||
return '${_mdFormat.format(time)} $hm';
|
||||
} else {
|
||||
return hm;
|
||||
}
|
||||
}
|
||||
|
||||
void _showMessagePathInfo(ChannelMessage message) {
|
||||
Navigator.push(
|
||||
context,
|
||||
@@ -2112,8 +2351,8 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
BottomSheetHeader(
|
||||
title: message.text.length > 40
|
||||
? '${message.text.substring(0, 40)}…'
|
||||
title: message.text.characters.length > 40
|
||||
? '${message.text.characters.take(40)}…'
|
||||
: message.text,
|
||||
subtitle: message.senderName.isNotEmpty
|
||||
? message.senderName
|
||||
@@ -2135,6 +2374,23 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
_showMessagePathInfo(message);
|
||||
},
|
||||
),
|
||||
if (message.pathBytes.isNotEmpty)
|
||||
ListTile(
|
||||
leading: const Icon(Icons.map_outlined),
|
||||
title: Text(context.l10n.chat_viewPathOnMap),
|
||||
onTap: () {
|
||||
Navigator.pop(sheetContext);
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => ChannelMessagePathMapScreen(
|
||||
message: message,
|
||||
channelMessage: true,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
// Can't react to your own messages
|
||||
if (!message.isOutgoing)
|
||||
ListTile(
|
||||
@@ -2222,6 +2478,9 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
|
||||
void _copyMessageText(String text) {
|
||||
Clipboard.setData(ClipboardData(text: text));
|
||||
// Android shows its own clipboard chip; the snackbar is redundant there
|
||||
// and lingers over the input field after the chip dismisses.
|
||||
if (PlatformInfo.isAndroid) return;
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(context.l10n.chat_messageCopied),
|
||||
@@ -2253,6 +2512,13 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
context.read<MeshCoreConnector>().clearMessagesForChannel(
|
||||
widget.channel.index,
|
||||
);
|
||||
try {
|
||||
await context.read<ReceivedImageStore>().deleteImagesForChannel(
|
||||
widget.channel.index,
|
||||
);
|
||||
} on ProviderNotFoundException {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2282,6 +2548,10 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
return PathHelper.splitPathBytes(pathBytes, pathHashByteWidth).length;
|
||||
}
|
||||
|
||||
String _displayRegion(String region) {
|
||||
return region.startsWith('#') ? region.substring(1) : region;
|
||||
}
|
||||
|
||||
Future<void> openRegionSelectDialog(Channel channel) async {
|
||||
// The AppBar subtitle reads the region from the connector inside a
|
||||
// Consumer, so setChannelRegion's notifyListeners refreshes it directly —
|
||||
@@ -2337,57 +2607,77 @@ class _RegionSelectDialogState extends State<_RegionSelectDialog> {
|
||||
backgroundColor: Colors.transparent,
|
||||
title: Text(context.l10n.channels_regionSelect_Title),
|
||||
centerTitle: true,
|
||||
actions: [
|
||||
IconButton(
|
||||
tooltip: context.l10n.channels_clearRegion,
|
||||
icon: const Icon(Icons.backspace_outlined),
|
||||
onPressed: () {
|
||||
context.read<MeshCoreConnector>().setChannelRegion(
|
||||
widget.channel.index,
|
||||
'',
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
child: Text(
|
||||
context.l10n.channels_regionSelectExplanation,
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
if (regions.isEmpty)
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Text(context.l10n.channels_regionEmpty),
|
||||
)
|
||||
else
|
||||
Expanded(
|
||||
child: ListView.builder(
|
||||
itemCount: regions.length,
|
||||
itemBuilder: (context, index) {
|
||||
final selected = selectedIndex == index;
|
||||
return ListTile(
|
||||
leading: Icon(
|
||||
Icons.landscape,
|
||||
color: selected ? MeshPalette.blue : null,
|
||||
),
|
||||
title: Text(regions[index]),
|
||||
trailing: selected
|
||||
? const Icon(Icons.check, color: MeshPalette.blue)
|
||||
: null,
|
||||
tileColor: selected ? MeshPalette.blueBg : null,
|
||||
onTap: () {
|
||||
// Tapping the already-selected region clears it.
|
||||
context.read<MeshCoreConnector>().setChannelRegion(
|
||||
widget.channel.index,
|
||||
selected ? '' : regions[index],
|
||||
);
|
||||
Navigator.pop(context);
|
||||
},
|
||||
);
|
||||
Navigator.pop(context);
|
||||
},
|
||||
),
|
||||
IconButton(
|
||||
tooltip: context.l10n.settings_regionSettingsSubtitle,
|
||||
icon: const Icon(Icons.settings),
|
||||
),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
TextButton(
|
||||
onPressed:
|
||||
context
|
||||
.read<MeshCoreConnector>()
|
||||
.getChannelRegion(widget.channel.index)
|
||||
.isEmpty
|
||||
? null
|
||||
: () {
|
||||
context.read<MeshCoreConnector>().setChannelRegion(
|
||||
widget.channel.index,
|
||||
'',
|
||||
);
|
||||
Navigator.pop(context);
|
||||
},
|
||||
child: Text(context.l10n.common_clear),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
await pushRegionManagementScreen(context);
|
||||
if (!mounted) return;
|
||||
loadRegions();
|
||||
},
|
||||
child: Text(context.l10n.channels_manageRegions),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 15),
|
||||
Expanded(
|
||||
child: ListView.builder(
|
||||
itemCount: regions.length,
|
||||
itemBuilder: (context, index) {
|
||||
final selected = selectedIndex == index;
|
||||
return ListTile(
|
||||
leading: Icon(
|
||||
Icons.landscape,
|
||||
color: selected ? MeshPalette.blue : null,
|
||||
),
|
||||
title: Text(regions[index]),
|
||||
trailing: selected
|
||||
? const Icon(Icons.check, color: MeshPalette.blue)
|
||||
: null,
|
||||
tileColor: selected ? MeshPalette.blueBg : null,
|
||||
onTap: () {
|
||||
// Tapping the already-selected region clears it.
|
||||
context.read<MeshCoreConnector>().setChannelRegion(
|
||||
widget.channel.index,
|
||||
selected ? '' : regions[index],
|
||||
);
|
||||
Navigator.pop(context);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
@@ -211,6 +211,13 @@ class ChannelMessagePathScreen extends StatelessWidget {
|
||||
observedLabel,
|
||||
scheme: scheme,
|
||||
),
|
||||
if (message.region?.isNotEmpty ?? false)
|
||||
_buildDetailRow(
|
||||
context,
|
||||
l10n.settings_regionName,
|
||||
message.region!,
|
||||
scheme: scheme,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
+240
-196
@@ -12,6 +12,7 @@ import 'package:uuid/uuid.dart';
|
||||
import '../connector/meshcore_connector.dart';
|
||||
import '../l10n/l10n.dart';
|
||||
import '../services/app_settings_service.dart';
|
||||
import '../services/received_image_store.dart';
|
||||
import '../services/ui_view_state_service.dart';
|
||||
import '../models/channel.dart';
|
||||
import '../models/community.dart';
|
||||
@@ -34,6 +35,7 @@ import 'community_qr_scanner_screen.dart';
|
||||
import 'contacts_screen.dart';
|
||||
import 'map_screen.dart';
|
||||
import 'settings_screen.dart';
|
||||
import '../review_mode/review_mode_banner.dart';
|
||||
|
||||
class ChannelsScreen extends StatefulWidget {
|
||||
final bool hideBackButton;
|
||||
@@ -165,171 +167,187 @@ class _ChannelsScreenState extends State<ChannelsScreen>
|
||||
),
|
||||
],
|
||||
),
|
||||
body: RefreshIndicator(
|
||||
onRefresh: () async {
|
||||
await context.read<MeshCoreConnector>().getChannels(force: true);
|
||||
},
|
||||
child: () {
|
||||
final channels = connector.channels;
|
||||
final waitingForFirstChannel =
|
||||
connector.isLoadingChannels && channels.isEmpty;
|
||||
body: Column(
|
||||
children: [
|
||||
const ReviewModeBanner(),
|
||||
Expanded(
|
||||
child: RefreshIndicator(
|
||||
onRefresh: () async {
|
||||
await context.read<MeshCoreConnector>().getChannels(
|
||||
force: true,
|
||||
);
|
||||
},
|
||||
child: () {
|
||||
final channels = connector.channels;
|
||||
final waitingForFirstChannel =
|
||||
connector.isLoadingChannels && channels.isEmpty;
|
||||
|
||||
// Only block the list while the first channel is actively loading.
|
||||
// If the initial sync aborts, show cached/partial channels instead
|
||||
// of trapping the user behind an idle spinner.
|
||||
if (waitingForFirstChannel) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
// Only block the list while the first channel is actively loading.
|
||||
// If the initial sync aborts, show cached/partial channels instead
|
||||
// of trapping the user behind an idle spinner.
|
||||
if (waitingForFirstChannel) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
|
||||
if (channels.isEmpty) {
|
||||
return ListView(
|
||||
children: [
|
||||
SizedBox(
|
||||
height: MediaQuery.of(context).size.height - 200,
|
||||
child: EmptyState(
|
||||
icon: Icons.tag,
|
||||
title: context.l10n.channels_noChannelsConfigured,
|
||||
action: FilledButton.icon(
|
||||
onPressed: () => _addPublicChannel(context, connector),
|
||||
icon: const Icon(Icons.public),
|
||||
label: Text(context.l10n.channels_addPublicChannel),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
if (channels.isEmpty) {
|
||||
return ListView(
|
||||
children: [
|
||||
SizedBox(
|
||||
height: MediaQuery.of(context).size.height - 200,
|
||||
child: EmptyState(
|
||||
icon: Icons.tag,
|
||||
title: context.l10n.channels_noChannelsConfigured,
|
||||
action: FilledButton.icon(
|
||||
onPressed: () =>
|
||||
_addPublicChannel(context, connector),
|
||||
icon: const Icon(Icons.public),
|
||||
label: Text(
|
||||
context.l10n.channels_addPublicChannel,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
final filteredChannels = _filterAndSortChannels(
|
||||
channels,
|
||||
connector,
|
||||
viewState,
|
||||
);
|
||||
final filteredChannels = _filterAndSortChannels(
|
||||
channels,
|
||||
connector,
|
||||
viewState,
|
||||
);
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: TextField(
|
||||
controller: _searchController,
|
||||
decoration: InputDecoration(
|
||||
hintText: context.l10n.channels_searchChannels,
|
||||
prefixIcon: const Icon(Icons.search),
|
||||
suffixIcon: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
if (viewState.channelsSearchText.isNotEmpty)
|
||||
IconButton(
|
||||
icon: const Icon(Icons.clear),
|
||||
onPressed: () {
|
||||
_searchDebounce?.cancel();
|
||||
_searchDebounce = null;
|
||||
_searchController.clear();
|
||||
return Column(
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: TextField(
|
||||
controller: _searchController,
|
||||
decoration: InputDecoration(
|
||||
hintText: context.l10n.channels_searchChannels,
|
||||
prefixIcon: const Icon(Icons.search),
|
||||
suffixIcon: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
if (viewState.channelsSearchText.isNotEmpty)
|
||||
IconButton(
|
||||
icon: const Icon(Icons.clear),
|
||||
tooltip: context.l10n.common_clearSearch,
|
||||
onPressed: () {
|
||||
_searchDebounce?.cancel();
|
||||
_searchDebounce = null;
|
||||
_searchController.clear();
|
||||
context
|
||||
.read<UiViewStateService>()
|
||||
.setChannelsSearchText('');
|
||||
},
|
||||
),
|
||||
_buildFilterButton(viewState),
|
||||
],
|
||||
),
|
||||
contentPadding: const EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
vertical: 12,
|
||||
),
|
||||
),
|
||||
onChanged: (value) {
|
||||
_searchDebounce?.cancel();
|
||||
_searchDebounce = Timer(
|
||||
const Duration(milliseconds: 300),
|
||||
() {
|
||||
if (!mounted) return;
|
||||
context
|
||||
.read<UiViewStateService>()
|
||||
.setChannelsSearchText('');
|
||||
.setChannelsSearchText(value);
|
||||
},
|
||||
),
|
||||
_buildFilterButton(viewState),
|
||||
],
|
||||
),
|
||||
contentPadding: const EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
vertical: 12,
|
||||
),
|
||||
),
|
||||
onChanged: (value) {
|
||||
_searchDebounce?.cancel();
|
||||
_searchDebounce = Timer(
|
||||
const Duration(milliseconds: 300),
|
||||
() {
|
||||
if (!mounted) return;
|
||||
context
|
||||
.read<UiViewStateService>()
|
||||
.setChannelsSearchText(value);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: filteredChannels.isEmpty
|
||||
? LayoutBuilder(
|
||||
builder: (context, constraints) => ListView(
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
children: [
|
||||
ConstrainedBox(
|
||||
constraints: BoxConstraints(
|
||||
minHeight: constraints.maxHeight,
|
||||
),
|
||||
child: EmptyState(
|
||||
icon: Icons.search_off,
|
||||
title: context.l10n.channels_noChannelsFound,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
: (viewState.channelsSortOption ==
|
||||
ChannelSortOption.manual &&
|
||||
viewState.channelsSearchText.isEmpty)
|
||||
? ReorderableListView.builder(
|
||||
padding: const EdgeInsets.only(
|
||||
left: 0,
|
||||
right: 0,
|
||||
top: 8,
|
||||
bottom: 88,
|
||||
),
|
||||
buildDefaultDragHandles: false,
|
||||
itemCount: filteredChannels.length,
|
||||
onReorderItem: (oldIndex, newIndex) {
|
||||
final reordered = List<Channel>.from(
|
||||
filteredChannels,
|
||||
);
|
||||
final item = reordered.removeAt(oldIndex);
|
||||
reordered.insert(newIndex, item);
|
||||
unawaited(
|
||||
connector.setChannelOrder(
|
||||
reordered.map((c) => c.index).toList(),
|
||||
),
|
||||
);
|
||||
},
|
||||
itemBuilder: (context, index) {
|
||||
final channel = filteredChannels[index];
|
||||
return _buildChannelTile(
|
||||
context,
|
||||
connector,
|
||||
channelMessageStore,
|
||||
channel,
|
||||
showDragHandle: true,
|
||||
dragIndex: index,
|
||||
listIndex: index,
|
||||
);
|
||||
},
|
||||
)
|
||||
: ListView.builder(
|
||||
padding: const EdgeInsets.only(
|
||||
left: 0,
|
||||
right: 0,
|
||||
top: 8,
|
||||
bottom: 88,
|
||||
),
|
||||
itemCount: filteredChannels.length,
|
||||
itemBuilder: (context, index) {
|
||||
final channel = filteredChannels[index];
|
||||
return _buildChannelTile(
|
||||
context,
|
||||
connector,
|
||||
channelMessageStore,
|
||||
channel,
|
||||
listIndex: index,
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}(),
|
||||
),
|
||||
Expanded(
|
||||
child: filteredChannels.isEmpty
|
||||
? LayoutBuilder(
|
||||
builder: (context, constraints) => ListView(
|
||||
physics:
|
||||
const AlwaysScrollableScrollPhysics(),
|
||||
children: [
|
||||
ConstrainedBox(
|
||||
constraints: BoxConstraints(
|
||||
minHeight: constraints.maxHeight,
|
||||
),
|
||||
child: EmptyState(
|
||||
icon: Icons.search_off,
|
||||
title: context
|
||||
.l10n
|
||||
.channels_noChannelsFound,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
: (viewState.channelsSortOption ==
|
||||
ChannelSortOption.manual &&
|
||||
viewState.channelsSearchText.isEmpty)
|
||||
? ReorderableListView.builder(
|
||||
padding: const EdgeInsets.only(
|
||||
left: 0,
|
||||
right: 0,
|
||||
top: 8,
|
||||
bottom: 88,
|
||||
),
|
||||
buildDefaultDragHandles: false,
|
||||
itemCount: filteredChannels.length,
|
||||
onReorderItem: (oldIndex, newIndex) {
|
||||
final reordered = List<Channel>.from(
|
||||
filteredChannels,
|
||||
);
|
||||
final item = reordered.removeAt(oldIndex);
|
||||
reordered.insert(newIndex, item);
|
||||
unawaited(
|
||||
connector.setChannelOrder(
|
||||
reordered.map((c) => c.index).toList(),
|
||||
),
|
||||
);
|
||||
},
|
||||
itemBuilder: (context, index) {
|
||||
final channel = filteredChannels[index];
|
||||
return _buildChannelTile(
|
||||
context,
|
||||
connector,
|
||||
channelMessageStore,
|
||||
channel,
|
||||
showDragHandle: true,
|
||||
dragIndex: index,
|
||||
listIndex: index,
|
||||
);
|
||||
},
|
||||
)
|
||||
: ListView.builder(
|
||||
padding: const EdgeInsets.only(
|
||||
left: 0,
|
||||
right: 0,
|
||||
top: 8,
|
||||
bottom: 88,
|
||||
),
|
||||
itemCount: filteredChannels.length,
|
||||
itemBuilder: (context, index) {
|
||||
final channel = filteredChannels[index];
|
||||
return _buildChannelTile(
|
||||
context,
|
||||
connector,
|
||||
channelMessageStore,
|
||||
channel,
|
||||
listIndex: index,
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}(),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
onPressed: () => _showAddChannelDialog(context),
|
||||
@@ -361,7 +379,7 @@ class _ChannelsScreenState extends State<ChannelsScreen>
|
||||
}) {
|
||||
final unreadCount = connector.getUnreadCountForChannel(channel);
|
||||
final isMuted = context.watch<AppSettingsService>().isChannelMuted(
|
||||
channel.name,
|
||||
channel.muteKey,
|
||||
);
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
|
||||
@@ -402,7 +420,7 @@ class _ChannelsScreenState extends State<ChannelsScreen>
|
||||
iconColor = MeshPalette.signal;
|
||||
case ChannelType.hashtag:
|
||||
icon = Icons.tag;
|
||||
iconColor = MeshPalette.blue;
|
||||
iconColor = MeshPalette.warn;
|
||||
case ChannelType.private:
|
||||
icon = Icons.lock;
|
||||
iconColor = MeshPalette.blue;
|
||||
@@ -516,14 +534,18 @@ class _ChannelsScreenState extends State<ChannelsScreen>
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
Text(
|
||||
'CH ${channel.index}',
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 11,
|
||||
color: scheme.onSurfaceVariant.withValues(alpha: 0.7),
|
||||
if (showDragHandle) ...[
|
||||
const SizedBox(width: 6),
|
||||
Text(
|
||||
'CH ${channel.index}',
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 11,
|
||||
color: scheme.onSurfaceVariant.withValues(
|
||||
alpha: 0.7,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
if (subtitle.isNotEmpty) ...[
|
||||
@@ -584,17 +606,21 @@ class _ChannelsScreenState extends State<ChannelsScreen>
|
||||
],
|
||||
),
|
||||
if (showDragHandle && dragIndex != null) ...[
|
||||
const SizedBox(width: 4),
|
||||
ReorderableDragStartListener(
|
||||
index: dragIndex,
|
||||
// Top-aligned with the "CH n" / time line. Bottom padding keeps
|
||||
// a comfortable drag target without pushing the icon down.
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(left: 8, right: 8, bottom: 16),
|
||||
child: Icon(
|
||||
Icons.drag_handle,
|
||||
size: 18,
|
||||
color: scheme.onSurfaceVariant,
|
||||
child: MouseRegion(
|
||||
cursor: SystemMouseCursors.grab,
|
||||
child: Tooltip(
|
||||
message: context.l10n.channels_dragToReorder,
|
||||
child: SizedBox(
|
||||
width: 48,
|
||||
height: 48,
|
||||
child: Icon(
|
||||
Icons.drag_indicator,
|
||||
size: 28,
|
||||
color: scheme.onSurface,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -613,7 +639,7 @@ class _ChannelsScreenState extends State<ChannelsScreen>
|
||||
) {
|
||||
final parentContext = context;
|
||||
final settingsService = context.read<AppSettingsService>();
|
||||
final isMuted = settingsService.isChannelMuted(channel.name);
|
||||
final isMuted = settingsService.isChannelMuted(channel.muteKey);
|
||||
|
||||
showModalBottomSheet(
|
||||
context: parentContext,
|
||||
@@ -646,9 +672,9 @@ class _ChannelsScreenState extends State<ChannelsScreen>
|
||||
onTap: () async {
|
||||
Navigator.pop(sheetContext);
|
||||
if (isMuted) {
|
||||
await settingsService.unmuteChannel(channel.name);
|
||||
await settingsService.unmuteChannel(channel.muteKey);
|
||||
} else {
|
||||
await settingsService.muteChannel(channel.name);
|
||||
await settingsService.muteChannel(channel.muteKey);
|
||||
}
|
||||
},
|
||||
),
|
||||
@@ -814,6 +840,13 @@ class _ChannelsScreenState extends State<ChannelsScreen>
|
||||
connector.channels,
|
||||
connector.maxChannels,
|
||||
);
|
||||
if (nextIndex == null) {
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(context.l10n.channels_noFreeSlots),
|
||||
);
|
||||
return;
|
||||
}
|
||||
final hasPublicChannel = connector.channels.any((c) => c.isPublicChannel);
|
||||
int? selectedOption;
|
||||
final nameController = TextEditingController();
|
||||
@@ -1455,24 +1488,7 @@ class _ChannelsScreenState extends State<ChannelsScreen>
|
||||
controller: scrollController,
|
||||
padding: const EdgeInsets.only(bottom: 24),
|
||||
children: [
|
||||
buildOptionCard(
|
||||
optionIndex: 0,
|
||||
icon: Icons.add,
|
||||
title: sheetContext.l10n.channels_createPrivateChannel,
|
||||
subtitle:
|
||||
sheetContext.l10n.channels_createPrivateChannelDesc,
|
||||
),
|
||||
if (selectedOption == 0)
|
||||
buildExpandedContent(_channelMessageStore)!,
|
||||
buildOptionCard(
|
||||
optionIndex: 1,
|
||||
icon: Icons.lock,
|
||||
title: sheetContext.l10n.channels_joinPrivateChannel,
|
||||
subtitle:
|
||||
sheetContext.l10n.channels_joinPrivateChannelDesc,
|
||||
),
|
||||
if (selectedOption == 1)
|
||||
buildExpandedContent(_channelMessageStore)!,
|
||||
SectionHeader(sheetContext.l10n.channels_addSectionJoin),
|
||||
if (!hasPublicChannel) ...[
|
||||
buildOptionCard(
|
||||
optionIndex: 2,
|
||||
@@ -1493,6 +1509,15 @@ class _ChannelsScreenState extends State<ChannelsScreen>
|
||||
),
|
||||
if (selectedOption == 3)
|
||||
buildExpandedContent(_channelMessageStore)!,
|
||||
buildOptionCard(
|
||||
optionIndex: 1,
|
||||
icon: Icons.lock,
|
||||
title: sheetContext.l10n.channels_joinPrivateChannel,
|
||||
subtitle:
|
||||
sheetContext.l10n.channels_joinPrivateChannelDesc,
|
||||
),
|
||||
if (selectedOption == 1)
|
||||
buildExpandedContent(_channelMessageStore)!,
|
||||
buildOptionCard(
|
||||
optionIndex: 4,
|
||||
icon: Icons.qr_code_scanner,
|
||||
@@ -1501,6 +1526,18 @@ class _ChannelsScreenState extends State<ChannelsScreen>
|
||||
),
|
||||
if (selectedOption == 4)
|
||||
buildExpandedContent(_channelMessageStore)!,
|
||||
SectionHeader(
|
||||
sheetContext.l10n.channels_addSectionCreate,
|
||||
),
|
||||
buildOptionCard(
|
||||
optionIndex: 0,
|
||||
icon: Icons.add,
|
||||
title: sheetContext.l10n.channels_createPrivateChannel,
|
||||
subtitle:
|
||||
sheetContext.l10n.channels_createPrivateChannelDesc,
|
||||
),
|
||||
if (selectedOption == 0)
|
||||
buildExpandedContent(_channelMessageStore)!,
|
||||
buildOptionCard(
|
||||
optionIndex: 5,
|
||||
icon: Icons.groups,
|
||||
@@ -1737,6 +1774,12 @@ class _ChannelsScreenState extends State<ChannelsScreen>
|
||||
ChannelMessageStore channelMessageStore,
|
||||
Channel channel,
|
||||
) {
|
||||
ReceivedImageStore? imageStore;
|
||||
try {
|
||||
imageStore = context.read<ReceivedImageStore>();
|
||||
} on ProviderNotFoundException {
|
||||
imageStore = null;
|
||||
}
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (dialogContext) => AlertDialog(
|
||||
@@ -1756,6 +1799,7 @@ class _ChannelsScreenState extends State<ChannelsScreen>
|
||||
await connector.deleteChannel(channel.index);
|
||||
|
||||
await channelMessageStore.clearChannelMessages(channel.index);
|
||||
await imageStore?.deleteImagesForChannel(channel.index);
|
||||
|
||||
if (!context.mounted) return;
|
||||
|
||||
@@ -1800,12 +1844,12 @@ class _ChannelsScreenState extends State<ChannelsScreen>
|
||||
);
|
||||
}
|
||||
|
||||
int _findNextAvailableIndex(List<Channel> channels, int maxChannels) {
|
||||
int? _findNextAvailableIndex(List<Channel> channels, int maxChannels) {
|
||||
final usedIndices = channels.map((c) => c.index).toSet();
|
||||
for (int i = 0; i < maxChannels; i++) {
|
||||
if (!usedIndices.contains(i)) return i;
|
||||
}
|
||||
return 0;
|
||||
return null;
|
||||
}
|
||||
|
||||
void _showManageCommunitiesDialog(BuildContext context) {
|
||||
|
||||
@@ -31,6 +31,7 @@ import '../services/path_history_service.dart';
|
||||
import '../services/translation_service.dart';
|
||||
import '../widgets/chat_zoom_wrapper.dart';
|
||||
import '../widgets/byte_count_input.dart';
|
||||
import '../widgets/chat_day_separator.dart';
|
||||
import 'channel_message_path_screen.dart';
|
||||
import 'map_screen.dart';
|
||||
import '../widgets/emoji_picker.dart';
|
||||
@@ -189,10 +190,6 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
title: Consumer2<PathHistoryService, MeshCoreConnector>(
|
||||
builder: (context, pathService, connector, _) {
|
||||
final contact = _resolveContact(connector);
|
||||
final unreadCount = connector.getUnreadCountForContactKey(
|
||||
widget.contact.publicKeyHex,
|
||||
);
|
||||
final unreadLabel = context.l10n.chat_unread(unreadCount);
|
||||
final pathLabel = _currentPathLabel(contact);
|
||||
|
||||
return Column(
|
||||
@@ -211,7 +208,7 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 6),
|
||||
child: Text(
|
||||
'$pathLabel • $unreadLabel',
|
||||
pathLabel,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(
|
||||
fontSize: 11,
|
||||
@@ -435,10 +432,20 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
final isUnreadAnchor =
|
||||
_unreadDividerMessageId != null &&
|
||||
message.messageId == _unreadDividerMessageId;
|
||||
final child = isUnreadAnchor
|
||||
final startsDay =
|
||||
messageIndex == reversedMessages.length - 1 ||
|
||||
!isSameChatDay(
|
||||
reversedMessages[messageIndex + 1].timestamp,
|
||||
message.timestamp,
|
||||
);
|
||||
final child = isUnreadAnchor || startsDay
|
||||
? Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [const UnreadDivider(), bubble],
|
||||
children: [
|
||||
if (startsDay) ChatDaySeparator(day: message.timestamp),
|
||||
if (isUnreadAnchor) const UnreadDivider(),
|
||||
bubble,
|
||||
],
|
||||
)
|
||||
: bubble;
|
||||
if (identical(message, _pendingUnreadScrollTarget)) {
|
||||
@@ -479,26 +486,10 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
PopupMenuButton<String>(
|
||||
icon: const Icon(Icons.add_circle_outline),
|
||||
position: PopupMenuPosition.over,
|
||||
offset: const Offset(0, -64),
|
||||
tooltip: context.l10n.chat_selectSendAction,
|
||||
onSelected: (action) {
|
||||
if (action == 'gif') _showGifPicker(context);
|
||||
},
|
||||
itemBuilder: (context) => [
|
||||
PopupMenuItem(
|
||||
value: 'gif',
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.gif_box),
|
||||
const SizedBox(width: 12),
|
||||
Text(context.l10n.chat_sendGif),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
IconButton(
|
||||
icon: const Icon(Icons.gif_box_outlined),
|
||||
tooltip: context.l10n.chat_sendGif,
|
||||
onPressed: () => _showGifPicker(context),
|
||||
),
|
||||
if (settings.translationEnabled)
|
||||
MessageTranslationButton(
|
||||
@@ -546,6 +537,7 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
const SizedBox(width: 8),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.close),
|
||||
tooltip: context.l10n.chat_removeGif,
|
||||
onPressed: () {
|
||||
_textController.clear();
|
||||
_textFieldFocusNode.requestFocus();
|
||||
@@ -557,6 +549,11 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
}
|
||||
return ByteCountedTextField(
|
||||
maxBytes: maxBytes,
|
||||
softLimitBytes:
|
||||
maxTextPayloadBytesAfterFullLengthAttempts,
|
||||
softLimitNote: context.l10n.chat_longMessageRetryNote(
|
||||
maxFullLengthTextAttempt + 1,
|
||||
),
|
||||
controller: _textController,
|
||||
focusNode: _textFieldFocusNode,
|
||||
hintText: context.l10n.chat_typeMessage,
|
||||
@@ -827,7 +824,7 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
final hopCount = _displayHopCount(
|
||||
contact.path,
|
||||
contact.pathLength,
|
||||
connector.pathHashByteWidth,
|
||||
contact.pathHashWidth,
|
||||
);
|
||||
return context.l10n.chat_hopsCount(hopCount);
|
||||
}
|
||||
@@ -1116,7 +1113,11 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
void _openMessagePath(Message message, Contact contact) {
|
||||
void _openMessagePath(
|
||||
Message message,
|
||||
Contact contact, {
|
||||
bool openMap = false,
|
||||
}) {
|
||||
final connector = context.read<MeshCoreConnector>();
|
||||
final fourByteHex = message.fourByteRoomContactKey
|
||||
.map((b) => b.toRadixString(16).padLeft(2, '0'))
|
||||
@@ -1148,7 +1149,9 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => ChannelMessagePathScreen(message: pathMessage),
|
||||
builder: (context) => openMap
|
||||
? ChannelMessagePathMapScreen(message: pathMessage)
|
||||
: ChannelMessagePathScreen(message: pathMessage),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -1170,8 +1173,8 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
BottomSheetHeader(
|
||||
title: message.text.length > 40
|
||||
? '${message.text.substring(0, 40)}…'
|
||||
title: message.text.characters.length > 40
|
||||
? '${message.text.characters.take(40)}…'
|
||||
: message.text,
|
||||
),
|
||||
// Can't react to your own messages
|
||||
@@ -1192,6 +1195,15 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
_openMessagePath(message, contact);
|
||||
},
|
||||
),
|
||||
if (message.pathBytes.isNotEmpty)
|
||||
ListTile(
|
||||
leading: const Icon(Icons.map_outlined),
|
||||
title: Text(context.l10n.chat_viewPathOnMap),
|
||||
onTap: () {
|
||||
Navigator.pop(sheetContext);
|
||||
_openMessagePath(message, contact, openMap: true);
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.copy),
|
||||
title: Text(context.l10n.common_copy),
|
||||
@@ -1267,6 +1279,9 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
|
||||
void _copyMessageText(String text) {
|
||||
Clipboard.setData(ClipboardData(text: text));
|
||||
// Android shows its own clipboard chip; the snackbar is redundant there
|
||||
// and lingers over the input field after the chip dismisses.
|
||||
if (PlatformInfo.isAndroid) return;
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(context.l10n.chat_messageCopied),
|
||||
@@ -1623,16 +1638,16 @@ class _MessageBubble extends StatelessWidget {
|
||||
crossAxisAlignment: WrapCrossAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
_formatTime(message.timestamp),
|
||||
formatChatTime(context, message.timestamp),
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 10 * textScale,
|
||||
fontSize: 12 * textScale,
|
||||
color: metaColor,
|
||||
),
|
||||
),
|
||||
if (isOutgoing) ...[
|
||||
const SizedBox(width: 2),
|
||||
MessageStatusIcon(
|
||||
size: 12 * textScale,
|
||||
size: 16 * textScale,
|
||||
onColor: metaColor,
|
||||
isAcked:
|
||||
message.status ==
|
||||
@@ -1658,7 +1673,7 @@ class _MessageBubble extends StatelessWidget {
|
||||
Text(
|
||||
'${(message.tripTimeMs! / 1000).toStringAsFixed(1)}s',
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 9 * textScale,
|
||||
fontSize: 11 * textScale,
|
||||
color: isOutgoing
|
||||
? metaColor
|
||||
: scheme.tertiary,
|
||||
@@ -1837,12 +1852,6 @@ class _MessageBubble extends StatelessWidget {
|
||||
Widget _buildAvatar(String senderName) {
|
||||
return AvatarCircle(name: senderName, size: 32);
|
||||
}
|
||||
|
||||
String _formatTime(DateTime time) {
|
||||
final hour = time.hour.toString().padLeft(2, '0');
|
||||
final minute = time.minute.toString().padLeft(2, '0');
|
||||
return '$hour:$minute';
|
||||
}
|
||||
}
|
||||
|
||||
/// Deterministic name-to-hue mapping consistent with [AvatarCircle].
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:meshcore_open/connector/meshcore_connector.dart';
|
||||
import 'package:meshcore_open/models/companion_radio_stats.dart';
|
||||
import 'package:meshcore_open/screens/telemetry_screen.dart';
|
||||
import 'package:meshcore_open/l10n/l10n.dart';
|
||||
import 'package:meshcore_open/theme/mesh_theme.dart';
|
||||
import 'package:meshcore_open/widgets/mesh_ui.dart';
|
||||
@@ -46,8 +47,8 @@ class _CompanionRadioStatsScreenState extends State<CompanionRadioStatsScreen> {
|
||||
@override
|
||||
void dispose() {
|
||||
_connector?.radioStatsNotifier.removeListener(_onStatsUpdate);
|
||||
_connector?.releaseRadioStatsPolling();
|
||||
_connector?.setPollingInterval(30);
|
||||
_connector?.releaseRadioStatsPolling();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@@ -77,6 +78,18 @@ class _CompanionRadioStatsScreenState extends State<CompanionRadioStatsScreen> {
|
||||
appBar: AppBar(
|
||||
title: Text(l10n.radioStats_screenTitle),
|
||||
centerTitle: true,
|
||||
actions: [
|
||||
Selector<MeshCoreConnector, bool>(
|
||||
selector: (_, c) => c.isConnected,
|
||||
builder: (context, connected, _) => IconButton(
|
||||
icon: const Icon(Icons.thermostat),
|
||||
tooltip: l10n.contact_telemetry,
|
||||
onPressed: connected
|
||||
? () => pushSelfTelemetryScreen(context)
|
||||
: null,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
body: Selector<MeshCoreConnector, ({bool connected, bool supported})>(
|
||||
selector: (_, c) => (
|
||||
@@ -109,8 +122,8 @@ class _CompanionRadioStatsScreenState extends State<CompanionRadioStatsScreen> {
|
||||
padding: const EdgeInsets.symmetric(vertical: 8),
|
||||
children: [
|
||||
if (stats != null) ...[
|
||||
const SectionHeader(
|
||||
'Signal',
|
||||
SectionHeader(
|
||||
l10n.radioStats_sectionSignal,
|
||||
padding: EdgeInsets.fromLTRB(16, 16, 16, 8),
|
||||
),
|
||||
MeshCard(
|
||||
@@ -144,8 +157,8 @@ class _CompanionRadioStatsScreenState extends State<CompanionRadioStatsScreen> {
|
||||
],
|
||||
),
|
||||
),
|
||||
const SectionHeader(
|
||||
'Airtime',
|
||||
SectionHeader(
|
||||
l10n.radioStats_sectionAirtime,
|
||||
padding: EdgeInsets.fromLTRB(16, 16, 16, 8),
|
||||
),
|
||||
MeshCard(
|
||||
|
||||
@@ -0,0 +1,310 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'package:mobile_scanner/mobile_scanner.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../connector/meshcore_connector.dart';
|
||||
import '../connector/meshcore_protocol.dart';
|
||||
import '../helpers/snack_bar_builder.dart';
|
||||
import '../l10n/l10n.dart';
|
||||
import '../theme/mesh_theme.dart';
|
||||
import '../utils/contact_qr.dart';
|
||||
import '../utils/contact_qr_frame.dart';
|
||||
import '../widgets/adaptive_app_bar_title.dart';
|
||||
import '../widgets/qr_scanner_widget.dart';
|
||||
|
||||
/// Screen for scanning MeshCore contact QR codes, either with the camera
|
||||
/// or by picking a photo containing a QR code from the gallery.
|
||||
class ContactQrScannerScreen extends StatefulWidget {
|
||||
const ContactQrScannerScreen({super.key});
|
||||
|
||||
@override
|
||||
State<ContactQrScannerScreen> createState() => _ContactQrScannerScreenState();
|
||||
}
|
||||
|
||||
class _ContactQrScannerScreenState extends State<ContactQrScannerScreen> {
|
||||
bool _isProcessing = false;
|
||||
|
||||
/// Set after a failed import so the camera does not immediately rescan the
|
||||
/// same QR and resend the frame in a loop.
|
||||
bool _importFailed = false;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: AdaptiveAppBarTitle(context.l10n.contacts_scanQrCode),
|
||||
centerTitle: true,
|
||||
actions: [
|
||||
IconButton(
|
||||
tooltip: context.l10n.contacts_qrFromGallery,
|
||||
icon: const Icon(Icons.photo_library),
|
||||
onPressed: _isProcessing ? null : _pickFromGallery,
|
||||
),
|
||||
],
|
||||
),
|
||||
body: _isProcessing
|
||||
? Container(
|
||||
color: Theme.of(context).colorScheme.surface,
|
||||
child: const Center(child: CircularProgressIndicator()),
|
||||
)
|
||||
: _importFailed
|
||||
? _buildImportFailed(context)
|
||||
: QrScannerWidget(
|
||||
onScanned: (data) => _handleScannedData(data),
|
||||
validator: (data) => parseContactQr(data) != null,
|
||||
onValidationFailed: (_) => _showInvalidQrError(),
|
||||
instructions: context.l10n.contacts_scanQrInstructions,
|
||||
overlay: _buildThemedOverlay(context),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildImportFailed(BuildContext context) {
|
||||
return Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.error_outline,
|
||||
size: 64,
|
||||
color: Theme.of(context).colorScheme.error,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
context.l10n.contacts_contactImportFailed,
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
FilledButton.icon(
|
||||
onPressed: () => setState(() => _importFailed = false),
|
||||
icon: const Icon(Icons.refresh),
|
||||
label: Text(context.l10n.common_retry),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildThemedOverlay(BuildContext context) {
|
||||
return Stack(
|
||||
fit: StackFit.expand,
|
||||
children: [
|
||||
// Dark semi-transparent background with cutout
|
||||
ColorFiltered(
|
||||
colorFilter: ColorFilter.mode(
|
||||
Colors.black.withValues(alpha: 0.5),
|
||||
BlendMode.srcOut,
|
||||
),
|
||||
child: Stack(
|
||||
fit: StackFit.expand,
|
||||
children: [
|
||||
Container(
|
||||
decoration: const BoxDecoration(
|
||||
color: Colors.black,
|
||||
backgroundBlendMode: BlendMode.dstOut,
|
||||
),
|
||||
),
|
||||
Center(
|
||||
child: Container(
|
||||
height: 250,
|
||||
width: 250,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.red,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
// Corner brackets on top
|
||||
const ScannerCornerOverlay(
|
||||
scanWindowSize: 250,
|
||||
borderColor: MeshPalette.blue,
|
||||
borderWidth: 2,
|
||||
cornerLength: 24,
|
||||
),
|
||||
// Instructions pill below the scan window
|
||||
Center(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const SizedBox(height: 250 + 24),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 20,
|
||||
vertical: 10,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.black.withValues(alpha: 0.72),
|
||||
borderRadius: BorderRadius.circular(MeshRadii.pill),
|
||||
),
|
||||
child: Text(
|
||||
context.l10n.contacts_scanQrInstructions,
|
||||
style: const TextStyle(color: MeshPalette.ink2, fontSize: 13),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _pickFromGallery() async {
|
||||
if (_isProcessing) return;
|
||||
|
||||
// Claim the flag before awaiting the picker, otherwise a camera detection
|
||||
// can start a second import while the gallery sheet is open.
|
||||
setState(() {
|
||||
_isProcessing = true;
|
||||
});
|
||||
|
||||
final XFile? image;
|
||||
try {
|
||||
image = await ImagePicker().pickImage(source: ImageSource.gallery);
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_isProcessing = false;
|
||||
});
|
||||
_showGalleryError();
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (!mounted) return;
|
||||
if (image == null) {
|
||||
setState(() {
|
||||
_isProcessing = false;
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
String? rawValue;
|
||||
bool decodedAnyBarcode = false;
|
||||
final controller = MobileScannerController();
|
||||
try {
|
||||
final capture = await controller.analyzeImage(image.path);
|
||||
for (final barcode in capture?.barcodes ?? const []) {
|
||||
final value = barcode.rawValue;
|
||||
if (value == null || value.isEmpty) continue;
|
||||
decodedAnyBarcode = true;
|
||||
if (parseContactQr(value) != null) {
|
||||
rawValue = value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} on UnsupportedError {
|
||||
rawValue = null;
|
||||
} catch (e) {
|
||||
rawValue = null;
|
||||
} finally {
|
||||
controller.dispose();
|
||||
}
|
||||
|
||||
if (!mounted) return;
|
||||
|
||||
if (rawValue == null) {
|
||||
setState(() {
|
||||
_isProcessing = false;
|
||||
});
|
||||
if (decodedAnyBarcode) {
|
||||
_showInvalidQrError();
|
||||
} else {
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(context.l10n.contacts_noQrCodeFound),
|
||||
backgroundColor: MeshPalette.warn,
|
||||
duration: const Duration(seconds: 2),
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
setState(() {
|
||||
_isProcessing = false;
|
||||
});
|
||||
await _handleScannedData(rawValue);
|
||||
}
|
||||
|
||||
Future<void> _handleScannedData(String data) async {
|
||||
if (_isProcessing) return;
|
||||
|
||||
setState(() {
|
||||
_isProcessing = true;
|
||||
_importFailed = false;
|
||||
});
|
||||
|
||||
final scanned = parseContactQr(data);
|
||||
if (scanned == null) {
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_isProcessing = false;
|
||||
});
|
||||
_showInvalidQrError();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
final connector = Provider.of<MeshCoreConnector>(context, listen: false);
|
||||
final publicKey = scanned.publicKey;
|
||||
// Saved contacts first (their flags matter), then discovery-only records,
|
||||
// which still carry a known name worth preserving.
|
||||
final existing = publicKey == null
|
||||
? null
|
||||
: connector.allContactsUnfiltered
|
||||
.where(
|
||||
(contact) => contact.publicKeyHex == pubKeyToHex(publicKey),
|
||||
)
|
||||
.firstOrNull;
|
||||
final frame = buildContactQrFrame(
|
||||
scanned,
|
||||
existing: existing,
|
||||
pathHashByteWidth: connector.pathHashByteWidth,
|
||||
);
|
||||
|
||||
try {
|
||||
await connector.sendFrame(frame, waitForGenericAck: true);
|
||||
await connector.refreshContacts();
|
||||
if (!mounted) return;
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(context.l10n.contacts_contactImported),
|
||||
);
|
||||
// Keep _isProcessing set: resetting it would restart the camera on a
|
||||
// closing route and let a second detection import and pop again.
|
||||
Navigator.pop(context);
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_isProcessing = false;
|
||||
_importFailed = true;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void _showInvalidQrError() {
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(context.l10n.contacts_invalidAdvertFormat),
|
||||
backgroundColor: MeshPalette.warn,
|
||||
duration: const Duration(seconds: 2),
|
||||
);
|
||||
}
|
||||
|
||||
void _showGalleryError() {
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(context.l10n.contacts_qrGalleryFailed),
|
||||
backgroundColor: MeshPalette.warn,
|
||||
duration: const Duration(seconds: 2),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -34,8 +34,10 @@ import '../widgets/unread_badge.dart';
|
||||
import '../helpers/snack_bar_builder.dart';
|
||||
import 'channels_screen.dart';
|
||||
import 'chat_screen.dart';
|
||||
import 'contact_qr_scanner_screen.dart';
|
||||
import 'discovery_screen.dart';
|
||||
import 'map_screen.dart';
|
||||
import '../review_mode/review_mode_banner.dart';
|
||||
import 'repeater_hub_screen.dart';
|
||||
import 'settings_screen.dart';
|
||||
|
||||
@@ -185,6 +187,14 @@ class _ContactsScreenState extends State<ContactsScreen>
|
||||
}
|
||||
final hexString = pubKeyToHex(advertPacket);
|
||||
Clipboard.setData(ClipboardData(text: "meshcore://$hexString"));
|
||||
_pendingOperations.remove(ContactOperationType.export);
|
||||
if (mounted) {
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(context.l10n.contacts_contactAdvertCopied),
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Generic OK/ERR acks carry no command correlation, so consume only
|
||||
@@ -376,6 +386,21 @@ class _ContactsScreenState extends State<ContactsScreen>
|
||||
),
|
||||
onTap: () => _contactImport(),
|
||||
),
|
||||
PopupMenuItem(
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.qr_code_scanner),
|
||||
const SizedBox(width: 8),
|
||||
Text(context.l10n.contacts_scanQrCode),
|
||||
],
|
||||
),
|
||||
onTap: () => Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => const ContactQrScannerScreen(),
|
||||
),
|
||||
),
|
||||
),
|
||||
const PopupMenuDivider(),
|
||||
PopupMenuItem(
|
||||
child: Row(
|
||||
@@ -453,7 +478,12 @@ class _ContactsScreenState extends State<ContactsScreen>
|
||||
),
|
||||
],
|
||||
),
|
||||
body: _buildContactsBody(context, connector),
|
||||
body: Column(
|
||||
children: [
|
||||
const ReviewModeBanner(),
|
||||
Expanded(child: _buildContactsBody(context, connector)),
|
||||
],
|
||||
),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
onPressed: () => _showAddContactSheet(context),
|
||||
child: const Icon(Icons.person_add),
|
||||
@@ -488,6 +518,19 @@ class _ContactsScreenState extends State<ContactsScreen>
|
||||
_contactImport();
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.qr_code_scanner),
|
||||
title: Text(context.l10n.contacts_scanQrCode),
|
||||
onTap: () {
|
||||
Navigator.pop(sheetContext);
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => const ContactQrScannerScreen(),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.person_add_rounded),
|
||||
title: Text(context.l10n.discoveredContacts_Title),
|
||||
@@ -704,7 +747,7 @@ class _ContactsScreenState extends State<ContactsScreen>
|
||||
return EmptyState(
|
||||
icon: Icons.people_outline,
|
||||
title: context.l10n.contacts_noContacts,
|
||||
subtitle: context.l10n.contacts_contactsWillAppear,
|
||||
subtitle: context.l10n.contacts_noContactsDiscoveredHint,
|
||||
action: FilledButton.icon(
|
||||
onPressed: () => Navigator.push(
|
||||
context,
|
||||
@@ -882,6 +925,45 @@ class _ContactsScreenState extends State<ContactsScreen>
|
||||
],
|
||||
),
|
||||
),
|
||||
if (connector.contactsStorageFull)
|
||||
Container(
|
||||
width: double.infinity,
|
||||
color: Theme.of(context).colorScheme.errorContainer,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 10),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.warning_amber_rounded,
|
||||
size: 18,
|
||||
color: Theme.of(context).colorScheme.onErrorContainer,
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: Text(
|
||||
context.l10n.contacts_storageFull,
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
color: Theme.of(context).colorScheme.onErrorContainer,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
ListTile(
|
||||
dense: true,
|
||||
leading: const Icon(Icons.person_add_rounded),
|
||||
title: Text(
|
||||
context.l10n.contacts_discoveredNearby(
|
||||
connector.discoveredContacts.where((c) => !c.isActive).length,
|
||||
),
|
||||
),
|
||||
trailing: const Icon(Icons.chevron_right),
|
||||
onTap: () => Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) => const DiscoveryScreen()),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: RefreshIndicator(
|
||||
onRefresh: () => connector.getContacts(),
|
||||
@@ -922,6 +1004,7 @@ class _ContactsScreenState extends State<ContactsScreen>
|
||||
onTap: () => _openChat(context, contact),
|
||||
onLongPress: () =>
|
||||
_showContactOptions(context, connector, contact),
|
||||
onManage: _manageAction(context, contact),
|
||||
);
|
||||
},
|
||||
),
|
||||
@@ -1047,6 +1130,17 @@ class _ContactsScreenState extends State<ContactsScreen>
|
||||
}
|
||||
}
|
||||
|
||||
VoidCallback? _manageAction(BuildContext context, Contact contact) {
|
||||
if (contact.type == advTypeRepeater) {
|
||||
return () => _showRepeaterLogin(context, contact);
|
||||
}
|
||||
if (contact.type == advTypeRoom) {
|
||||
return () =>
|
||||
_showRoomLogin(context, contact, RoomLoginDestination.management);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
void _handleQuickSwitch(int index, BuildContext context) {
|
||||
if (index == 0) return;
|
||||
switch (index) {
|
||||
@@ -1505,7 +1599,7 @@ class _ContactsScreenState extends State<ContactsScreen>
|
||||
color: Theme.of(context).colorScheme.error,
|
||||
),
|
||||
title: Text(
|
||||
context.l10n.contacts_deleteContact,
|
||||
context.l10n.contacts_removeFromContacts,
|
||||
style: TextStyle(color: Theme.of(context).colorScheme.error),
|
||||
),
|
||||
onTap: () {
|
||||
@@ -1535,27 +1629,46 @@ class _ContactsScreenState extends State<ContactsScreen>
|
||||
MeshCoreConnector connector,
|
||||
Contact contact,
|
||||
) {
|
||||
var keepHistory = false;
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (dialogContext) => AlertDialog(
|
||||
title: Text(context.l10n.contacts_deleteContact),
|
||||
content: Text(context.l10n.contacts_removeConfirm(contact.name)),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(dialogContext),
|
||||
child: Text(context.l10n.common_cancel),
|
||||
builder: (dialogContext) => StatefulBuilder(
|
||||
builder: (dialogContext, setDialogState) => AlertDialog(
|
||||
title: Text(context.l10n.contacts_removeFromContacts),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
context.l10n.contacts_removeFromContactsConfirm(contact.name),
|
||||
),
|
||||
CheckboxListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
controlAffinity: ListTileControlAffinity.leading,
|
||||
value: keepHistory,
|
||||
title: Text(context.l10n.contacts_keepChatHistory),
|
||||
onChanged: (value) =>
|
||||
setDialogState(() => keepHistory = value ?? false),
|
||||
),
|
||||
],
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(dialogContext);
|
||||
connector.removeContact(contact);
|
||||
},
|
||||
child: Text(
|
||||
context.l10n.common_delete,
|
||||
style: TextStyle(color: Theme.of(context).colorScheme.error),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(dialogContext),
|
||||
child: Text(context.l10n.common_cancel),
|
||||
),
|
||||
),
|
||||
],
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(dialogContext);
|
||||
connector.removeContact(contact, keepMessages: keepHistory);
|
||||
},
|
||||
child: Text(
|
||||
context.l10n.contacts_remove,
|
||||
style: TextStyle(color: Theme.of(context).colorScheme.error),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -1569,6 +1682,7 @@ class _ContactTile extends StatelessWidget {
|
||||
final bool isFavorite;
|
||||
final VoidCallback onTap;
|
||||
final VoidCallback onLongPress;
|
||||
final VoidCallback? onManage;
|
||||
|
||||
const _ContactTile({
|
||||
required this.contact,
|
||||
@@ -1578,6 +1692,7 @@ class _ContactTile extends StatelessWidget {
|
||||
required this.isFavorite,
|
||||
required this.onTap,
|
||||
required this.onLongPress,
|
||||
this.onManage,
|
||||
});
|
||||
|
||||
/// Node-type avatar color per design language.
|
||||
@@ -1614,9 +1729,6 @@ class _ContactTile extends StatelessWidget {
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
final emoji = firstEmoji(contact.name);
|
||||
final isChat = contact.type == advTypeChat;
|
||||
final pathLen = contact.pathBytesForDisplay.length;
|
||||
final isDirect = contact.pathLength >= 0;
|
||||
final hasPath = pathLen > 0 || contact.pathLength == 0;
|
||||
|
||||
return GestureDetector(
|
||||
onSecondaryTapUp: PlatformInfo.isDesktop ? (_) => onLongPress() : null,
|
||||
@@ -1704,13 +1816,6 @@ class _ContactTile extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
),
|
||||
if (hasPath) ...[
|
||||
const SizedBox(width: 6),
|
||||
RouteChip(
|
||||
isDirect: isDirect,
|
||||
hops: isDirect ? contact.pathLength : null,
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
],
|
||||
@@ -1749,6 +1854,15 @@ class _ContactTile extends StatelessWidget {
|
||||
],
|
||||
),
|
||||
),
|
||||
if (onManage != null)
|
||||
IconButton(
|
||||
icon: const Icon(Icons.admin_panel_settings_outlined),
|
||||
tooltip: contact.type == advTypeRoom
|
||||
? context.l10n.room_management
|
||||
: context.l10n.contacts_manageRepeater,
|
||||
visualDensity: VisualDensity.compact,
|
||||
onPressed: onManage,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -1788,6 +1902,7 @@ class _ContactTileEntrance extends StatelessWidget {
|
||||
final bool isFavorite;
|
||||
final VoidCallback onTap;
|
||||
final VoidCallback onLongPress;
|
||||
final VoidCallback? onManage;
|
||||
|
||||
const _ContactTileEntrance({
|
||||
required this.index,
|
||||
@@ -1798,6 +1913,7 @@ class _ContactTileEntrance extends StatelessWidget {
|
||||
required this.isFavorite,
|
||||
required this.onTap,
|
||||
required this.onLongPress,
|
||||
this.onManage,
|
||||
});
|
||||
|
||||
@override
|
||||
@@ -1812,6 +1928,7 @@ class _ContactTileEntrance extends StatelessWidget {
|
||||
isFavorite: isFavorite,
|
||||
onTap: onTap,
|
||||
onLongPress: onLongPress,
|
||||
onManage: onManage,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -34,9 +34,17 @@ class _DiscoveryScreenState extends State<DiscoveryScreen> {
|
||||
ContactTypeFilter typeFilter = ContactTypeFilter.all;
|
||||
DiscoverySortOption discoverySortOption = DiscoverySortOption.lastSeen;
|
||||
Timer? _searchDebounce;
|
||||
ScaffoldMessengerState? _messenger;
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
_messenger = ScaffoldMessenger.maybeOf(context);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_messenger?.hideCurrentSnackBar();
|
||||
_searchController.dispose();
|
||||
_searchDebounce?.cancel();
|
||||
super.dispose();
|
||||
@@ -169,33 +177,7 @@ class _DiscoveryScreenState extends State<DiscoveryScreen> {
|
||||
return ListEntrance(
|
||||
index: index,
|
||||
child: MeshCard(
|
||||
onTap: () async {
|
||||
try {
|
||||
final imported = await connector.importDiscoveredContact(contact);
|
||||
if (!context.mounted) return;
|
||||
if (!imported) {
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(context.l10n.contacts_contactImportFailed),
|
||||
);
|
||||
return;
|
||||
}
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(context.l10n.discoveredContacts_contactAdded),
|
||||
action: SnackBarAction(
|
||||
label: context.l10n.common_undo,
|
||||
onPressed: () => connector.removeContact(contact),
|
||||
),
|
||||
);
|
||||
} catch (_) {
|
||||
if (!context.mounted) return;
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(context.l10n.contacts_contactImportFailed),
|
||||
);
|
||||
}
|
||||
},
|
||||
onTap: () => _addContact(context, contact, connector),
|
||||
onLongPress: () => _showContactContextMenu(contact, connector),
|
||||
onSecondaryTap: PlatformInfo.isDesktop
|
||||
? () => _showContactContextMenu(contact, connector)
|
||||
@@ -296,12 +278,49 @@ class _DiscoveryScreenState extends State<DiscoveryScreen> {
|
||||
),
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
tooltip: context.l10n.discoveredContacts_addContact,
|
||||
icon: const Icon(Icons.person_add_alt_1),
|
||||
onPressed: () => _addContact(context, contact, connector),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _addContact(
|
||||
BuildContext context,
|
||||
Contact contact,
|
||||
MeshCoreConnector connector,
|
||||
) async {
|
||||
try {
|
||||
final imported = await connector.importDiscoveredContact(contact);
|
||||
if (!context.mounted) return;
|
||||
if (!imported) {
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(context.l10n.contacts_contactImportFailed),
|
||||
);
|
||||
return;
|
||||
}
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(context.l10n.discoveredContacts_contactAdded),
|
||||
action: SnackBarAction(
|
||||
label: context.l10n.common_undo,
|
||||
onPressed: () => connector.removeContact(contact),
|
||||
),
|
||||
);
|
||||
} catch (_) {
|
||||
if (!context.mounted) return;
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(context.l10n.contacts_contactImportFailed),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _showContactContextMenu(
|
||||
Contact contact,
|
||||
MeshCoreConnector connector,
|
||||
@@ -431,6 +450,7 @@ class _DiscoveryScreenState extends State<DiscoveryScreen> {
|
||||
if (searchQuery.isNotEmpty)
|
||||
IconButton(
|
||||
icon: const Icon(Icons.clear),
|
||||
tooltip: context.l10n.common_clearSearch,
|
||||
onPressed: () {
|
||||
_searchController.clear();
|
||||
setState(() {
|
||||
|
||||
+319
-259
@@ -1,3 +1,4 @@
|
||||
import 'dart:async';
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
@@ -16,12 +17,15 @@ import '../l10n/l10n.dart';
|
||||
import '../models/app_settings.dart';
|
||||
import '../models/channel.dart';
|
||||
import '../models/contact.dart';
|
||||
import '../models/path_history.dart';
|
||||
import '../l10n/contact_localization.dart';
|
||||
import '../services/app_settings_service.dart';
|
||||
import '../services/path_history_service.dart';
|
||||
import '../services/map_marker_service.dart';
|
||||
import '../services/map_tile_cache_service.dart';
|
||||
import '../storage/prefs_manager.dart';
|
||||
import '../utils/contact_search.dart';
|
||||
import '../utils/disconnect_navigation_mixin.dart';
|
||||
import '../utils/battery_utils.dart';
|
||||
import '../utils/route_transitions.dart';
|
||||
import '../widgets/quick_switch_bar.dart';
|
||||
@@ -34,6 +38,7 @@ import '../theme/mesh_theme.dart';
|
||||
import '../widgets/mesh_ui.dart';
|
||||
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 'repeater_hub_screen.dart';
|
||||
import 'settings_screen.dart';
|
||||
@@ -59,7 +64,7 @@ class MapScreen extends StatefulWidget {
|
||||
State<MapScreen> createState() => _MapScreenState();
|
||||
}
|
||||
|
||||
class _MapScreenState extends State<MapScreen> {
|
||||
class _MapScreenState extends State<MapScreen> with DisconnectNavigationMixin {
|
||||
// Zoom level at which node labels start to appear
|
||||
static const double _labelZoomThreshold = 14.0;
|
||||
// Below this zoom, nearby nodes collapse into clusters.
|
||||
@@ -93,15 +98,51 @@ class _MapScreenState extends State<MapScreen> {
|
||||
final FocusNode _searchFocus = FocusNode();
|
||||
String _searchQuery = '';
|
||||
List<_GuessedLocation> _cachedGuessedLocations = [];
|
||||
String _guessedLocationsCacheKey = '';
|
||||
int? _guessedLocationsCacheKey;
|
||||
static const Duration _guessMaxAge = Duration(days: 7);
|
||||
({LatLng center, double zoom})? _cachedFallbackCamera;
|
||||
bool _guessInFlight = false;
|
||||
VoidCallback? _guessRerun;
|
||||
// Saved paths for contacts outside the path-history cache, read once.
|
||||
final Map<String, List<PathRecord>> _storedPaths = {};
|
||||
int? _sharedMarkersCacheSignature;
|
||||
Locale? _sharedMarkersCacheLocale;
|
||||
List<_SharedMarker> _cachedSharedMarkers = const [];
|
||||
_NodeMarkersCacheKey? _nodeMarkersCacheKey;
|
||||
List<Marker> _cachedNodeMarkers = const [];
|
||||
|
||||
static const String _lastCameraKey = 'map_last_camera';
|
||||
|
||||
({LatLng center, double zoom}) _fallbackCamera(MeshCoreConnector connector) {
|
||||
final lat = connector.selfLatitude;
|
||||
final lon = connector.selfLongitude;
|
||||
if (lat != null && lon != null && isPlausibleLocation(lat, lon)) {
|
||||
return (center: LatLng(lat, lon), zoom: 12.0);
|
||||
}
|
||||
final saved = PrefsManager.instance.getStringList(_lastCameraKey);
|
||||
if (saved != null && saved.length == 3) {
|
||||
final values = saved.map(double.tryParse).toList();
|
||||
if (!values.contains(null)) {
|
||||
return (center: LatLng(values[0]!, values[1]!), zoom: values[2]!);
|
||||
}
|
||||
}
|
||||
return (center: const LatLng(20, 0), zoom: _mapMinZoom);
|
||||
}
|
||||
|
||||
void _saveLastCamera() {
|
||||
try {
|
||||
final camera = _mapController.camera;
|
||||
PrefsManager.instance.setStringList(_lastCameraKey, [
|
||||
camera.center.latitude.toString(),
|
||||
camera.center.longitude.toString(),
|
||||
camera.zoom.toString(),
|
||||
]);
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_saveLastCamera();
|
||||
_searchController.dispose();
|
||||
_searchFocus.dispose();
|
||||
_mapController.dispose();
|
||||
@@ -194,15 +235,6 @@ class _MapScreenState extends State<MapScreen> {
|
||||
}
|
||||
}
|
||||
|
||||
bool _checkLocationPlausibility(double lat, double lon) {
|
||||
const double epsilon = 1e-6;
|
||||
return (lat.abs() > epsilon || lon.abs() > epsilon) &&
|
||||
lat >= -90.0 &&
|
||||
lat <= 90.0 &&
|
||||
lon >= -180.0 &&
|
||||
lon <= 180.0;
|
||||
}
|
||||
|
||||
double _standardDeviation(List<double> values) {
|
||||
if (values.length <= 1) {
|
||||
return 0.0;
|
||||
@@ -298,7 +330,7 @@ class _MapScreenState extends State<MapScreen> {
|
||||
IconButton(
|
||||
color: MapPalette.selected,
|
||||
icon: const Icon(Icons.my_location),
|
||||
tooltip: context.l10n.map_setAsMyLocation,
|
||||
tooltip: context.l10n.map_centerOnMe,
|
||||
onPressed: () => _mapController.move(
|
||||
LatLng(connector.selfLatitude!, connector.selfLongitude!),
|
||||
max(_zoom, 14),
|
||||
@@ -345,6 +377,9 @@ class _MapScreenState extends State<MapScreen> {
|
||||
_MapConnectorSnapshot.fromConnector,
|
||||
);
|
||||
final connector = connectorSnapshot.connector;
|
||||
if (!checkConnectionAndNavigate(connector)) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
final settings = context.select<AppSettingsService, AppSettings>(
|
||||
(service) => service.settings,
|
||||
);
|
||||
@@ -426,33 +461,42 @@ class _MapScreenState extends State<MapScreen> {
|
||||
noLocations: true,
|
||||
);
|
||||
|
||||
// Compute guessed locations with caching
|
||||
// Guessed locations are computed in a background isolate; the last
|
||||
// result stays on screen until the new one arrives.
|
||||
final maxRangeKm = _estimateLoRaRangeKm(connector);
|
||||
final pathHashByteWidth = connector.pathHashByteWidth
|
||||
.clamp(1, 4)
|
||||
.toInt();
|
||||
final filteredKeys = guessCandidates
|
||||
.map((c) => '${c.publicKeyHex}:${c.path.join("-")}')
|
||||
.join(',');
|
||||
final anchorKeys = allContactsWithLocation
|
||||
.map(
|
||||
final cacheKey = Object.hash(
|
||||
Object.hashAll(
|
||||
guessCandidates.map(
|
||||
(c) => Object.hash(c.publicKeyHex, _bytesSignature(c.path)),
|
||||
),
|
||||
),
|
||||
Object.hashAll(
|
||||
allContactsWithLocation.map(
|
||||
(c) =>
|
||||
'${c.publicKeyHex}:${c.latitude}:${c.longitude}:${PathHelper.formatHopHex(c.path.isNotEmpty ? c.path.sublist(max(0, c.path.length - pathHashByteWidth)) : const [])}',
|
||||
)
|
||||
.join(',');
|
||||
final cacheKey =
|
||||
'$filteredKeys|$anchorKeys|$pathHistoryVersion:$pathHashByteWidth:${connector.currentFreqHz}:${connector.currentSf}:${connector.currentBwHz}:${connector.currentTxPower}:${settings.mapShowGuessedLocations}';
|
||||
Object.hash(c.publicKeyHex, c.latitude, c.longitude, c.type),
|
||||
),
|
||||
),
|
||||
pathHistoryVersion,
|
||||
maxRangeKm,
|
||||
connector.selfLatitude,
|
||||
connector.selfLongitude,
|
||||
settings.mapShowGuessedLocations,
|
||||
);
|
||||
if (cacheKey != _guessedLocationsCacheKey) {
|
||||
_guessedLocationsCacheKey = cacheKey;
|
||||
_cachedGuessedLocations = settings.mapShowGuessedLocations
|
||||
? _computeGuessedLocations(
|
||||
guessCandidates,
|
||||
allContactsWithLocation,
|
||||
pathHistory,
|
||||
maxRangeKm,
|
||||
pathHashByteWidth,
|
||||
)
|
||||
: [];
|
||||
if (settings.mapShowGuessedLocations) {
|
||||
unawaited(
|
||||
_startGuessedLocations(
|
||||
cacheKey,
|
||||
guessCandidates,
|
||||
allContactsWithLocation,
|
||||
pathHistory,
|
||||
maxRangeKm,
|
||||
),
|
||||
);
|
||||
} else {
|
||||
_cachedGuessedLocations = [];
|
||||
}
|
||||
}
|
||||
final guessedLocations = settings.mapShowGuessedLocations
|
||||
? _cachedGuessedLocations
|
||||
@@ -491,14 +535,13 @@ class _MapScreenState extends State<MapScreen> {
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate center and zoom of all nodes, or default to (0, 0)
|
||||
LatLng center = const LatLng(0, 0);
|
||||
double initialZoom = 10.0;
|
||||
final hasMapContent =
|
||||
contactsWithLocation.isNotEmpty ||
|
||||
sharedMarkers.isNotEmpty ||
|
||||
_isSelectingPoi ||
|
||||
highlightPosition != null;
|
||||
// Only the first frame's camera matters; afterwards reuse it instead
|
||||
// of re-reading prefs on every rebuild.
|
||||
final (center: fallbackCenter, zoom: fallbackZoom) = _hasInitializedMap
|
||||
? (_cachedFallbackCamera ??= _fallbackCamera(connector))
|
||||
: _fallbackCamera(connector);
|
||||
LatLng center = fallbackCenter;
|
||||
double initialZoom = fallbackZoom;
|
||||
if (contactsWithLocation.isNotEmpty || sharedMarkers.isNotEmpty) {
|
||||
final allPoints = [
|
||||
...contactsWithLocation.map(
|
||||
@@ -573,13 +616,11 @@ class _MapScreenState extends State<MapScreen> {
|
||||
_hasInitializedMap = true;
|
||||
_showNodeLabels = initialZoom >= _labelZoomThreshold;
|
||||
_zoom = initialZoom;
|
||||
if (hasMapContent) {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (mounted) {
|
||||
_mapController.move(center, initialZoom);
|
||||
}
|
||||
});
|
||||
}
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (mounted) {
|
||||
_mapController.move(center, initialZoom);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
final allowBack = !connector.isConnected;
|
||||
@@ -769,6 +810,12 @@ class _MapScreenState extends State<MapScreen> {
|
||||
onSecondaryTap: (_, latLng) {
|
||||
_handleMapContextPress(context, connector, latLng);
|
||||
},
|
||||
onMapEvent: (event) {
|
||||
if (event is MapEventMoveEnd ||
|
||||
event is MapEventFlingAnimationEnd) {
|
||||
_saveLastCamera();
|
||||
}
|
||||
},
|
||||
onPositionChanged: (camera, hasGesture) {
|
||||
// Track zoom in half-step buckets so cluster/marker
|
||||
// detail levels update without rebuilding every frame.
|
||||
@@ -925,6 +972,20 @@ class _MapScreenState extends State<MapScreen> {
|
||||
pinCount: sharedMarkers.length,
|
||||
),
|
||||
if (_isBuildingPathTrace) _buildPathTraceOverlay(),
|
||||
if (contactsWithLocation.isEmpty &&
|
||||
selectedContact == null &&
|
||||
!_isBuildingPathTrace)
|
||||
Positioned(
|
||||
left: 16,
|
||||
right: 88,
|
||||
bottom: 16,
|
||||
child: Card(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(12),
|
||||
child: Text(context.l10n.map_noNodesLocationHint),
|
||||
),
|
||||
),
|
||||
),
|
||||
if (selectedContact != null && !_isBuildingPathTrace)
|
||||
_buildSelectedNodeCard(context, selectedContact, connector),
|
||||
],
|
||||
@@ -992,6 +1053,7 @@ class _MapScreenState extends State<MapScreen> {
|
||||
showChatNodes: settings.mapShowChatNodes,
|
||||
showOtherNodes: settings.mapShowOtherNodes,
|
||||
isBuildingPathTrace: _isBuildingPathTrace,
|
||||
clusterNodes: settings.mapClusterNodes,
|
||||
);
|
||||
if (key != _nodeMarkersCacheKey) {
|
||||
_nodeMarkersCacheKey = key;
|
||||
@@ -1007,141 +1069,100 @@ class _MapScreenState extends State<MapScreen> {
|
||||
return _cachedNodeMarkers;
|
||||
}
|
||||
|
||||
List<_GuessedLocation> _computeGuessedLocations(
|
||||
List<Contact> allContacts,
|
||||
Future<void> _startGuessedLocations(
|
||||
int cacheKey,
|
||||
List<Contact> candidates,
|
||||
List<Contact> withLocation,
|
||||
PathHistoryService pathHistory,
|
||||
double? maxRangeKm,
|
||||
int pathHashByteWidth,
|
||||
) {
|
||||
final result = <_GuessedLocation>[];
|
||||
final hopWidth = pathHashByteWidth.clamp(1, 4).toInt();
|
||||
final anchorsByPrefix = <String, List<Contact>>{};
|
||||
for (final repeater in withLocation) {
|
||||
if (repeater.type != advTypeRepeater) continue;
|
||||
if (repeater.publicKey.length < hopWidth) continue;
|
||||
final prefix = PathHelper.formatHopHex(
|
||||
repeater.publicKey.sublist(0, hopWidth),
|
||||
) async {
|
||||
if (_guessInFlight) {
|
||||
_guessRerun = () => _startGuessedLocations(
|
||||
cacheKey,
|
||||
candidates,
|
||||
withLocation,
|
||||
pathHistory,
|
||||
maxRangeKm,
|
||||
);
|
||||
anchorsByPrefix.putIfAbsent(prefix, () => []).add(repeater);
|
||||
return;
|
||||
}
|
||||
|
||||
for (final contact in allContacts) {
|
||||
if (contact.hasLocation) continue;
|
||||
if (contact.lastSeen.isBefore(
|
||||
DateTime.now().subtract(const Duration(hours: 24)),
|
||||
)) {
|
||||
continue; // skip stale contacts
|
||||
}
|
||||
|
||||
final anchorSet = <LatLng>{};
|
||||
|
||||
// Collect the contact-side (last-hop) repeater from every known path.
|
||||
// path = [device-side hop, ..., contact-side hop]
|
||||
// Only the last hop chunk is actually within radio range of the contact.
|
||||
final pathSets = <List<int>>[
|
||||
contact.path.toList(),
|
||||
...pathHistory
|
||||
.getRecentPaths(contact.publicKeyHex)
|
||||
.map((r) => r.pathBytes),
|
||||
];
|
||||
for (final pathBytes in pathSets) {
|
||||
if (pathBytes.isEmpty) continue;
|
||||
final lastHop = pathBytes.sublist(max(0, pathBytes.length - hopWidth));
|
||||
if (lastHop.isEmpty) continue;
|
||||
|
||||
final repeaters = anchorsByPrefix[PathHelper.formatHopHex(lastHop)];
|
||||
if (repeaters != null && repeaters.isNotEmpty) {
|
||||
final repeater = repeaters.first;
|
||||
anchorSet.add(LatLng(repeater.latitude!, repeater.longitude!));
|
||||
}
|
||||
}
|
||||
|
||||
// Filter anchors that are geometrically inconsistent with radio range.
|
||||
// Two anchors more than 2 * maxRange apart cannot both be in direct radio
|
||||
// range of the same node, so isolated outliers are removed.
|
||||
final anchors = maxRangeKm != null && anchorSet.length > 1
|
||||
? _filterConsistentAnchors(anchorSet.toList(), maxRangeKm)
|
||||
: anchorSet.toList();
|
||||
|
||||
if (anchors.isEmpty) continue;
|
||||
|
||||
final LatLng position;
|
||||
if (anchors.length == 1) {
|
||||
// Spread single-anchor guesses around the anchor so they remain visible.
|
||||
position = _offsetGuessedPosition(
|
||||
anchors[0],
|
||||
contact,
|
||||
radiusMeters: 330,
|
||||
);
|
||||
if (!_checkLocationPlausibility(
|
||||
position.latitude,
|
||||
position.longitude,
|
||||
)) {
|
||||
continue; // discard implausible guesses near (0, 0)
|
||||
}
|
||||
} else {
|
||||
double lat = 0, lon = 0, weight = 1.0;
|
||||
int counted = 0;
|
||||
for (final a in anchors) {
|
||||
if (counted == 0) {
|
||||
lat = a.latitude;
|
||||
lon = a.longitude;
|
||||
} else {
|
||||
lat += a.latitude * weight;
|
||||
lon += a.longitude * weight;
|
||||
}
|
||||
// weight subsequent anchors less to create a bias towards the first (if more than 2)
|
||||
weight = weight / 2;
|
||||
counted++;
|
||||
}
|
||||
position = _offsetGuessedPosition(
|
||||
LatLng(lat / anchors.length, lon / anchors.length),
|
||||
contact,
|
||||
radiusMeters: anchors.length >= 3 ? 80 : 120,
|
||||
);
|
||||
if (!_checkLocationPlausibility(
|
||||
position.latitude,
|
||||
position.longitude,
|
||||
)) {
|
||||
continue; // discard implausible guesses near (0, 0
|
||||
}
|
||||
}
|
||||
result.add(
|
||||
_GuessedLocation(
|
||||
contact: contact,
|
||||
position: position,
|
||||
highConfidence: anchors.length >= 2,
|
||||
),
|
||||
);
|
||||
_guessInFlight = true;
|
||||
final connector = context.read<MeshCoreConnector>();
|
||||
final selfLat = connector.selfLatitude;
|
||||
final selfLon = connector.selfLongitude;
|
||||
// Old paths say little about where a node is now.
|
||||
final cutoff = DateTime.now().subtract(_guessMaxAge);
|
||||
final eligible = candidates
|
||||
.where((c) => !c.hasLocation && c.lastSeen.isAfter(cutoff))
|
||||
.toList();
|
||||
for (final c in eligible) {
|
||||
final key = c.publicKeyHex;
|
||||
if (pathHistory.isCached(key) || _storedPaths.containsKey(key)) continue;
|
||||
_storedPaths[key] = await pathHistory.readStoredPaths(key);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
LatLng _offsetGuessedPosition(
|
||||
LatLng anchor,
|
||||
Contact contact, {
|
||||
required double radiusMeters,
|
||||
}) {
|
||||
final seed = _guessSeed(contact.publicKey);
|
||||
final angle = ((seed & 0xFFFF) / 0x10000) * 2 * pi;
|
||||
final latOffsetDeg = (radiusMeters / 111320.0) * cos(angle);
|
||||
final lonScale = max(cos(anchor.latitude * pi / 180.0).abs(), 0.2);
|
||||
final lonOffsetDeg = (radiusMeters / (111320.0 * lonScale)) * sin(angle);
|
||||
return LatLng(
|
||||
anchor.latitude + latOffsetDeg,
|
||||
anchor.longitude + lonOffsetDeg,
|
||||
if (!mounted) {
|
||||
_guessInFlight = false;
|
||||
return;
|
||||
}
|
||||
List<PathRecord> pathsFor(String key) => pathHistory.isCached(key)
|
||||
? pathHistory.peekRecentPaths(key)
|
||||
: _storedPaths[key] ?? const [];
|
||||
final input = (
|
||||
candidates: [
|
||||
for (final c in eligible)
|
||||
(
|
||||
publicKey: c.publicKey,
|
||||
paths: [
|
||||
(c.path.toList(), c.pathHashWidth),
|
||||
for (final r in pathsFor(c.publicKeyHex))
|
||||
(
|
||||
r.pathBytes,
|
||||
Contact.inferPathHashWidth(r.hopCount, r.pathBytes.length),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
anchors: [
|
||||
for (final r in withLocation)
|
||||
if (r.type == advTypeRepeater || r.type == advTypeRoom)
|
||||
(r.publicKey, r.latitude!, r.longitude!),
|
||||
],
|
||||
selfPosition:
|
||||
selfLat != null &&
|
||||
selfLon != null &&
|
||||
isPlausibleLocation(selfLat, selfLon)
|
||||
? (selfLat, selfLon)
|
||||
: null,
|
||||
maxRangeKm: maxRangeKm,
|
||||
);
|
||||
}
|
||||
|
||||
int _guessSeed(Uint8List publicKey) {
|
||||
var seed = 0x811C9DC5;
|
||||
for (final byte in publicKey) {
|
||||
seed ^= byte;
|
||||
seed = (seed * 0x01000193) & 0x7FFFFFFF;
|
||||
List<(int, double, double, bool)> placed;
|
||||
try {
|
||||
placed = await compute(estimateGuessedLocations, input);
|
||||
} catch (e) {
|
||||
debugPrint('Guessed location estimate failed: $e');
|
||||
placed = const [];
|
||||
} finally {
|
||||
_guessInFlight = false;
|
||||
}
|
||||
return seed;
|
||||
final rerun = _guessRerun;
|
||||
_guessRerun = null;
|
||||
if (!mounted) return;
|
||||
if (!context.read<AppSettingsService>().settings.mapShowGuessedLocations) {
|
||||
return;
|
||||
}
|
||||
// Show this result even if inputs moved on; it is newer than what is on
|
||||
// screen, and the queued rerun replaces it shortly.
|
||||
rerun?.call();
|
||||
setState(() {
|
||||
_cachedGuessedLocations = [
|
||||
for (final (index, lat, lon, highConfidence) in placed)
|
||||
_GuessedLocation(
|
||||
contact: eligible[index],
|
||||
position: LatLng(lat, lon),
|
||||
highConfidence: highConfidence,
|
||||
),
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
/// Estimates the free-space maximum LoRa range in km from the connected
|
||||
@@ -1190,20 +1211,6 @@ class _MapScreenState extends State<MapScreen> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Removes anchors that have no neighbour within 2 * maxRangeKm.
|
||||
/// A node cannot be simultaneously in radio range of two points farther apart
|
||||
/// than twice the expected maximum range.
|
||||
List<LatLng> _filterConsistentAnchors(
|
||||
List<LatLng> anchors,
|
||||
double maxRangeKm,
|
||||
) {
|
||||
const distance = Distance();
|
||||
final maxDistM = maxRangeKm * 2000;
|
||||
return anchors
|
||||
.where((a) => anchors.any((b) => b != a && distance(a, b) <= maxDistM))
|
||||
.toList();
|
||||
}
|
||||
|
||||
List<Marker> _buildGuessedMarker(
|
||||
List<_GuessedLocation> guessed, {
|
||||
required bool showLabels,
|
||||
@@ -1380,7 +1387,10 @@ class _MapScreenState extends State<MapScreen> {
|
||||
}
|
||||
}
|
||||
|
||||
if (_zoom >= _clusterOffZoom || overlapsMode || _isBuildingPathTrace) {
|
||||
if (!settings.mapClusterNodes ||
|
||||
_zoom >= _clusterOffZoom ||
|
||||
overlapsMode ||
|
||||
_isBuildingPathTrace) {
|
||||
for (final contact in items) {
|
||||
addNode(contact);
|
||||
}
|
||||
@@ -1832,6 +1842,7 @@ class _MapScreenState extends State<MapScreen> {
|
||||
? IconButton(
|
||||
color: _overlayPrimaryTextColor,
|
||||
icon: const Icon(Icons.close, size: 18),
|
||||
tooltip: context.l10n.common_clearSearch,
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
_searchQuery = '';
|
||||
@@ -1953,6 +1964,14 @@ class _MapScreenState extends State<MapScreen> {
|
||||
!settings.mapShowChatNodes,
|
||||
),
|
||||
),
|
||||
_mapChip(
|
||||
label: context.l10n.map_groupChip,
|
||||
selected: settings.mapClusterNodes,
|
||||
color: MapPalette.cluster,
|
||||
onTap: () => settingsService.setMapClusterNodes(
|
||||
!settings.mapClusterNodes,
|
||||
),
|
||||
),
|
||||
];
|
||||
|
||||
if (constraints.maxWidth < 600) {
|
||||
@@ -1995,45 +2014,53 @@ class _MapScreenState extends State<MapScreen> {
|
||||
final accent = color ?? MapPalette.selected;
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(right: 6),
|
||||
child: Material(
|
||||
color: selected
|
||||
? Color.alphaBlend(
|
||||
accent.withValues(alpha: 0.34),
|
||||
_overlayPanelColor,
|
||||
)
|
||||
: _overlayPanelColor,
|
||||
shape: StadiumBorder(
|
||||
side: BorderSide(
|
||||
color: selected ? accent : _overlayBorderColor,
|
||||
width: selected ? 1.5 : 1,
|
||||
child: Semantics(
|
||||
button: true,
|
||||
selected: selected,
|
||||
child: Material(
|
||||
color: selected
|
||||
? Color.alphaBlend(
|
||||
accent.withValues(alpha: 0.34),
|
||||
_overlayPanelColor,
|
||||
)
|
||||
: _overlayPanelColor,
|
||||
shape: StadiumBorder(
|
||||
side: BorderSide(
|
||||
color: selected ? accent : _overlayBorderColor,
|
||||
width: selected ? 1.5 : 1,
|
||||
),
|
||||
),
|
||||
),
|
||||
clipBehavior: Clip.antiAlias,
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
HapticFeedback.selectionClick();
|
||||
onTap();
|
||||
},
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 7),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
if (selected) ...[
|
||||
Icon(Icons.check, size: 13, color: _overlayPrimaryTextColor),
|
||||
const SizedBox(width: 4),
|
||||
],
|
||||
Text(
|
||||
label,
|
||||
style: TextStyle(
|
||||
fontSize: 12.5,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: selected
|
||||
? _overlayPrimaryTextColor
|
||||
: _overlaySecondaryTextColor,
|
||||
clipBehavior: Clip.antiAlias,
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
HapticFeedback.selectionClick();
|
||||
onTap();
|
||||
},
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 7),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
if (selected) ...[
|
||||
Icon(
|
||||
Icons.check,
|
||||
size: 13,
|
||||
color: _overlayPrimaryTextColor,
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
],
|
||||
Text(
|
||||
label,
|
||||
style: TextStyle(
|
||||
fontSize: 12.5,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: selected
|
||||
? _overlayPrimaryTextColor
|
||||
: _overlaySecondaryTextColor,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -2392,6 +2419,7 @@ class _MapScreenState extends State<MapScreen> {
|
||||
IconButton(
|
||||
color: _overlayPrimaryTextColor,
|
||||
icon: const Icon(Icons.close, size: 20),
|
||||
tooltip: context.l10n.common_close,
|
||||
onPressed: _clearSelection,
|
||||
),
|
||||
],
|
||||
@@ -2526,6 +2554,12 @@ class _MapScreenState extends State<MapScreen> {
|
||||
}
|
||||
_showRoomLogin(context, contact);
|
||||
}),
|
||||
action(context.l10n.map_manageServer, Icons.room_preferences, () {
|
||||
if (!contact.isActive) {
|
||||
connector.importDiscoveredContact(contact);
|
||||
}
|
||||
_showRoomLogin(context, contact, manage: true);
|
||||
}),
|
||||
];
|
||||
default:
|
||||
return const [];
|
||||
@@ -2705,13 +2739,16 @@ class _MapScreenState extends State<MapScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
void _showRoomLogin(BuildContext context, Contact room) {
|
||||
void _showRoomLogin(
|
||||
BuildContext context,
|
||||
Contact room, {
|
||||
bool manage = false,
|
||||
}) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => RoomLoginDialog(
|
||||
room: room,
|
||||
// onLogin(password, isAdmin) isAdmin not used for room caht screen
|
||||
onLogin: (password, _) {
|
||||
onLogin: (password, isAdmin) {
|
||||
final connector = context.read<MeshCoreConnector>();
|
||||
final unread = connector.getUnreadCountForContactKey(
|
||||
room.publicKeyHex,
|
||||
@@ -2720,8 +2757,13 @@ class _MapScreenState extends State<MapScreen> {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) =>
|
||||
ChatScreen(contact: room, initialUnreadCount: unread),
|
||||
builder: (context) => manage
|
||||
? RepeaterHubScreen(
|
||||
repeater: room,
|
||||
password: password,
|
||||
isAdmin: isAdmin,
|
||||
)
|
||||
: ChatScreen(contact: room, initialUnreadCount: unread),
|
||||
),
|
||||
);
|
||||
},
|
||||
@@ -2791,6 +2833,18 @@ class _MapScreenState extends State<MapScreen> {
|
||||
child: Text(context.l10n.map_joinRoom),
|
||||
),
|
||||
);
|
||||
actions.add(
|
||||
FilledButton(
|
||||
onPressed: () {
|
||||
if (!contact.isActive) {
|
||||
connector.importDiscoveredContact(contact);
|
||||
}
|
||||
Navigator.pop(sheetContext);
|
||||
_showRoomLogin(context, contact, manage: true);
|
||||
},
|
||||
child: Text(context.l10n.map_manageServer),
|
||||
),
|
||||
);
|
||||
}
|
||||
return SafeArea(
|
||||
child: SingleChildScrollView(
|
||||
@@ -3437,6 +3491,16 @@ class _MapScreenState extends State<MapScreen> {
|
||||
onChanged: (value) =>
|
||||
service.setMapShowMarkers(value),
|
||||
),
|
||||
SwitchListTile(
|
||||
title: Text(sheetContext.l10n.map_clusterNodes),
|
||||
subtitle: Text(
|
||||
sheetContext.l10n.map_clusterNodesSubtitle,
|
||||
),
|
||||
value: settings.mapClusterNodes,
|
||||
dense: true,
|
||||
onChanged: (value) =>
|
||||
service.setMapClusterNodes(value),
|
||||
),
|
||||
SwitchListTile(
|
||||
title: Text(
|
||||
sheetContext.l10n.map_showGuessedLocations,
|
||||
@@ -3794,6 +3858,7 @@ int _mapContactSignature(Contact contact) {
|
||||
contact.flags,
|
||||
contact.pathLength,
|
||||
_bytesSignature(contact.path),
|
||||
contact.pathHashWidth,
|
||||
contact.pathOverride,
|
||||
_bytesSignature(contact.pathOverrideBytes),
|
||||
contact.latitude,
|
||||
@@ -3836,42 +3901,32 @@ class _MapConnectorSnapshot {
|
||||
),
|
||||
);
|
||||
|
||||
// Only detect that a conversation changed; _collectSharedMarkers does the
|
||||
// per-message scan when this signature moves.
|
||||
final markerParts = <Object?>[connector.selfName];
|
||||
for (final contact in connector.contacts) {
|
||||
markerParts.add(contact.publicKeyHex);
|
||||
markerParts.add(contact.name);
|
||||
for (final message in connector.getMessages(contact)) {
|
||||
if (!message.text.trimLeft().startsWith('m:')) continue;
|
||||
markerParts.add(
|
||||
Object.hash(
|
||||
message.messageId,
|
||||
message.text,
|
||||
message.timestamp.millisecondsSinceEpoch,
|
||||
message.isOutgoing,
|
||||
),
|
||||
);
|
||||
}
|
||||
final messages = connector.getMessages(contact);
|
||||
markerParts.add(
|
||||
Object.hash(
|
||||
contact.publicKeyHex,
|
||||
contact.name,
|
||||
messages.length,
|
||||
messages.isEmpty ? null : messages.last.messageId,
|
||||
),
|
||||
);
|
||||
}
|
||||
for (final channel in connector.channels) {
|
||||
final messages = connector.getChannelMessages(channel);
|
||||
markerParts.add(
|
||||
Object.hash(
|
||||
channel.index,
|
||||
channel.name,
|
||||
channel.isPublicChannel,
|
||||
channel.isEmpty,
|
||||
messages.length,
|
||||
messages.isEmpty ? null : messages.last.messageId,
|
||||
),
|
||||
);
|
||||
for (final message in connector.getChannelMessages(channel)) {
|
||||
if (!message.text.trimLeft().startsWith('m:')) continue;
|
||||
markerParts.add(
|
||||
Object.hash(
|
||||
message.messageId,
|
||||
message.text,
|
||||
message.senderName,
|
||||
message.timestamp.millisecondsSinceEpoch,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return _MapConnectorSnapshot(
|
||||
@@ -3929,6 +3984,7 @@ class _NodeMarkersCacheKey {
|
||||
final bool showChatNodes;
|
||||
final bool showOtherNodes;
|
||||
final bool isBuildingPathTrace;
|
||||
final bool clusterNodes;
|
||||
|
||||
const _NodeMarkersCacheKey({
|
||||
required this.contactsSignature,
|
||||
@@ -3948,6 +4004,7 @@ class _NodeMarkersCacheKey {
|
||||
required this.showChatNodes,
|
||||
required this.showOtherNodes,
|
||||
required this.isBuildingPathTrace,
|
||||
required this.clusterNodes,
|
||||
});
|
||||
|
||||
@override
|
||||
@@ -3969,7 +4026,8 @@ class _NodeMarkersCacheKey {
|
||||
showRepeaters == other.showRepeaters &&
|
||||
showChatNodes == other.showChatNodes &&
|
||||
showOtherNodes == other.showOtherNodes &&
|
||||
isBuildingPathTrace == other.isBuildingPathTrace;
|
||||
isBuildingPathTrace == other.isBuildingPathTrace &&
|
||||
clusterNodes == other.clusterNodes;
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -3991,6 +4049,7 @@ class _NodeMarkersCacheKey {
|
||||
showChatNodes,
|
||||
showOtherNodes,
|
||||
isBuildingPathTrace,
|
||||
clusterNodes,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -4029,6 +4088,7 @@ MarkerPayload? parseMarkerText(String text) {
|
||||
final lat = double.tryParse(match.group(1) ?? '');
|
||||
final lon = double.tryParse(match.group(2) ?? '');
|
||||
if (lat == null || lon == null) return null;
|
||||
if (lat.abs() > 90 || lon.abs() > 180) return null;
|
||||
final label = (match.group(3) ?? '').trim();
|
||||
final flags = (match.group(4) ?? '').trim();
|
||||
return MarkerPayload(position: LatLng(lat, lon), label: label, flags: flags);
|
||||
|
||||
@@ -31,12 +31,16 @@ class NeighborsScreen extends StatefulWidget {
|
||||
|
||||
class _NeighborsScreenState extends State<NeighborsScreen> {
|
||||
static const int _reqNeighborsKeyLen = 4;
|
||||
// Firmware packs results into a 130-byte buffer (simple_repeater/MyMesh.cpp).
|
||||
static const int _reqNeighborsPageSize = 130 ~/ (_reqNeighborsKeyLen + 5);
|
||||
static const int _statusPayloadOffset = 8;
|
||||
static const int _statusStatsSize = 52;
|
||||
static const int _statusResponseBytes =
|
||||
_statusPayloadOffset + _statusStatsSize;
|
||||
Uint8List _tagData = Uint8List(4);
|
||||
bool _awaitingSent = false;
|
||||
int _neighborCount = 0;
|
||||
int _pageOffset = 0;
|
||||
|
||||
bool _isLoading = false;
|
||||
bool _isLoaded = false;
|
||||
@@ -82,12 +86,14 @@ class _NeighborsScreenState extends State<NeighborsScreen> {
|
||||
_frameSubscription = connector.receivedFrames.listen((frame) {
|
||||
if (frame.isEmpty) return;
|
||||
|
||||
if (frame[0] == respCodeSent) {
|
||||
if (frame[0] == respCodeSent && _awaitingSent && frame.length >= 6) {
|
||||
_awaitingSent = false;
|
||||
_tagData = frame.sublist(2, 6);
|
||||
}
|
||||
|
||||
// Check if it's a binary response
|
||||
if (frame[0] == pushCodeBinaryResponse &&
|
||||
frame.length >= 6 &&
|
||||
listEquals(frame.sublist(2, 6), _tagData)) {
|
||||
_handleNeighborsResponse(connector, frame.sublist(6));
|
||||
}
|
||||
@@ -148,7 +154,11 @@ class _NeighborsScreenState extends State<NeighborsScreen> {
|
||||
final contacts = connector.allContactsUnfiltered;
|
||||
try {
|
||||
final neighborCount = buffer.readUInt16LE();
|
||||
final parsedNeighbors = parseNeighborsData(buffer, buffer.readUInt16LE());
|
||||
final page = parseNeighborsData(buffer, buffer.readUInt16LE());
|
||||
final parsedNeighbors = [
|
||||
if (_pageOffset > 0) ...?_parsedNeighbors,
|
||||
...page,
|
||||
];
|
||||
contacts.where((c) => c.type == advTypeRepeater).forEach((repeater) {
|
||||
for (var neighborData in parsedNeighbors) {
|
||||
final publicKey = neighborData['publicKey'];
|
||||
@@ -166,13 +176,19 @@ class _NeighborsScreenState extends State<NeighborsScreen> {
|
||||
_neighborCount = neighborCount;
|
||||
});
|
||||
|
||||
_tagData = Uint8List(4);
|
||||
_statusTimeout?.cancel();
|
||||
_recordStatusResult(true);
|
||||
if (!mounted) return;
|
||||
if (page.isNotEmpty && parsedNeighbors.length < neighborCount) {
|
||||
_loadNeighbors(offset: parsedNeighbors.length);
|
||||
return;
|
||||
}
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(context.l10n.neighbors_receivedData),
|
||||
backgroundColor: Theme.of(context).colorScheme.tertiary,
|
||||
);
|
||||
_statusTimeout?.cancel();
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
_isLoaded = true;
|
||||
@@ -183,9 +199,10 @@ class _NeighborsScreenState extends State<NeighborsScreen> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _loadNeighbors() async {
|
||||
Future<void> _loadNeighbors({int offset = 0}) async {
|
||||
if (_commandService == null) return;
|
||||
|
||||
_pageOffset = offset;
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
_isLoaded = false;
|
||||
@@ -202,13 +219,14 @@ class _NeighborsScreenState extends State<NeighborsScreen> {
|
||||
payload: Uint8List.fromList([
|
||||
reqTypeGetNeighbors,
|
||||
0x00,
|
||||
0x0F,
|
||||
0x00,
|
||||
0x00,
|
||||
_reqNeighborsPageSize,
|
||||
offset & 0xFF,
|
||||
(offset >> 8) & 0xFF,
|
||||
0x00,
|
||||
_reqNeighborsKeyLen,
|
||||
]),
|
||||
);
|
||||
_awaitingSent = true;
|
||||
await connector.sendFrame(frame);
|
||||
|
||||
final pathLengthValue = selection.useFlood ? -1 : selection.hopCount;
|
||||
@@ -234,6 +252,7 @@ class _NeighborsScreenState extends State<NeighborsScreen> {
|
||||
_recordStatusResult(false);
|
||||
});
|
||||
} catch (e) {
|
||||
_awaitingSent = false;
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
|
||||
@@ -91,6 +91,7 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen>
|
||||
Timer? _timeoutTimer;
|
||||
|
||||
bool _isLoading = false;
|
||||
bool _awaitingTraceSent = false;
|
||||
bool _failed2Loaded = false;
|
||||
bool _hasData = false;
|
||||
PathTraceData? _traceData;
|
||||
@@ -112,6 +113,7 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen>
|
||||
// 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);
|
||||
int _tracedPathHashWidth = 1;
|
||||
|
||||
// Packet-flow animation + multi-path view state.
|
||||
late final PathPlaybackController _playback;
|
||||
@@ -184,9 +186,13 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen>
|
||||
Uint8List? _tracePathFromBytes(
|
||||
Uint8List pathBytes,
|
||||
int traceHashByteWidth,
|
||||
MeshCoreConnector connector,
|
||||
) {
|
||||
final hops = PathHelper.splitPathBytes(pathBytes, widget.pathHashByteWidth);
|
||||
MeshCoreConnector connector, {
|
||||
int? pathHashByteWidth,
|
||||
}) {
|
||||
final hops = PathHelper.splitPathBytes(
|
||||
pathBytes,
|
||||
pathHashByteWidth ?? widget.pathHashByteWidth,
|
||||
);
|
||||
final traceBytes = <int>[];
|
||||
for (final hop in hops) {
|
||||
final traceHop = _expandHopForTrace(hop, traceHashByteWidth, connector);
|
||||
@@ -316,11 +322,12 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen>
|
||||
Uint8List? buildPath(
|
||||
Uint8List pathBytes,
|
||||
int traceHashByteWidth,
|
||||
MeshCoreConnector connector,
|
||||
) {
|
||||
MeshCoreConnector connector, {
|
||||
int? pathHashByteWidth,
|
||||
}) {
|
||||
final pathHops = PathHelper.splitPathBytes(
|
||||
pathBytes,
|
||||
widget.pathHashByteWidth,
|
||||
pathHashByteWidth ?? widget.pathHashByteWidth,
|
||||
);
|
||||
final hopWidth = traceHashByteWidth.clamp(1, pubKeySize).toInt();
|
||||
|
||||
@@ -375,17 +382,21 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen>
|
||||
/// route (flipPathAround), re-read that contact's live forced/auto path from
|
||||
/// the connector so a path the user just changed (force flood / set path /
|
||||
/// reset to auto) is honored immediately, instead of the value captured when
|
||||
/// this screen was first pushed.
|
||||
Uint8List _resolveLivePath(MeshCoreConnector connector) {
|
||||
/// this screen was first pushed. Also returns the path's bytes per hop: the
|
||||
/// contact's learned width for its device path, the local mode otherwise.
|
||||
(Uint8List, int) _resolveLivePath(MeshCoreConnector connector) {
|
||||
final target = widget.targetContact;
|
||||
if (!widget.flipPathAround || target == null) {
|
||||
return widget.path;
|
||||
return (widget.path, widget.pathHashByteWidth);
|
||||
}
|
||||
final live = connector.allContactsUnfiltered.firstWhere(
|
||||
(c) => c.publicKeyHex == target.publicKeyHex,
|
||||
orElse: () => target,
|
||||
);
|
||||
return live.pathBytesForDisplay;
|
||||
final width = live.pathOverride == null && live.path.isNotEmpty
|
||||
? live.pathHashWidth
|
||||
: widget.pathHashByteWidth;
|
||||
return (live.pathBytesForDisplay, width);
|
||||
}
|
||||
|
||||
Future<void> _doPathTrace() async {
|
||||
@@ -398,17 +409,28 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen>
|
||||
}
|
||||
|
||||
final connector = Provider.of<MeshCoreConnector>(context, listen: false);
|
||||
final traceHashByteWidth = _traceHashByteWidth(widget.pathHashByteWidth);
|
||||
final livePath = _resolveLivePath(connector);
|
||||
final (livePath, hopWidth) = _resolveLivePath(connector);
|
||||
final traceHashByteWidth = _traceHashByteWidth(hopWidth);
|
||||
_tracedPath = livePath;
|
||||
_tracedPathHashWidth = hopWidth;
|
||||
|
||||
final pathTmp = widget.reversePathAround
|
||||
? _reversePathByHop(livePath, widget.pathHashByteWidth)
|
||||
? _reversePathByHop(livePath, hopWidth)
|
||||
: livePath;
|
||||
|
||||
final path = widget.flipPathAround
|
||||
? buildPath(pathTmp, traceHashByteWidth, connector)
|
||||
: _tracePathFromBytes(pathTmp, traceHashByteWidth, connector);
|
||||
? buildPath(
|
||||
pathTmp,
|
||||
traceHashByteWidth,
|
||||
connector,
|
||||
pathHashByteWidth: hopWidth,
|
||||
)
|
||||
: _tracePathFromBytes(
|
||||
pathTmp,
|
||||
traceHashByteWidth,
|
||||
connector,
|
||||
pathHashByteWidth: hopWidth,
|
||||
);
|
||||
|
||||
if (path == null) {
|
||||
if (!mounted) return;
|
||||
@@ -442,6 +464,7 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen>
|
||||
flags, // flag
|
||||
payload: tracePayload,
|
||||
);
|
||||
_awaitingTraceSent = true;
|
||||
connector.sendFrame(frame);
|
||||
}
|
||||
|
||||
@@ -455,7 +478,8 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen>
|
||||
try {
|
||||
final code = frameBuffer.readUInt8();
|
||||
|
||||
if (code == respCodeSent) {
|
||||
if (code == respCodeSent && _awaitingTraceSent) {
|
||||
_awaitingTraceSent = false;
|
||||
frameBuffer.skipBytes(1); //reserved
|
||||
tagData = frameBuffer.readBytes(4);
|
||||
final timeoutMilliseconds = frameBuffer.readUInt32LE();
|
||||
@@ -474,7 +498,8 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen>
|
||||
);
|
||||
}
|
||||
|
||||
if (code == respCodeErr) {
|
||||
if (code == respCodeErr && _awaitingTraceSent) {
|
||||
_awaitingTraceSent = false;
|
||||
_timeoutTimer?.cancel();
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
@@ -593,7 +618,7 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen>
|
||||
c.hasLocation &&
|
||||
c.path.isNotEmpty &&
|
||||
_matchesHopPrefix(
|
||||
_lastHopChunk(c.path, widget.pathHashByteWidth),
|
||||
_lastHopChunk(c.path, c.pathHashWidth),
|
||||
hop,
|
||||
),
|
||||
)
|
||||
@@ -633,7 +658,7 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen>
|
||||
// sits in the middle of the symmetric sequence; .last is the local side.
|
||||
final tracedHops = PathHelper.splitPathBytes(
|
||||
_tracedPath,
|
||||
widget.pathHashByteWidth,
|
||||
_tracedPathHashWidth,
|
||||
);
|
||||
final hopsForEndpoint = tracedHops.isNotEmpty
|
||||
? tracedHops
|
||||
@@ -649,7 +674,7 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen>
|
||||
c.hasLocation &&
|
||||
c.path.isNotEmpty &&
|
||||
_matchesHopPrefix(
|
||||
_lastHopChunk(c.path, widget.pathHashByteWidth),
|
||||
_lastHopChunk(c.path, c.pathHashWidth),
|
||||
lastHop,
|
||||
),
|
||||
)
|
||||
@@ -794,10 +819,7 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen>
|
||||
(c) =>
|
||||
c.hasLocation &&
|
||||
c.path.isNotEmpty &&
|
||||
_matchesHopPrefix(
|
||||
_lastHopChunk(c.path, widget.pathHashByteWidth),
|
||||
hop,
|
||||
),
|
||||
_matchesHopPrefix(_lastHopChunk(c.path, c.pathHashWidth), hop),
|
||||
)
|
||||
.toList();
|
||||
if (peers.isEmpty) return null;
|
||||
@@ -837,7 +859,7 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen>
|
||||
if (record.pathBytes.isEmpty) continue;
|
||||
final recordHops = PathHelper.splitPathBytes(
|
||||
record.pathBytes,
|
||||
widget.pathHashByteWidth,
|
||||
Contact.inferPathHashWidth(record.hopCount, record.pathBytes.length),
|
||||
);
|
||||
if (!seen.add(_pathKeyForHops(recordHops))) continue;
|
||||
if (altIndex >= kAlternatePathColors.length) break;
|
||||
|
||||
@@ -78,13 +78,82 @@ class _RegionManagementScreenState extends State<RegionManagementScreen> {
|
||||
),
|
||||
],
|
||||
),
|
||||
body: ListView.builder(
|
||||
padding: const EdgeInsets.only(left: 16, right: 16, top: 8, bottom: 88),
|
||||
itemCount: _regions.length,
|
||||
itemBuilder: (context, index) {
|
||||
final region = _regions[index];
|
||||
return _buildRegionTile(context, region);
|
||||
},
|
||||
body: _regions.isEmpty
|
||||
? _buildEmptyState(context)
|
||||
: ListView.builder(
|
||||
padding: const EdgeInsets.only(
|
||||
left: 16,
|
||||
right: 16,
|
||||
top: 8,
|
||||
bottom: 88,
|
||||
),
|
||||
itemCount: _regions.length + 1,
|
||||
itemBuilder: (context, index) {
|
||||
if (index == 0) return _buildDefaultRegionTile(context);
|
||||
return _buildRegionTile(context, _regions[index - 1]);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildEmptyState(BuildContext context) {
|
||||
final l10n = context.l10n;
|
||||
return Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Icon(Icons.landscape, size: 48, color: MeshPalette.blue),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
l10n.settings_regionEmptyExplanation,
|
||||
textAlign: TextAlign.center,
|
||||
style: Theme.of(context).textTheme.bodyMedium,
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
FilledButton.icon(
|
||||
icon: const Icon(Icons.travel_explore),
|
||||
label: Text(l10n.settings_regionFetchFromRepeaters),
|
||||
onPressed: _isFetchingRegions ? null : _showFetchRegionsDialog,
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
OutlinedButton.icon(
|
||||
icon: const Icon(Icons.add),
|
||||
label: Text(l10n.settings_regionAddRegion),
|
||||
onPressed: () => _showAddRegionDialog(context),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildDefaultRegionTile(BuildContext context) {
|
||||
final l10n = context.l10n;
|
||||
final connector = context.watch<MeshCoreConnector>();
|
||||
final current = _regions.contains(connector.defaultRegion)
|
||||
? connector.defaultRegion
|
||||
: '';
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 8),
|
||||
child: DropdownButtonFormField<Region>(
|
||||
key: ValueKey(current),
|
||||
initialValue: current,
|
||||
decoration: InputDecoration(
|
||||
labelText: l10n.settings_regionDefault,
|
||||
helperText: l10n.settings_regionDefaultSubtitle,
|
||||
border: const OutlineInputBorder(),
|
||||
),
|
||||
items: [
|
||||
DropdownMenuItem(
|
||||
value: '',
|
||||
child: Text(l10n.settings_regionDefaultNone),
|
||||
),
|
||||
for (final region in _regions)
|
||||
DropdownMenuItem(value: region, child: Text(region)),
|
||||
],
|
||||
onChanged: (value) => connector.setDefaultRegion(value ?? ''),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -440,7 +509,12 @@ class _RegionManagementScreenState extends State<RegionManagementScreen> {
|
||||
await connector.clearContactPath(repeater);
|
||||
return;
|
||||
}
|
||||
await connector.setContactPath(repeater, originalPath, originalPathLength);
|
||||
await connector.setContactPath(
|
||||
repeater,
|
||||
originalPath,
|
||||
originalPathLength,
|
||||
pathHashWidth: repeater.pathHashWidth,
|
||||
);
|
||||
}
|
||||
|
||||
Set<Region> _parseRegionsResponse(Uint8List frame) {
|
||||
|
||||
@@ -34,6 +34,8 @@ class _RepeaterCliScreenState extends State<RepeaterCliScreen> {
|
||||
int _historyIndex = -1;
|
||||
StreamSubscription<Uint8List>? _frameSubscription;
|
||||
RepeaterCommandService? _commandService;
|
||||
bool _regionLoadActive = false;
|
||||
static final RegExp _regionLoadPattern = RegExp(r'^region +load( |$)');
|
||||
|
||||
late final List<Map<String, String>> _quickCommands = [
|
||||
{'labelKey': 'advertise', 'command': 'advert'},
|
||||
@@ -111,8 +113,13 @@ class _RepeaterCliScreenState extends State<RepeaterCliScreen> {
|
||||
}
|
||||
|
||||
void _sendCommand({bool showDebug = false}) async {
|
||||
if (_regionLoadActive) {
|
||||
_sendRegionLoadLine();
|
||||
return;
|
||||
}
|
||||
final command = _commandController.text.trim();
|
||||
if (command.isEmpty) return;
|
||||
final startsRegionLoad = _regionLoadPattern.hasMatch(command.toLowerCase());
|
||||
|
||||
setState(() {
|
||||
_commandHistory.add({
|
||||
@@ -121,6 +128,9 @@ class _RepeaterCliScreenState extends State<RepeaterCliScreen> {
|
||||
'timestamp': DateTime.now().toString(),
|
||||
});
|
||||
});
|
||||
_commandController.clear();
|
||||
_historyIndex = -1;
|
||||
_commandFocusNode.requestFocus();
|
||||
|
||||
if (showDebug && mounted) {
|
||||
final frame = buildSendCliCommandFrame(
|
||||
@@ -168,12 +178,79 @@ 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();
|
||||
}
|
||||
|
||||
/// In `region load` mode lines go out verbatim: no `XX|` prefix and no
|
||||
/// trimming, since indentation encodes the parent. Region lines get no
|
||||
/// reply; a blank line commits the load and is answered with
|
||||
/// "OK - loaded N regions".
|
||||
Future<void> _sendRegionLoadLine() async {
|
||||
final line = _commandController.text;
|
||||
final isTerminator = line.trim().isEmpty;
|
||||
final connector = Provider.of<MeshCoreConnector>(context, listen: false);
|
||||
final repeater = _resolveRepeater(connector);
|
||||
setState(() {
|
||||
_commandHistory.add({
|
||||
'type': 'command',
|
||||
'text': isTerminator ? context.l10n.repeater_cliRegionLoadEnd : line,
|
||||
'timestamp': DateTime.now().toString(),
|
||||
});
|
||||
});
|
||||
_commandController.clear();
|
||||
_historyIndex = -1;
|
||||
_commandFocusNode.requestFocus();
|
||||
|
||||
String? response;
|
||||
var ended = false;
|
||||
try {
|
||||
if (isTerminator) {
|
||||
response = await _commandService!.sendCommand(
|
||||
repeater,
|
||||
'',
|
||||
retries: 1,
|
||||
raw: true,
|
||||
);
|
||||
ended = true;
|
||||
} else {
|
||||
await _commandService!.sendUnansweredLine(repeater, line);
|
||||
}
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
response = context.l10n.repeater_cliCommandError(e.toString());
|
||||
}
|
||||
}
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
if (ended) _regionLoadActive = false;
|
||||
if (response != null) {
|
||||
_commandHistory.add({
|
||||
'type': 'response',
|
||||
'text': response,
|
||||
'timestamp': DateTime.now().toString(),
|
||||
});
|
||||
}
|
||||
});
|
||||
_scrollToBottom();
|
||||
}
|
||||
|
||||
void _scrollToBottom() {
|
||||
if (!mounted) return;
|
||||
Future.delayed(const Duration(milliseconds: 100), () {
|
||||
if (_scrollController.hasClients) {
|
||||
if (mounted && _scrollController.hasClients) {
|
||||
_scrollController.animateTo(
|
||||
_scrollController.position.maxScrollExtent,
|
||||
duration: const Duration(milliseconds: 200),
|
||||
@@ -337,7 +414,9 @@ class _RepeaterCliScreenState extends State<RepeaterCliScreen> {
|
||||
backgroundColor: MeshPalette.blueBg,
|
||||
side: const BorderSide(color: MeshPalette.blueLine),
|
||||
visualDensity: VisualDensity.compact,
|
||||
onPressed: () => _useQuickCommand(cmd['command']!),
|
||||
onPressed: _regionLoadActive
|
||||
? null
|
||||
: () => _useQuickCommand(cmd['command']!),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
@@ -392,12 +471,14 @@ class _RepeaterCliScreenState extends State<RepeaterCliScreen> {
|
||||
color: MeshPalette.ink,
|
||||
),
|
||||
decoration: InputDecoration(
|
||||
hintText: context.l10n.repeater_enterCommandHint,
|
||||
hintText: _regionLoadActive
|
||||
? context.l10n.repeater_cliRegionLoadHint
|
||||
: context.l10n.repeater_enterCommandHint,
|
||||
hintStyle: MeshTheme.mono(
|
||||
fontSize: 13,
|
||||
color: MeshPalette.ink4,
|
||||
),
|
||||
prefixText: '> ',
|
||||
prefixText: _regionLoadActive ? '' : '> ',
|
||||
prefixStyle: MeshTheme.mono(
|
||||
fontSize: 13,
|
||||
color: MeshPalette.blue,
|
||||
@@ -609,22 +690,6 @@ class _RepeaterCliScreenState extends State<RepeaterCliScreen> {
|
||||
command: 'powersaving {on|off}',
|
||||
description: l10n.repeater_cliHelpPowersavingOnOff,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'erase',
|
||||
description: l10n.repeater_cliHelpErase,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'stats-packets',
|
||||
description: l10n.repeater_cliHelpStatsPackets,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'stats-radio',
|
||||
description: l10n.repeater_cliHelpStatsRadio,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'stats-core',
|
||||
description: l10n.repeater_cliHelpStatsCore,
|
||||
),
|
||||
];
|
||||
|
||||
final settingsCommands = [
|
||||
@@ -648,6 +713,14 @@ class _RepeaterCliScreenState extends State<RepeaterCliScreen> {
|
||||
command: 'set flood.max {max-hops}',
|
||||
description: l10n.repeater_cliHelpSetFloodMax,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'set flood.max.unscoped {0-64}',
|
||||
description: l10n.repeater_cliHelpSetFloodMaxUnscoped,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'set flood.max.advert {0-64}',
|
||||
description: l10n.repeater_cliHelpSetFloodMaxAdvert,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'set int.thresh {db}',
|
||||
description: l10n.repeater_cliHelpSetIntThresh,
|
||||
@@ -700,26 +773,6 @@ class _RepeaterCliScreenState extends State<RepeaterCliScreen> {
|
||||
command: 'set direct.txdelay {factor}',
|
||||
description: l10n.repeater_cliHelpSetDirectTxDelay,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'set bridge.enabled {on|off}',
|
||||
description: l10n.repeater_cliHelpSetBridgeEnabled,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'set bridge.delay {0-10000}',
|
||||
description: l10n.repeater_cliHelpSetBridgeDelay,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'set bridge.source {rx|tx}',
|
||||
description: l10n.repeater_cliHelpSetBridgeSource,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'set bridge.baud {speed}',
|
||||
description: l10n.repeater_cliHelpSetBridgeBaud,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'set bridge.secret {shared-secret}',
|
||||
description: l10n.repeater_cliHelpSetBridgeSecret,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'set adc.multiplier {factor}',
|
||||
description: l10n.repeater_cliHelpSetAdcMultiplier,
|
||||
@@ -744,6 +797,14 @@ class _RepeaterCliScreenState extends State<RepeaterCliScreen> {
|
||||
command: 'set radio.rxgain {on|off}',
|
||||
description: l10n.repeater_cliHelpSetRadioRxGain,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'set radio.fem.rxgain {on|off}',
|
||||
description: l10n.repeater_cliHelpSetRadioFemRxGain,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'set radio.fem.txgain {on|off}',
|
||||
description: l10n.repeater_cliHelpSetRadioFemTxGain,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'set owner.info {text}',
|
||||
description: l10n.repeater_cliHelpSetOwnerInfo,
|
||||
@@ -756,17 +817,57 @@ class _RepeaterCliScreenState extends State<RepeaterCliScreen> {
|
||||
command: 'set loop.detect {off|minimal|moderate|strict}',
|
||||
description: l10n.repeater_cliHelpSetLoopDetect,
|
||||
),
|
||||
];
|
||||
|
||||
final bridgeCommands = [
|
||||
_CommandHelpEntry(
|
||||
command: 'set freq {mhz}',
|
||||
description: l10n.repeater_cliHelpSetFreq,
|
||||
command: 'set bridge.enabled {on|off}',
|
||||
description: l10n.repeater_cliHelpSetBridgeEnabled,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'set bridge.delay {0-10000}',
|
||||
description: l10n.repeater_cliHelpSetBridgeDelay,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'set bridge.source {rx|tx}',
|
||||
description: l10n.repeater_cliHelpSetBridgeSource,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'set bridge.baud {speed}',
|
||||
description: l10n.repeater_cliHelpSetBridgeBaud,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'set bridge.secret {shared-secret}',
|
||||
description: l10n.repeater_cliHelpSetBridgeSecret,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'set bridge.channel {1-14}',
|
||||
description: l10n.repeater_cliHelpSetBridgeChannel,
|
||||
),
|
||||
];
|
||||
|
||||
final bridgeCommands = [
|
||||
_CommandHelpEntry(
|
||||
command: 'get bridge.enabled',
|
||||
description: l10n.repeater_cliHelpGetBridgeEnabled,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'get bridge.delay',
|
||||
description: l10n.repeater_cliHelpGetBridgeDelay,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'get bridge.source',
|
||||
description: l10n.repeater_cliHelpGetBridgeSource,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'get bridge.baud',
|
||||
description: l10n.repeater_cliHelpGetBridgeBaud,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'get bridge.channel',
|
||||
description: l10n.repeater_cliHelpGetBridgeChannel,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'get bridge.secret',
|
||||
description: l10n.repeater_cliHelpGetBridgeSecret,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'get bridge.type',
|
||||
description: l10n.repeater_cliHelpGetBridgeType,
|
||||
@@ -808,6 +909,10 @@ class _RepeaterCliScreenState extends State<RepeaterCliScreen> {
|
||||
command: 'region load',
|
||||
description: l10n.repeater_cliHelpRegionLoad,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'region def {name}[,{jump-prefix}] ...',
|
||||
description: l10n.repeater_cliHelpRegionDef,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'region get {* | name-prefix}',
|
||||
description: l10n.repeater_cliHelpRegionGet,
|
||||
@@ -871,10 +976,6 @@ class _RepeaterCliScreenState extends State<RepeaterCliScreen> {
|
||||
command: 'get public.key',
|
||||
description: l10n.repeater_cliHelpGetPublicKey,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'get prv.key',
|
||||
description: l10n.repeater_cliHelpGetPrvKey,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'get repeat',
|
||||
description: l10n.repeater_cliHelpGetRepeat,
|
||||
@@ -895,6 +996,14 @@ class _RepeaterCliScreenState extends State<RepeaterCliScreen> {
|
||||
command: 'get radio.rxgain',
|
||||
description: l10n.repeater_cliHelpGetRadioRxGain,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'get radio.fem.rxgain',
|
||||
description: l10n.repeater_cliHelpGetRadioFemRxGain,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'get radio.fem.txgain',
|
||||
description: l10n.repeater_cliHelpGetRadioFemTxGain,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'get af',
|
||||
description: l10n.repeater_cliHelpGetAf,
|
||||
@@ -955,6 +1064,14 @@ class _RepeaterCliScreenState extends State<RepeaterCliScreen> {
|
||||
command: 'get flood.max',
|
||||
description: l10n.repeater_cliHelpGetFloodMax,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'get flood.max.unscoped',
|
||||
description: l10n.repeater_cliHelpGetFloodMaxUnscoped,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'get flood.max.advert',
|
||||
description: l10n.repeater_cliHelpGetFloodMaxAdvert,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'get owner.info',
|
||||
description: l10n.repeater_cliHelpGetOwnerInfo,
|
||||
@@ -967,34 +1084,6 @@ class _RepeaterCliScreenState extends State<RepeaterCliScreen> {
|
||||
command: 'get loop.detect',
|
||||
description: l10n.repeater_cliHelpGetLoopDetect,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'get acl',
|
||||
description: l10n.repeater_cliHelpGetAcl,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'get bridge.enabled',
|
||||
description: l10n.repeater_cliHelpGetBridgeEnabled,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'get bridge.delay',
|
||||
description: l10n.repeater_cliHelpGetBridgeDelay,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'get bridge.source',
|
||||
description: l10n.repeater_cliHelpGetBridgeSource,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'get bridge.baud',
|
||||
description: l10n.repeater_cliHelpGetBridgeBaud,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'get bridge.channel',
|
||||
description: l10n.repeater_cliHelpGetBridgeChannel,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'get bridge.secret',
|
||||
description: l10n.repeater_cliHelpGetBridgeSecret,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'get bootloader.ver',
|
||||
description: l10n.repeater_cliHelpGetBootloaderVer,
|
||||
@@ -1103,7 +1192,12 @@ class _RepeaterCliScreenState extends State<RepeaterCliScreen> {
|
||||
const SizedBox(height: 16),
|
||||
_buildHelpSection(context, l10n.repeater_sensors, sensorCommands),
|
||||
const SizedBox(height: 16),
|
||||
_buildHelpSection(context, l10n.repeater_bridge, bridgeCommands),
|
||||
_buildHelpSection(
|
||||
context,
|
||||
l10n.repeater_bridge,
|
||||
bridgeCommands,
|
||||
note: l10n.repeater_bridgeNote,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_buildHelpSection(
|
||||
context,
|
||||
|
||||
@@ -122,7 +122,9 @@ class RepeaterHubScreen extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
StatusChip(
|
||||
label: isAdmin ? 'ADMIN' : 'GUEST',
|
||||
label: isAdmin
|
||||
? l10n.repeater_roleAdmin
|
||||
: l10n.repeater_roleGuest,
|
||||
color: isAdmin
|
||||
? MeshPalette.blue
|
||||
: scheme.onSurfaceVariant,
|
||||
@@ -218,23 +220,26 @@ class RepeaterHubScreen extends StatelessWidget {
|
||||
},
|
||||
),
|
||||
|
||||
_HubActionTile(
|
||||
index: 2,
|
||||
icon: Icons.group,
|
||||
title: l10n.repeater_neighbors,
|
||||
subtitle: l10n.repeater_neighborsSubtitle,
|
||||
accentColor: MeshPalette.signal,
|
||||
onTap: () {
|
||||
HapticFeedback.selectionClick();
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) =>
|
||||
NeighborsScreen(repeater: repeater, password: password),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
if (repeater.type != advTypeRoom)
|
||||
_HubActionTile(
|
||||
index: 2,
|
||||
icon: Icons.group,
|
||||
title: l10n.repeater_neighbors,
|
||||
subtitle: l10n.repeater_neighborsSubtitle,
|
||||
accentColor: MeshPalette.signal,
|
||||
onTap: () {
|
||||
HapticFeedback.selectionClick();
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => NeighborsScreen(
|
||||
repeater: repeater,
|
||||
password: password,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
|
||||
if (isAdmin) ...[
|
||||
_HubActionTile(
|
||||
@@ -305,46 +310,53 @@ class _HubActionTile extends StatelessWidget {
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
return ListEntrance(
|
||||
index: index,
|
||||
child: MeshCard(
|
||||
onTap: onTap,
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 44,
|
||||
height: 44,
|
||||
decoration: BoxDecoration(
|
||||
color: accentColor.withValues(alpha: 0.12),
|
||||
borderRadius: BorderRadius.circular(MeshRadii.md),
|
||||
border: Border.all(color: accentColor.withValues(alpha: 0.3)),
|
||||
child: Semantics(
|
||||
button: true,
|
||||
child: MeshCard(
|
||||
onTap: onTap,
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 44,
|
||||
height: 44,
|
||||
decoration: BoxDecoration(
|
||||
color: accentColor.withValues(alpha: 0.12),
|
||||
borderRadius: BorderRadius.circular(MeshRadii.md),
|
||||
border: Border.all(color: accentColor.withValues(alpha: 0.3)),
|
||||
),
|
||||
alignment: Alignment.center,
|
||||
child: Icon(icon, size: 22, color: accentColor),
|
||||
),
|
||||
alignment: Alignment.center,
|
||||
child: Icon(icon, size: 22, color: accentColor),
|
||||
),
|
||||
const SizedBox(width: 14),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
title,
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.w600,
|
||||
fontSize: 15,
|
||||
const SizedBox(width: 14),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
title,
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.w600,
|
||||
fontSize: 15,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
subtitle,
|
||||
style: TextStyle(
|
||||
fontSize: 12.5,
|
||||
color: scheme.onSurfaceVariant,
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
subtitle,
|
||||
style: TextStyle(
|
||||
fontSize: 12.5,
|
||||
color: scheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
Icon(Icons.chevron_right, color: scheme.onSurfaceVariant, size: 20),
|
||||
],
|
||||
Icon(
|
||||
Icons.chevron_right,
|
||||
color: scheme.onSurfaceVariant,
|
||||
size: 20,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -7,6 +7,7 @@ import '../l10n/l10n.dart';
|
||||
import '../models/contact.dart';
|
||||
import '../connector/meshcore_connector.dart';
|
||||
import '../connector/meshcore_protocol.dart';
|
||||
import '../helpers/utf8_length_limiter.dart';
|
||||
import '../services/repeater_command_service.dart';
|
||||
import '../services/storage_service.dart';
|
||||
import '../theme/mesh_theme.dart';
|
||||
@@ -112,6 +113,10 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
bool _refreshingIntThresh = false;
|
||||
bool _refreshingAgcResetInterval = false;
|
||||
bool _runningAction = false;
|
||||
bool _loadingAll = false;
|
||||
int _unansweredSections = 0;
|
||||
double _loadAllProgress = 0;
|
||||
final Set<String> _loadedKeys = {};
|
||||
bool _searchingForKeyPair = false;
|
||||
bool _stopSearchingForKeyPair = false;
|
||||
StreamSubscription<Uint8List>? _frameSubscription;
|
||||
@@ -191,6 +196,13 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
];
|
||||
final List<int> _spreadingFactorOptions = [5, 6, 7, 8, 9, 10, 11, 12];
|
||||
final List<int> _codingRateOptions = [5, 6, 7, 8];
|
||||
static const int _minRepeaterTxPower = -9;
|
||||
static const int _maxRepeaterTxPower = 30;
|
||||
// CommonCLI.h: password[16], node_name[32], owner_info[120].
|
||||
static const int _maxPasswordBytes = 15;
|
||||
static const int _maxNameBytes = 31;
|
||||
static const int _maxOwnerInfoBytes = 119;
|
||||
static const int _maxAgcResetInterval = 255 * 4;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -287,7 +299,7 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
break;
|
||||
case 'tx':
|
||||
final dbm = int.tryParse(value.replaceAll(RegExp(r'[^0-9-]'), ''));
|
||||
if (dbm != null && dbm >= 1 && dbm <= 30) {
|
||||
if (dbm != null && dbm >= -128 && dbm <= 127) {
|
||||
_txPowerController.text = dbm.toString();
|
||||
}
|
||||
break;
|
||||
@@ -364,7 +376,9 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
break;
|
||||
case 'agc.reset.interval':
|
||||
final v = int.tryParse(value.trim());
|
||||
if (v != null && v >= 0) _agcResetInterval = v;
|
||||
if (v != null && v >= 0) {
|
||||
_agcResetInterval = v.clamp(0, _maxAgcResetInterval);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -388,10 +402,18 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
}
|
||||
}
|
||||
if (parts.length > 2) {
|
||||
_spreadingFactor = int.tryParse(parts[2].trim()) ?? _spreadingFactor;
|
||||
final sf = int.tryParse(parts[2].trim());
|
||||
if (sf != null && _spreadingFactorOptions.contains(sf)) {
|
||||
_spreadingFactor = sf;
|
||||
}
|
||||
}
|
||||
if (parts.length > 3) {
|
||||
_codingRate = int.tryParse(parts[3].trim()) ?? _codingRate;
|
||||
final cr = int.tryParse(parts[3].trim());
|
||||
// Some firmware reports CR as 1-4 instead of 5-8.
|
||||
final uiCr = cr != null && cr <= 4 ? cr + 4 : cr;
|
||||
if (uiCr != null && _codingRateOptions.contains(uiCr)) {
|
||||
_codingRate = uiCr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -423,10 +445,15 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
final key = normalized.substring(4).trim();
|
||||
final value = _extractGetValue(response);
|
||||
if (value == null) return false;
|
||||
setState(() => _applyGetValue(key, value));
|
||||
setState(() {
|
||||
_applyGetValue(key, value);
|
||||
_loadedKeys.add(key);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
bool _loaded(String key) => _loadedKeys.contains(key);
|
||||
|
||||
/// Firmware GET replies are always `> <value>` (CommonCLI.cpp `sprintf(reply, "> %s", ...)`).
|
||||
/// Returns the first such value, trimmed; null if none found.
|
||||
String? _extractGetValue(String response) {
|
||||
@@ -451,6 +478,7 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
setState(() => setRefreshing(true));
|
||||
|
||||
var successCount = 0;
|
||||
var answered = false;
|
||||
final connector = Provider.of<MeshCoreConnector>(context, listen: false);
|
||||
final repeater = _resolveRepeater(connector);
|
||||
for (final command in commands) {
|
||||
@@ -460,14 +488,22 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
command,
|
||||
retries: 1,
|
||||
);
|
||||
if (!mounted) return;
|
||||
answered = true;
|
||||
if (_handleGetResponse(command, response)) successCount += 1;
|
||||
await Future.delayed(const Duration(milliseconds: 200));
|
||||
} catch (e) {
|
||||
debugPrint('Error fetching $command: $e');
|
||||
}
|
||||
if (!mounted) return;
|
||||
}
|
||||
|
||||
if (mounted) {
|
||||
if (_loadingAll) {
|
||||
// A reply we can't use usually means older firmware without that
|
||||
// setting; only a section that never answered counts as a failure.
|
||||
if (!answered) _unansweredSections += 1;
|
||||
setState(() => setRefreshing(false));
|
||||
} else {
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(
|
||||
@@ -702,9 +738,52 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _refreshAll() async {
|
||||
if (_loadingAll) return;
|
||||
final sections = <Future<void> Function()>[
|
||||
_refreshBasicSettings,
|
||||
_refreshRadioSettings,
|
||||
_refreshTxPower,
|
||||
_refreshRxGain,
|
||||
_refreshLat,
|
||||
_refreshLon,
|
||||
_refreshRepeat,
|
||||
_refreshAllowReadOnly,
|
||||
_refreshMultiAcks,
|
||||
_refreshLoopDetect,
|
||||
_refreshDutyCycle,
|
||||
_refreshAdvertInterval,
|
||||
_refreshFloodAdvertInterval,
|
||||
_refreshFloodMax,
|
||||
_refreshOwnerInfo,
|
||||
_refreshPathHashMode,
|
||||
_refreshTxDelay,
|
||||
_refreshDirectTxDelay,
|
||||
_refreshIntThresh,
|
||||
_refreshAgcResetInterval,
|
||||
];
|
||||
_unansweredSections = 0;
|
||||
setState(() {
|
||||
_loadingAll = true;
|
||||
_loadAllProgress = 0;
|
||||
});
|
||||
for (var i = 0; i < sections.length; i++) {
|
||||
if (!mounted) return;
|
||||
await sections[i]();
|
||||
if (!mounted) return;
|
||||
setState(() => _loadAllProgress = (i + 1) / sections.length);
|
||||
}
|
||||
setState(() => _loadingAll = false);
|
||||
if (_unansweredSections > 0) {
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(context.l10n.repeater_settingsLoadIncomplete),
|
||||
backgroundColor: Theme.of(context).colorScheme.error,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _loadSettings() async {
|
||||
// Just populate with current repeater data on initial load
|
||||
// User must click sync button to fetch from device
|
||||
setState(() {
|
||||
_nameController.text = widget.repeater.name;
|
||||
|
||||
@@ -734,11 +813,18 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
});
|
||||
|
||||
try {
|
||||
final l10n = context.l10n;
|
||||
// Each pending command remembers the dirty-field it came from (null for
|
||||
// password commands, which always re-send when text is present). On
|
||||
// failure we keep that field in `_dirtyFields` so the Save button stays
|
||||
// available and the user can retry.
|
||||
final pending = <({_SettingField? field, String command})>[];
|
||||
final failures = <String>[];
|
||||
final retainDirty = <_SettingField>{};
|
||||
void reject(_SettingField field, String message) {
|
||||
failures.add(message);
|
||||
retainDirty.add(field);
|
||||
}
|
||||
|
||||
if (_dirtyFields.contains(_SettingField.name) &&
|
||||
_nameController.text.isNotEmpty) {
|
||||
@@ -768,9 +854,24 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
_bandwidth != null &&
|
||||
_spreadingFactor != null &&
|
||||
_codingRate != null) {
|
||||
final freqText = _freqController.text.trim();
|
||||
if (double.tryParse(freqText) != null) {
|
||||
final bwKHz = _bandwidth! / 1000;
|
||||
final freqText = _normalizeDecimal(_freqController.text);
|
||||
final freq = double.tryParse(freqText);
|
||||
final bwKHz = _bandwidth! / 1000;
|
||||
if (freq == null || freq < 150 || freq > 2500) {
|
||||
reject(_SettingField.radio, l10n.repeater_frequencyInvalid);
|
||||
} else if (bwKHz < 7.8 || bwKHz > 500) {
|
||||
reject(_SettingField.radio, '${l10n.repeater_bandwidth}: $bwKHz');
|
||||
} else if (_spreadingFactor! < 5 || _spreadingFactor! > 12) {
|
||||
reject(
|
||||
_SettingField.radio,
|
||||
'${l10n.repeater_spreadingFactor}: $_spreadingFactor',
|
||||
);
|
||||
} else if (_codingRate! < 5 || _codingRate! > 8) {
|
||||
reject(
|
||||
_SettingField.radio,
|
||||
'${l10n.repeater_codingRate}: $_codingRate',
|
||||
);
|
||||
} else {
|
||||
pending.add((
|
||||
field: _SettingField.radio,
|
||||
command:
|
||||
@@ -782,26 +883,46 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
if (_dirtyFields.contains(_SettingField.txPower) &&
|
||||
_txPowerController.text.isNotEmpty) {
|
||||
final dbm = int.tryParse(_txPowerController.text.trim());
|
||||
if (dbm != null) {
|
||||
if (dbm == null ||
|
||||
dbm < _minRepeaterTxPower ||
|
||||
dbm > _maxRepeaterTxPower) {
|
||||
reject(
|
||||
_SettingField.txPower,
|
||||
'${l10n.repeater_txPower}: ${_txPowerController.text.trim()} '
|
||||
'($_minRepeaterTxPower-$_maxRepeaterTxPower dBm)',
|
||||
);
|
||||
} else {
|
||||
pending.add((field: _SettingField.txPower, command: 'set tx $dbm'));
|
||||
}
|
||||
}
|
||||
|
||||
if (_dirtyFields.contains(_SettingField.lat) &&
|
||||
_latController.text.isNotEmpty &&
|
||||
_isValidCoordinate(_latController.text, 90)) {
|
||||
pending.add((
|
||||
field: _SettingField.lat,
|
||||
command: 'set lat ${_latController.text}',
|
||||
));
|
||||
_latController.text.isNotEmpty) {
|
||||
if (_isValidCoordinate(_latController.text, 90)) {
|
||||
pending.add((
|
||||
field: _SettingField.lat,
|
||||
command: 'set lat ${_normalizeDecimal(_latController.text)}',
|
||||
));
|
||||
} else {
|
||||
reject(
|
||||
_SettingField.lat,
|
||||
'${l10n.repeater_latitude}: ${_latController.text.trim()}',
|
||||
);
|
||||
}
|
||||
}
|
||||
if (_dirtyFields.contains(_SettingField.lon) &&
|
||||
_lonController.text.isNotEmpty &&
|
||||
_isValidCoordinate(_lonController.text, 180)) {
|
||||
pending.add((
|
||||
field: _SettingField.lon,
|
||||
command: 'set lon ${_lonController.text}',
|
||||
));
|
||||
_lonController.text.isNotEmpty) {
|
||||
if (_isValidCoordinate(_lonController.text, 180)) {
|
||||
pending.add((
|
||||
field: _SettingField.lon,
|
||||
command: 'set lon ${_normalizeDecimal(_lonController.text)}',
|
||||
));
|
||||
} else {
|
||||
reject(
|
||||
_SettingField.lon,
|
||||
'${l10n.repeater_longitude}: ${_lonController.text.trim()}',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (_dirtyFields.contains(_SettingField.repeat)) {
|
||||
@@ -882,32 +1003,50 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
}
|
||||
if (_dirtyFields.contains(_SettingField.txDelay) &&
|
||||
_txDelayController.text.isNotEmpty) {
|
||||
final v = double.tryParse(_txDelayController.text.trim());
|
||||
final v = double.tryParse(_normalizeDecimal(_txDelayController.text));
|
||||
if (v != null) {
|
||||
pending.add((
|
||||
field: _SettingField.txDelay,
|
||||
command: 'set txdelay $v',
|
||||
));
|
||||
} else {
|
||||
reject(
|
||||
_SettingField.txDelay,
|
||||
'${l10n.repeater_txDelay}: ${_txDelayController.text.trim()}',
|
||||
);
|
||||
}
|
||||
}
|
||||
if (_dirtyFields.contains(_SettingField.directTxDelay) &&
|
||||
_directTxDelayController.text.isNotEmpty) {
|
||||
final v = double.tryParse(_directTxDelayController.text.trim());
|
||||
final v = double.tryParse(
|
||||
_normalizeDecimal(_directTxDelayController.text),
|
||||
);
|
||||
if (v != null) {
|
||||
pending.add((
|
||||
field: _SettingField.directTxDelay,
|
||||
command: 'set direct.txdelay $v',
|
||||
));
|
||||
} else {
|
||||
reject(
|
||||
_SettingField.directTxDelay,
|
||||
'${l10n.repeater_directTxDelay}: '
|
||||
'${_directTxDelayController.text.trim()}',
|
||||
);
|
||||
}
|
||||
}
|
||||
if (_dirtyFields.contains(_SettingField.intThresh) &&
|
||||
_intThreshController.text.isNotEmpty) {
|
||||
final v = int.tryParse(_intThreshController.text.trim());
|
||||
if (v != null) {
|
||||
if (v != null && v >= 0 && v <= 255) {
|
||||
pending.add((
|
||||
field: _SettingField.intThresh,
|
||||
command: 'set int.thresh $v',
|
||||
));
|
||||
} else {
|
||||
reject(
|
||||
_SettingField.intThresh,
|
||||
'${l10n.repeater_intThresh}: ${_intThreshController.text.trim()}',
|
||||
);
|
||||
}
|
||||
}
|
||||
if (_dirtyFields.contains(_SettingField.agcResetInterval)) {
|
||||
@@ -917,8 +1056,6 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
));
|
||||
}
|
||||
|
||||
final failures = <String>[];
|
||||
final retainDirty = <_SettingField>{};
|
||||
var passwordsFailed = false;
|
||||
var rebootNeeded = false;
|
||||
for (final entry in pending) {
|
||||
@@ -951,6 +1088,7 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
}
|
||||
await Future.delayed(const Duration(milliseconds: 200));
|
||||
}
|
||||
if (!mounted) return;
|
||||
|
||||
// Only clear password fields if every password command succeeded —
|
||||
// otherwise the user keeps their typed value to retry.
|
||||
@@ -967,7 +1105,6 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
});
|
||||
|
||||
if (mounted) {
|
||||
final l10n = context.l10n;
|
||||
if (failures.isEmpty && rebootNeeded) {
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
@@ -990,11 +1127,10 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
});
|
||||
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
});
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(
|
||||
@@ -1011,9 +1147,12 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
_flagHasChanges();
|
||||
}
|
||||
|
||||
static String _normalizeDecimal(String text) =>
|
||||
text.trim().replaceAll(',', '.');
|
||||
|
||||
static bool _isValidCoordinate(String text, double max) {
|
||||
if (text.trim().isEmpty) return true;
|
||||
final value = double.tryParse(text.trim());
|
||||
final value = double.tryParse(_normalizeDecimal(text));
|
||||
return value != null && value >= -max && value <= max;
|
||||
}
|
||||
|
||||
@@ -1095,13 +1234,24 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
onPressed: () =>
|
||||
ContactRoutingSheet.show(context, contact: repeater),
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.refresh),
|
||||
tooltip: l10n.repeater_refreshAll,
|
||||
onPressed: _loadingAll || _isLoading ? null : _refreshAll,
|
||||
),
|
||||
if (_hasChanges)
|
||||
TextButton.icon(
|
||||
onPressed: _isLoading ? null : _saveSettings,
|
||||
onPressed: _isLoading || _loadingAll ? null : _saveSettings,
|
||||
icon: const Icon(Icons.save),
|
||||
label: Text(l10n.common_save),
|
||||
),
|
||||
],
|
||||
bottom: _loadingAll
|
||||
? PreferredSize(
|
||||
preferredSize: const Size.fromHeight(4),
|
||||
child: LinearProgressIndicator(value: _loadAllProgress),
|
||||
)
|
||||
: null,
|
||||
),
|
||||
body: SafeArea(
|
||||
top: false,
|
||||
@@ -1110,6 +1260,27 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
: ListView(
|
||||
padding: const EdgeInsets.only(bottom: 32),
|
||||
children: [
|
||||
if (_loadedKeys.isEmpty && !_loadingAll)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 16),
|
||||
child: MeshCard(
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.info_outline, size: 20),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Text(
|
||||
context.l10n.repeater_settingsNotLoaded,
|
||||
),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: _isLoading ? null : _refreshAll,
|
||||
child: Text(context.l10n.repeater_refreshAll),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
_buildBasicSettingsCard(),
|
||||
_buildRadioSettingsCard(),
|
||||
_buildLocationSettingsCard(),
|
||||
@@ -1153,10 +1324,14 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
children: [
|
||||
TextField(
|
||||
controller: _nameController,
|
||||
enabled: _loaded('name'),
|
||||
decoration: InputDecoration(
|
||||
labelText: l10n.repeater_repeaterName,
|
||||
helperText: l10n.repeater_repeaterNameHelper,
|
||||
),
|
||||
inputFormatters: const [
|
||||
Utf8LengthLimitingTextInputFormatter(_maxNameBytes),
|
||||
],
|
||||
onChanged: (_) => _markChanged(_SettingField.name),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
@@ -1167,6 +1342,9 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
helperText: l10n.repeater_adminPasswordHelper,
|
||||
),
|
||||
obscureText: true,
|
||||
inputFormatters: const [
|
||||
Utf8LengthLimitingTextInputFormatter(_maxPasswordBytes),
|
||||
],
|
||||
onChanged: (_) => _flagHasChanges(),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
@@ -1177,6 +1355,9 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
helperText: l10n.repeater_guestPasswordHelper,
|
||||
),
|
||||
obscureText: true,
|
||||
inputFormatters: const [
|
||||
Utf8LengthLimitingTextInputFormatter(_maxPasswordBytes),
|
||||
],
|
||||
onChanged: (_) => _flagHasChanges(),
|
||||
),
|
||||
],
|
||||
@@ -1211,9 +1392,10 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
children: [
|
||||
TextField(
|
||||
controller: _freqController,
|
||||
enabled: _loaded('radio'),
|
||||
decoration: InputDecoration(
|
||||
labelText: l10n.repeater_frequencyMhz,
|
||||
helperText: l10n.repeater_frequencyHelper,
|
||||
helperText: l10n.repeater_frequencyRangeHelper,
|
||||
suffixText: 'MHz',
|
||||
),
|
||||
keyboardType: const TextInputType.numberWithOptions(
|
||||
@@ -1228,12 +1410,15 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
Expanded(
|
||||
child: TextField(
|
||||
controller: _txPowerController,
|
||||
enabled: _loaded('tx'),
|
||||
decoration: InputDecoration(
|
||||
labelText: l10n.repeater_txPower,
|
||||
helperText: l10n.repeater_txPowerHelper,
|
||||
helperText: l10n.repeater_txPowerRangeHelper,
|
||||
suffixText: 'dBm',
|
||||
),
|
||||
keyboardType: TextInputType.number,
|
||||
keyboardType: const TextInputType.numberWithOptions(
|
||||
signed: true,
|
||||
),
|
||||
onChanged: (_) => _markChanged(_SettingField.txPower),
|
||||
),
|
||||
),
|
||||
@@ -1254,14 +1439,16 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
child: Text(_formatBandwidthLabel(bw)),
|
||||
);
|
||||
}).toList(),
|
||||
onChanged: (value) {
|
||||
if (value != null) {
|
||||
setState(() {
|
||||
_bandwidth = value;
|
||||
});
|
||||
_markChanged(_SettingField.radio);
|
||||
}
|
||||
},
|
||||
onChanged: !_loaded('radio')
|
||||
? null
|
||||
: (value) {
|
||||
if (value != null) {
|
||||
setState(() {
|
||||
_bandwidth = value;
|
||||
});
|
||||
_markChanged(_SettingField.radio);
|
||||
}
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
DropdownButtonFormField<int>(
|
||||
@@ -1272,14 +1459,16 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
items: _spreadingFactorOptions.map((sf) {
|
||||
return DropdownMenuItem(value: sf, child: Text('SF$sf'));
|
||||
}).toList(),
|
||||
onChanged: (value) {
|
||||
if (value != null) {
|
||||
setState(() {
|
||||
_spreadingFactor = value;
|
||||
});
|
||||
_markChanged(_SettingField.radio);
|
||||
}
|
||||
},
|
||||
onChanged: !_loaded('radio')
|
||||
? null
|
||||
: (value) {
|
||||
if (value != null) {
|
||||
setState(() {
|
||||
_spreadingFactor = value;
|
||||
});
|
||||
_markChanged(_SettingField.radio);
|
||||
}
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
DropdownButtonFormField<int>(
|
||||
@@ -1290,20 +1479,23 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
items: _codingRateOptions.map((cr) {
|
||||
return DropdownMenuItem(value: cr, child: Text('4/$cr'));
|
||||
}).toList(),
|
||||
onChanged: (value) {
|
||||
if (value != null) {
|
||||
setState(() {
|
||||
_codingRate = value;
|
||||
});
|
||||
_markChanged(_SettingField.radio);
|
||||
}
|
||||
},
|
||||
onChanged: !_loaded('radio')
|
||||
? null
|
||||
: (value) {
|
||||
if (value != null) {
|
||||
setState(() {
|
||||
_codingRate = value;
|
||||
});
|
||||
_markChanged(_SettingField.radio);
|
||||
}
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
_buildFeatureToggleRow(
|
||||
title: l10n.repeater_rxGain,
|
||||
subtitle: l10n.repeater_rxGainHelper,
|
||||
value: _rxGainBoosted,
|
||||
loaded: _loaded('radio.rxgain'),
|
||||
isRefreshing: _refreshingRxGain,
|
||||
onChanged: (v) {
|
||||
setState(() => _rxGainBoosted = v);
|
||||
@@ -1335,6 +1527,7 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
Expanded(
|
||||
child: TextField(
|
||||
controller: _latController,
|
||||
enabled: _loaded('lat'),
|
||||
decoration: InputDecoration(
|
||||
labelText: l10n.repeater_latitude,
|
||||
helperText: l10n.repeater_latitudeHelper,
|
||||
@@ -1369,6 +1562,7 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
Expanded(
|
||||
child: TextField(
|
||||
controller: _lonController,
|
||||
enabled: _loaded('lon'),
|
||||
decoration: InputDecoration(
|
||||
labelText: l10n.repeater_longitude,
|
||||
helperText: l10n.repeater_longitudeHelper,
|
||||
@@ -1417,6 +1611,7 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
title: l10n.repeater_packetForwarding,
|
||||
subtitle: l10n.repeater_packetForwardingSubtitle,
|
||||
value: _repeatEnabled,
|
||||
loaded: _loaded('repeat'),
|
||||
isRefreshing: _refreshingRepeat,
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
@@ -1431,6 +1626,7 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
title: l10n.repeater_guestAccess,
|
||||
subtitle: l10n.repeater_guestAccessSubtitle,
|
||||
value: _allowReadOnly,
|
||||
loaded: _loaded('allow.read.only'),
|
||||
isRefreshing: _refreshingAllowReadOnly,
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
@@ -1445,6 +1641,7 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
title: l10n.repeater_multiAcks,
|
||||
subtitle: l10n.repeater_multiAcksSubtitle,
|
||||
value: _multiAcks,
|
||||
loaded: _loaded('multi.acks'),
|
||||
isRefreshing: _refreshingMultiAcks,
|
||||
onChanged: (v) {
|
||||
setState(() => _multiAcks = v);
|
||||
@@ -1479,6 +1676,7 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
required String title,
|
||||
required String subtitle,
|
||||
required bool value,
|
||||
required bool loaded,
|
||||
required bool isRefreshing,
|
||||
required ValueChanged<bool> onChanged,
|
||||
required VoidCallback onRefresh,
|
||||
@@ -1490,8 +1688,8 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
child: SwitchListTile(
|
||||
title: Text(title),
|
||||
subtitle: Text(subtitle),
|
||||
value: value,
|
||||
onChanged: onChanged,
|
||||
value: loaded && value,
|
||||
onChanged: loaded ? onChanged : null,
|
||||
contentPadding: EdgeInsets.zero,
|
||||
),
|
||||
),
|
||||
@@ -1527,19 +1725,23 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
child: ListTile(
|
||||
title: Text(l10n.repeater_localAdvertInterval),
|
||||
subtitle: Text(
|
||||
l10n.repeater_localAdvertIntervalMinutes(
|
||||
_advertInterval,
|
||||
),
|
||||
_loaded('advert.interval')
|
||||
? l10n.repeater_localAdvertIntervalMinutes(
|
||||
_advertInterval,
|
||||
)
|
||||
: '—',
|
||||
),
|
||||
trailing: Switch(
|
||||
value: _advertEnable,
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
_advertInterval = value ? 60 : 0;
|
||||
_advertEnable = value;
|
||||
});
|
||||
_markChanged(_SettingField.advertInterval);
|
||||
},
|
||||
value: _loaded('advert.interval') && _advertEnable,
|
||||
onChanged: !_loaded('advert.interval')
|
||||
? null
|
||||
: (value) {
|
||||
setState(() {
|
||||
_advertInterval = value ? 60 : 0;
|
||||
_advertEnable = value;
|
||||
});
|
||||
_markChanged(_SettingField.advertInterval);
|
||||
},
|
||||
),
|
||||
contentPadding: EdgeInsets.zero,
|
||||
),
|
||||
@@ -1561,16 +1763,14 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
],
|
||||
),
|
||||
Slider(
|
||||
value: _advertInterval == 0
|
||||
? 60.toDouble()
|
||||
: _advertInterval.toDouble(),
|
||||
value: _advertInterval.clamp(60, 240).toDouble(),
|
||||
min: 60,
|
||||
max: 240,
|
||||
divisions: 18,
|
||||
label: l10n.repeater_localAdvertIntervalMinutes(
|
||||
_advertInterval,
|
||||
),
|
||||
onChanged: _advertEnable
|
||||
onChanged: _advertEnable && _loaded('advert.interval')
|
||||
? (value) {
|
||||
setState(() {
|
||||
_advertInterval = value.toInt();
|
||||
@@ -1586,19 +1786,25 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
child: ListTile(
|
||||
title: Text(l10n.repeater_floodAdvertInterval),
|
||||
subtitle: Text(
|
||||
l10n.repeater_floodAdvertIntervalHours(
|
||||
_floodAdvertInterval,
|
||||
),
|
||||
_loaded('flood.advert.interval')
|
||||
? l10n.repeater_floodAdvertIntervalHours(
|
||||
_floodAdvertInterval,
|
||||
)
|
||||
: '—',
|
||||
),
|
||||
trailing: Switch(
|
||||
value: _floodAdvertEnable,
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
_floodAdvertInterval = value ? 3 : 0;
|
||||
_floodAdvertEnable = value;
|
||||
});
|
||||
_markChanged(_SettingField.floodAdvertInterval);
|
||||
},
|
||||
value:
|
||||
_loaded('flood.advert.interval') &&
|
||||
_floodAdvertEnable,
|
||||
onChanged: !_loaded('flood.advert.interval')
|
||||
? null
|
||||
: (value) {
|
||||
setState(() {
|
||||
_floodAdvertInterval = value ? 3 : 0;
|
||||
_floodAdvertEnable = value;
|
||||
});
|
||||
_markChanged(_SettingField.floodAdvertInterval);
|
||||
},
|
||||
),
|
||||
contentPadding: EdgeInsets.zero,
|
||||
),
|
||||
@@ -1620,16 +1826,15 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
],
|
||||
),
|
||||
Slider(
|
||||
value: _floodAdvertInterval == 0
|
||||
? 3.toDouble()
|
||||
: _floodAdvertInterval.toDouble(),
|
||||
value: _floodAdvertInterval.clamp(3, 168).toDouble(),
|
||||
min: 3,
|
||||
max: 168,
|
||||
divisions: 165,
|
||||
label: l10n.repeater_floodAdvertIntervalHours(
|
||||
_floodAdvertInterval,
|
||||
),
|
||||
onChanged: _floodAdvertEnable
|
||||
onChanged:
|
||||
_floodAdvertEnable && _loaded('flood.advert.interval')
|
||||
? (value) {
|
||||
setState(() {
|
||||
_floodAdvertInterval = value.toInt();
|
||||
@@ -1646,7 +1851,7 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
title: Text(l10n.repeater_floodMax),
|
||||
subtitle: Text(l10n.repeater_floodMaxHelper),
|
||||
trailing: Text(
|
||||
'$_floodMax',
|
||||
_loaded('flood.max') ? '$_floodMax' : '—',
|
||||
style: const TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
contentPadding: EdgeInsets.zero,
|
||||
@@ -1672,10 +1877,12 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
max: 64,
|
||||
divisions: 64,
|
||||
label: '$_floodMax',
|
||||
onChanged: (v) {
|
||||
setState(() => _floodMax = v.toInt());
|
||||
_markChanged(_SettingField.floodMax);
|
||||
},
|
||||
onChanged: !_loaded('flood.max')
|
||||
? null
|
||||
: (v) {
|
||||
setState(() => _floodMax = v.toInt());
|
||||
_markChanged(_SettingField.floodMax);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -1699,7 +1906,7 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
children: [
|
||||
Expanded(
|
||||
child: DropdownButtonFormField<String>(
|
||||
initialValue: _loopDetect,
|
||||
initialValue: _loaded('loop.detect') ? _loopDetect : null,
|
||||
decoration: InputDecoration(
|
||||
labelText: l10n.repeater_loopDetect,
|
||||
helperText: l10n.repeater_loopDetectHelper,
|
||||
@@ -1723,12 +1930,14 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
child: Text(l10n.repeater_loopDetectStrict),
|
||||
),
|
||||
],
|
||||
onChanged: (v) {
|
||||
if (v != null) {
|
||||
setState(() => _loopDetect = v);
|
||||
_markChanged(_SettingField.loopDetect);
|
||||
}
|
||||
},
|
||||
onChanged: !_loaded('loop.detect')
|
||||
? null
|
||||
: (v) {
|
||||
if (v != null) {
|
||||
setState(() => _loopDetect = v);
|
||||
_markChanged(_SettingField.loopDetect);
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
_buildInlineRefreshButton(
|
||||
@@ -1746,7 +1955,9 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
title: Text(l10n.repeater_dutyCycle),
|
||||
subtitle: Text(l10n.repeater_dutyCycleHelper),
|
||||
trailing: Text(
|
||||
l10n.repeater_dutyCyclePercent(_dutyCycle),
|
||||
_loaded('dutycycle')
|
||||
? l10n.repeater_dutyCyclePercent(_dutyCycle)
|
||||
: '—',
|
||||
style: const TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
contentPadding: EdgeInsets.zero,
|
||||
@@ -1772,10 +1983,12 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
max: 100,
|
||||
divisions: 99,
|
||||
label: l10n.repeater_dutyCyclePercent(_dutyCycle),
|
||||
onChanged: (v) {
|
||||
setState(() => _dutyCycle = v.toInt());
|
||||
_markChanged(_SettingField.dutyCycle);
|
||||
},
|
||||
onChanged: !_loaded('dutycycle')
|
||||
? null
|
||||
: (v) {
|
||||
setState(() => _dutyCycle = v.toInt());
|
||||
_markChanged(_SettingField.dutyCycle);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -1806,6 +2019,7 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
MeshCard(
|
||||
child: TextField(
|
||||
controller: _ownerInfoController,
|
||||
enabled: _loaded('owner.info'),
|
||||
decoration: InputDecoration(
|
||||
labelText: l10n.repeater_ownerInfo,
|
||||
helperText: l10n.repeater_ownerInfoHelper,
|
||||
@@ -1813,6 +2027,9 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
),
|
||||
maxLines: 4,
|
||||
minLines: 2,
|
||||
inputFormatters: const [
|
||||
Utf8LengthLimitingTextInputFormatter(_maxOwnerInfoBytes),
|
||||
],
|
||||
onChanged: (_) => _markChanged(_SettingField.ownerInfo),
|
||||
),
|
||||
),
|
||||
@@ -1887,23 +2104,36 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
children: [
|
||||
Expanded(
|
||||
child: DropdownButtonFormField<int>(
|
||||
initialValue: _pathHashMode,
|
||||
initialValue: _loaded('path.hash.mode')
|
||||
? _pathHashMode
|
||||
: null,
|
||||
decoration: InputDecoration(
|
||||
labelText: l10n.repeater_pathHashMode,
|
||||
helperText: l10n.repeater_pathHashModeHelper,
|
||||
helperMaxLines: 5,
|
||||
),
|
||||
items: const [
|
||||
DropdownMenuItem(value: 0, child: Text('0')),
|
||||
DropdownMenuItem(value: 1, child: Text('1')),
|
||||
DropdownMenuItem(value: 2, child: Text('2')),
|
||||
items: [
|
||||
DropdownMenuItem(
|
||||
value: 0,
|
||||
child: Text(l10n.repeater_pathHashModeOption0),
|
||||
),
|
||||
DropdownMenuItem(
|
||||
value: 1,
|
||||
child: Text(l10n.repeater_pathHashModeOption1),
|
||||
),
|
||||
DropdownMenuItem(
|
||||
value: 2,
|
||||
child: Text(l10n.repeater_pathHashModeOption2),
|
||||
),
|
||||
],
|
||||
onChanged: (v) {
|
||||
if (v != null) {
|
||||
setState(() => _pathHashMode = v);
|
||||
_markChanged(_SettingField.pathHashMode);
|
||||
}
|
||||
},
|
||||
onChanged: !_loaded('path.hash.mode')
|
||||
? null
|
||||
: (v) {
|
||||
if (v != null) {
|
||||
setState(() => _pathHashMode = v);
|
||||
_markChanged(_SettingField.pathHashMode);
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
_buildInlineRefreshButton(
|
||||
@@ -1920,6 +2150,7 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
Expanded(
|
||||
child: TextField(
|
||||
controller: _txDelayController,
|
||||
enabled: _loaded('txdelay'),
|
||||
decoration: InputDecoration(
|
||||
labelText: l10n.repeater_txDelay,
|
||||
helperText: l10n.repeater_txDelayHelper,
|
||||
@@ -1945,6 +2176,7 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
Expanded(
|
||||
child: TextField(
|
||||
controller: _directTxDelayController,
|
||||
enabled: _loaded('direct.txdelay'),
|
||||
decoration: InputDecoration(
|
||||
labelText: l10n.repeater_directTxDelay,
|
||||
helperText: l10n.repeater_directTxDelayHelper,
|
||||
@@ -1970,6 +2202,7 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
Expanded(
|
||||
child: TextField(
|
||||
controller: _intThreshController,
|
||||
enabled: _loaded('int.thresh'),
|
||||
decoration: InputDecoration(
|
||||
labelText: l10n.repeater_intThresh,
|
||||
helperText: l10n.repeater_intThreshHelper,
|
||||
@@ -1994,7 +2227,9 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
title: Text(l10n.repeater_agcResetInterval),
|
||||
subtitle: Text(l10n.repeater_agcResetIntervalHelper),
|
||||
trailing: Text(
|
||||
'${_agcResetInterval}s',
|
||||
_loaded('agc.reset.interval')
|
||||
? '${_agcResetInterval}s'
|
||||
: '—',
|
||||
style: const TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
contentPadding: EdgeInsets.zero,
|
||||
@@ -2017,18 +2252,20 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
],
|
||||
),
|
||||
Slider(
|
||||
value: _agcResetInterval.toDouble(),
|
||||
value: _agcResetInterval.clamp(0, _maxAgcResetInterval).toDouble(),
|
||||
min: 0,
|
||||
max: 240,
|
||||
divisions: 60,
|
||||
max: _maxAgcResetInterval.toDouble(),
|
||||
divisions: _maxAgcResetInterval ~/ 4,
|
||||
label: '${_agcResetInterval}s',
|
||||
onChanged: (v) {
|
||||
setState(() {
|
||||
// Clamp to multiple of 4 to match firmware semantics.
|
||||
_agcResetInterval = (v.toInt() ~/ 4) * 4;
|
||||
});
|
||||
_markChanged(_SettingField.agcResetInterval);
|
||||
},
|
||||
onChanged: !_loaded('agc.reset.interval')
|
||||
? null
|
||||
: (v) {
|
||||
setState(() {
|
||||
// Clamp to multiple of 4 to match firmware semantics.
|
||||
_agcResetInterval = (v.toInt() ~/ 4) * 4;
|
||||
});
|
||||
_markChanged(_SettingField.agcResetInterval);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:typed_data';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import '../l10n/l10n.dart';
|
||||
import '../models/contact.dart';
|
||||
import '../models/path_selection.dart';
|
||||
import '../models/remote_node_stats.dart';
|
||||
import '../connector/meshcore_connector.dart';
|
||||
import '../connector/meshcore_protocol.dart';
|
||||
import '../services/app_settings_service.dart';
|
||||
@@ -32,10 +32,7 @@ class RepeaterStatusScreen extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _RepeaterStatusScreenState extends State<RepeaterStatusScreen> {
|
||||
static const int _statusPayloadOffset = 8;
|
||||
static const int _statusStatsSize = 52;
|
||||
static const int _statusResponseBytes =
|
||||
_statusPayloadOffset + _statusStatsSize;
|
||||
static const int _statusResponseBytes = RemoteNodeStats.payloadOffset + 56;
|
||||
|
||||
bool _isLoading = false;
|
||||
StreamSubscription<Uint8List>? _frameSubscription;
|
||||
@@ -50,6 +47,9 @@ class _RepeaterStatusScreenState extends State<RepeaterStatusScreen> {
|
||||
int? _noiseFloor;
|
||||
int? _txAirSecs;
|
||||
int? _rxAirSecs;
|
||||
int? _recvErrors;
|
||||
int? _posted;
|
||||
int? _postPushes;
|
||||
int? _packetsSent;
|
||||
int? _packetsRecv;
|
||||
int? _floodTx;
|
||||
@@ -124,72 +124,39 @@ class _RepeaterStatusScreenState extends State<RepeaterStatusScreen> {
|
||||
if (frame.length < 8) return;
|
||||
final prefix = frame.sublist(2, 8);
|
||||
if (!_matchesRepeaterPrefix(prefix)) return;
|
||||
if (frame.length < _statusResponseBytes) return;
|
||||
|
||||
final data = ByteData.sublistView(
|
||||
frame,
|
||||
_statusPayloadOffset,
|
||||
_statusResponseBytes,
|
||||
);
|
||||
int offset = 0;
|
||||
|
||||
final batteryMv = data.getUint16(offset, Endian.little);
|
||||
offset += 2;
|
||||
final queueLen = data.getUint16(offset, Endian.little);
|
||||
offset += 2;
|
||||
final noiseFloor = data.getInt16(offset, Endian.little);
|
||||
offset += 2;
|
||||
final lastRssi = data.getInt16(offset, Endian.little);
|
||||
offset += 2;
|
||||
final packetsRecv = data.getUint32(offset, Endian.little);
|
||||
offset += 4;
|
||||
final packetsSent = data.getUint32(offset, Endian.little);
|
||||
offset += 4;
|
||||
final txAirSecs = data.getUint32(offset, Endian.little);
|
||||
offset += 4;
|
||||
final uptimeSecs = data.getUint32(offset, Endian.little);
|
||||
offset += 4;
|
||||
final floodTx = data.getUint32(offset, Endian.little);
|
||||
offset += 4;
|
||||
final directTx = data.getUint32(offset, Endian.little);
|
||||
offset += 4;
|
||||
final floodRx = data.getUint32(offset, Endian.little);
|
||||
offset += 4;
|
||||
final directRx = data.getUint32(offset, Endian.little);
|
||||
offset += 4;
|
||||
final errEvents = data.getUint16(offset, Endian.little);
|
||||
offset += 2;
|
||||
final lastSnrRaw = data.getInt16(offset, Endian.little);
|
||||
offset += 2;
|
||||
final directDups = data.getUint16(offset, Endian.little);
|
||||
offset += 2;
|
||||
final floodDups = data.getUint16(offset, Endian.little);
|
||||
offset += 2;
|
||||
final rxAirSecs = data.getUint32(offset, Endian.little);
|
||||
final stats = RemoteNodeStats.tryParse(frame, isRoom: _isRoom);
|
||||
if (stats == null) return;
|
||||
|
||||
_statusTimeout?.cancel();
|
||||
if (!mounted) return;
|
||||
final rxAirSecs = stats.rxAirSecs;
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
_batteryMv = batteryMv;
|
||||
_queueLen = queueLen;
|
||||
_noiseFloor = noiseFloor;
|
||||
_lastRssi = lastRssi;
|
||||
_packetsRecv = packetsRecv;
|
||||
_packetsSent = packetsSent;
|
||||
_txAirSecs = txAirSecs;
|
||||
_batteryMv = stats.batteryMv;
|
||||
_queueLen = stats.queueLen;
|
||||
_noiseFloor = stats.noiseFloor;
|
||||
_lastRssi = stats.lastRssi;
|
||||
_packetsRecv = stats.packetsRecv;
|
||||
_packetsSent = stats.packetsSent;
|
||||
_txAirSecs = stats.txAirSecs;
|
||||
_rxAirSecs = rxAirSecs;
|
||||
_uptimeSecs = uptimeSecs;
|
||||
_floodTx = floodTx;
|
||||
_directTx = directTx;
|
||||
_floodRx = floodRx;
|
||||
_directRx = directRx;
|
||||
_debugFlags = errEvents;
|
||||
_lastSnr = lastSnrRaw / 4.0;
|
||||
_dupDirect = directDups;
|
||||
_dupFlood = floodDups;
|
||||
_chanUtil = ((txAirSecs + rxAirSecs) / uptimeSecs) * 100;
|
||||
_recvErrors = stats.recvErrors;
|
||||
_posted = stats.posted;
|
||||
_postPushes = stats.postPushes;
|
||||
_uptimeSecs = stats.uptimeSecs;
|
||||
_floodTx = stats.floodTx;
|
||||
_directTx = stats.directTx;
|
||||
_floodRx = stats.floodRx;
|
||||
_directRx = stats.directRx;
|
||||
_debugFlags = stats.errEvents;
|
||||
_lastSnr = stats.lastSnr;
|
||||
_dupDirect = stats.directDups;
|
||||
_dupFlood = stats.floodDups;
|
||||
_chanUtil = rxAirSecs != null && stats.uptimeSecs > 0
|
||||
? ((stats.txAirSecs + rxAirSecs) / stats.uptimeSecs) * 100
|
||||
: null;
|
||||
});
|
||||
final batteryMv = stats.batteryMv;
|
||||
final connector = Provider.of<MeshCoreConnector>(context, listen: false);
|
||||
connector.updateRepeaterBatterySnapshot(
|
||||
widget.repeater.publicKeyHex,
|
||||
@@ -199,6 +166,8 @@ class _RepeaterStatusScreenState extends State<RepeaterStatusScreen> {
|
||||
_recordStatusResult(true);
|
||||
}
|
||||
|
||||
bool get _isRoom => widget.repeater.type == advTypeRoom;
|
||||
|
||||
bool _matchesRepeaterPrefix(Uint8List prefix) {
|
||||
final target = widget.repeater.publicKey;
|
||||
if (target.length < 6 || prefix.length < 6) return false;
|
||||
@@ -266,6 +235,9 @@ class _RepeaterStatusScreenState extends State<RepeaterStatusScreen> {
|
||||
_noiseFloor = null;
|
||||
_txAirSecs = null;
|
||||
_rxAirSecs = null;
|
||||
_recvErrors = null;
|
||||
_posted = null;
|
||||
_postPushes = null;
|
||||
_packetsSent = null;
|
||||
_packetsRecv = null;
|
||||
_floodTx = null;
|
||||
@@ -551,12 +523,13 @@ class _RepeaterStatusScreenState extends State<RepeaterStatusScreen> {
|
||||
value: _formatDuration(_txAirSecs),
|
||||
color: MeshPalette.warn,
|
||||
),
|
||||
_StatItem(
|
||||
icon: Icons.download,
|
||||
label: l10n.repeater_rxAirtime,
|
||||
value: _formatDuration(_rxAirSecs),
|
||||
color: MeshPalette.signal,
|
||||
),
|
||||
if (!_isRoom)
|
||||
_StatItem(
|
||||
icon: Icons.download,
|
||||
label: l10n.repeater_rxAirtime,
|
||||
value: _formatDuration(_rxAirSecs),
|
||||
color: MeshPalette.signal,
|
||||
),
|
||||
]),
|
||||
),
|
||||
|
||||
@@ -583,16 +556,39 @@ class _RepeaterStatusScreenState extends State<RepeaterStatusScreen> {
|
||||
value: _duplicateText(),
|
||||
color: scheme.onSurfaceVariant,
|
||||
),
|
||||
_StatItem(
|
||||
icon: Icons.percent,
|
||||
label: l10n.repeater_chanUtil,
|
||||
value: _chanUtilText(),
|
||||
color: _chanUtil != null && _chanUtil! > 80
|
||||
? MeshPalette.alert
|
||||
: _chanUtil != null && _chanUtil! > 50
|
||||
? MeshPalette.warn
|
||||
: MeshPalette.signal,
|
||||
),
|
||||
if (_isRoom) ...[
|
||||
_StatItem(
|
||||
icon: Icons.forum_outlined,
|
||||
label: l10n.room_postsStored,
|
||||
value: _formatValue(_posted),
|
||||
color: MeshPalette.blue,
|
||||
),
|
||||
_StatItem(
|
||||
icon: Icons.outbox,
|
||||
label: l10n.room_postsPushed,
|
||||
value: _formatValue(_postPushes),
|
||||
color: MeshPalette.signal,
|
||||
),
|
||||
] else
|
||||
_StatItem(
|
||||
icon: Icons.error_outline,
|
||||
label: l10n.repeater_recvErrors,
|
||||
value: _formatValue(_recvErrors),
|
||||
color: _recvErrors != null && _recvErrors! > 0
|
||||
? MeshPalette.warn
|
||||
: scheme.onSurfaceVariant,
|
||||
),
|
||||
if (!_isRoom)
|
||||
_StatItem(
|
||||
icon: Icons.percent,
|
||||
label: l10n.repeater_chanUtil,
|
||||
value: _chanUtilText(),
|
||||
color: _chanUtil != null && _chanUtil! > 80
|
||||
? MeshPalette.alert
|
||||
: _chanUtil != null && _chanUtil! > 50
|
||||
? MeshPalette.warn
|
||||
: MeshPalette.signal,
|
||||
),
|
||||
]),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
@@ -618,23 +614,33 @@ class _RepeaterStatusScreenState extends State<RepeaterStatusScreen> {
|
||||
}
|
||||
|
||||
Widget _buildStatGrid(List<_StatItem> items) {
|
||||
return GridView.count(
|
||||
crossAxisCount: 2,
|
||||
shrinkWrap: true,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
mainAxisSpacing: 8,
|
||||
crossAxisSpacing: 8,
|
||||
childAspectRatio: 2.2,
|
||||
children: items
|
||||
.map(
|
||||
(item) => StatTile(
|
||||
final textScaler = MediaQuery.textScalerOf(context);
|
||||
return LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
final columns = constraints.maxWidth / textScaler.scale(1) < 320
|
||||
? 1
|
||||
: 2;
|
||||
return GridView.builder(
|
||||
shrinkWrap: true,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
itemCount: items.length,
|
||||
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisCount: columns,
|
||||
mainAxisSpacing: 8,
|
||||
crossAxisSpacing: 8,
|
||||
mainAxisExtent: textScaler.scale(52) + 28,
|
||||
),
|
||||
itemBuilder: (context, index) {
|
||||
final item = items[index];
|
||||
return StatTile(
|
||||
icon: item.icon,
|
||||
label: item.label,
|
||||
value: item.value,
|
||||
color: item.color,
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import '../widgets/device_tile.dart';
|
||||
import '../widgets/empty_state.dart';
|
||||
import '../widgets/mesh_ui.dart';
|
||||
import '../helpers/snack_bar_builder.dart';
|
||||
import '../review_mode/review_mode_entry.dart';
|
||||
import 'channels_screen.dart';
|
||||
import 'tcp_screen.dart';
|
||||
import 'usb_screen.dart';
|
||||
@@ -103,7 +104,9 @@ class _ScannerScreenState extends State<ScannerScreen> {
|
||||
},
|
||||
)
|
||||
: null,
|
||||
title: AdaptiveAppBarTitle(context.l10n.scanner_title),
|
||||
title: ReviewModeLongPress(
|
||||
child: AdaptiveAppBarTitle(context.l10n.scanner_title),
|
||||
),
|
||||
centerTitle: true,
|
||||
automaticallyImplyLeading: false,
|
||||
actions: [
|
||||
|
||||
@@ -20,6 +20,7 @@ import 'app_settings_screen.dart';
|
||||
import 'app_debug_log_screen.dart';
|
||||
import 'ble_debug_log_screen.dart';
|
||||
import '../widgets/radio_stats_entry.dart';
|
||||
import 'telemetry_screen.dart';
|
||||
import '../widgets/sync_progress_overlay.dart';
|
||||
import 'region_management_screen.dart';
|
||||
|
||||
@@ -29,15 +30,24 @@ int _toUiCodingRate(int deviceCr) {
|
||||
return deviceCr <= 4 ? deviceCr + 4 : deviceCr;
|
||||
}
|
||||
|
||||
/// Convert UI coding-rate value (5-8) back to firmware encoding.
|
||||
/// Uses the current device CR to detect which encoding the firmware expects.
|
||||
int _toDeviceCodingRate(int uiCr, int? deviceCr) {
|
||||
if (deviceCr != null && deviceCr <= 4) {
|
||||
return uiCr - 4;
|
||||
const Set<int> _defaultRepeatFreqsKHz = {433000, 869495, 918000};
|
||||
|
||||
/// Whether the firmware accepts [freqKHz] for off-grid client repeat, using
|
||||
/// the ranges from CMD_GET_ALLOWED_REPEAT_FREQ when known.
|
||||
bool _isAllowedRepeatFreqKHz(MeshCoreConnector connector, int freqKHz) {
|
||||
final ranges = connector.allowedRepeatFreqRanges;
|
||||
if (ranges == null || ranges.isEmpty) {
|
||||
return _defaultRepeatFreqsKHz.contains(freqKHz);
|
||||
}
|
||||
return uiCr;
|
||||
return ranges.any((r) => freqKHz >= r.lowKHz && freqKHz <= r.highKHz);
|
||||
}
|
||||
|
||||
/// Companion firmware version that added CMD_SET_PATH_HASH_MODE (v1.14.0).
|
||||
const int _minFirmwareVerCodeForPathHashMode = 10;
|
||||
|
||||
/// Lowest TX power companion firmware accepts (CMD_SET_RADIO_TX_POWER).
|
||||
const int _minTxPowerDbm = -9;
|
||||
|
||||
class SettingsScreen extends StatefulWidget {
|
||||
const SettingsScreen({super.key});
|
||||
|
||||
@@ -499,18 +509,39 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
context,
|
||||
icon: Icons.sensors_outlined,
|
||||
title: l10n.radioStats_settingsTile,
|
||||
subtitle: l10n.radioStats_settingsSubtitle,
|
||||
subtitle:
|
||||
connector.isConnected && !connector.supportsCompanionRadioStats
|
||||
? l10n.settings_requiresFirmware('v1.10')
|
||||
: l10n.radioStats_settingsSubtitle,
|
||||
onTap: connector.isConnected && connector.supportsCompanionRadioStats
|
||||
? () => pushCompanionRadioStatsScreen(context)
|
||||
: null,
|
||||
),
|
||||
const Divider(height: 1, indent: 16),
|
||||
_tappableTile(
|
||||
context,
|
||||
icon: Icons.thermostat_outlined,
|
||||
title: l10n.contact_telemetry,
|
||||
subtitle: l10n.repeater_telemetrySubtitle,
|
||||
onTap: connector.isConnected
|
||||
? () => pushSelfTelemetryScreen(context)
|
||||
: null,
|
||||
),
|
||||
const Divider(height: 1, indent: 16),
|
||||
_tappableTile(
|
||||
context,
|
||||
icon: Icons.route_outlined,
|
||||
title: l10n.repeater_pathHashMode,
|
||||
subtitle: _pathHashModeSubtitle(context, connector.pathHashByteWidth),
|
||||
onTap: connector.isConnected
|
||||
subtitle:
|
||||
connector.isConnected &&
|
||||
(connector.firmwareVerCode ?? 0) <
|
||||
_minFirmwareVerCodeForPathHashMode
|
||||
? l10n.settings_requiresFirmware('v1.14')
|
||||
: _pathHashModeSubtitle(context, connector.pathHashByteWidth),
|
||||
onTap:
|
||||
connector.isConnected &&
|
||||
(connector.firmwareVerCode ?? 0) >=
|
||||
_minFirmwareVerCodeForPathHashMode
|
||||
? () => _editPathHashMode(context, connector)
|
||||
: null,
|
||||
),
|
||||
@@ -818,12 +849,12 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
|
||||
void _editPathHashMode(BuildContext context, MeshCoreConnector connector) {
|
||||
final l10n = context.l10n;
|
||||
var selectedMode = (connector.pathHashByteWidth - 1).clamp(0, 3).toInt();
|
||||
var selectedMode = (connector.pathHashByteWidth - 1).clamp(0, 2).toInt();
|
||||
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (dialogContext) => StatefulBuilder(
|
||||
builder: (context, setDialogState) => AlertDialog(
|
||||
builder: (builderContext, setDialogState) => AlertDialog(
|
||||
title: Text(l10n.repeater_pathHashMode),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
@@ -848,10 +879,6 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
value: 2,
|
||||
child: Text(l10n.repeater_pathHashModeOption2),
|
||||
),
|
||||
DropdownMenuItem(
|
||||
value: 3,
|
||||
child: Text(l10n.repeater_pathHashModeOption3),
|
||||
),
|
||||
],
|
||||
onChanged: (value) {
|
||||
if (value == null) return;
|
||||
@@ -860,8 +887,8 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Text(
|
||||
l10n.repeater_pathHashModeHelper,
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
l10n.settings_pathHashModeHelper,
|
||||
style: Theme.of(builderContext).textTheme.bodySmall,
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -921,7 +948,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (dialogContext) => StatefulBuilder(
|
||||
builder: (context, setDialogState) => AlertDialog(
|
||||
builder: (builderContext, setDialogState) => AlertDialog(
|
||||
title: Text(l10n.settings_location),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
@@ -987,7 +1014,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
onPressed: () => Navigator.pop(dialogContext),
|
||||
child: Text(l10n.common_cancel),
|
||||
),
|
||||
TextButton(
|
||||
@@ -1008,7 +1035,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
}
|
||||
}
|
||||
|
||||
Navigator.pop(context);
|
||||
Navigator.pop(dialogContext);
|
||||
|
||||
if (interval != null) {
|
||||
await settingsService.setGpsIntervalSeconds(
|
||||
@@ -1348,21 +1375,37 @@ void _privacySettings(BuildContext context, MeshCoreConnector connector) {
|
||||
settingsService.settings.autoSendZeroHopAdvertOnGpsUpdate;
|
||||
|
||||
final telemModeBase = [
|
||||
DropdownMenuItem(value: teleModeDeny, child: Text(l10n.settings_denyAll)),
|
||||
DropdownMenuItem(
|
||||
value: teleModeDeny,
|
||||
child: Text(
|
||||
l10n.settings_denyAll,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
DropdownMenuItem(
|
||||
value: teleModeAllowFlags,
|
||||
child: Text(l10n.settings_allowByContact),
|
||||
child: Text(
|
||||
l10n.settings_allowByContact,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
DropdownMenuItem(
|
||||
value: teleModeAllowAll,
|
||||
child: Text(l10n.settings_allowAll),
|
||||
child: Text(
|
||||
l10n.settings_allowAll,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
];
|
||||
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (dialogContext) => StatefulBuilder(
|
||||
builder: (context, setDialogState) => AlertDialog(
|
||||
builder: (builderContext, setDialogState) => AlertDialog(
|
||||
insetPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 24),
|
||||
title: Text(l10n.settings_privacy),
|
||||
content: SingleChildScrollView(
|
||||
child: Column(
|
||||
@@ -1396,6 +1439,7 @@ void _privacySettings(BuildContext context, MeshCoreConnector connector) {
|
||||
const SizedBox(height: 8),
|
||||
SwitchListTile(
|
||||
title: Text(l10n.settings_multiAck),
|
||||
subtitle: Text(l10n.settings_multiAckSubtitle),
|
||||
value: multiAcks == 1,
|
||||
onChanged: (value) {
|
||||
setDialogState(() => multiAcks = value ? 1 : 0);
|
||||
@@ -1405,6 +1449,7 @@ void _privacySettings(BuildContext context, MeshCoreConnector connector) {
|
||||
const SizedBox(height: 16),
|
||||
DropdownButtonFormField<int>(
|
||||
initialValue: telemetryMode,
|
||||
isExpanded: true,
|
||||
decoration: InputDecoration(
|
||||
labelText: l10n.settings_telemetryBaseMode,
|
||||
border: const OutlineInputBorder(),
|
||||
@@ -1419,6 +1464,7 @@ void _privacySettings(BuildContext context, MeshCoreConnector connector) {
|
||||
const SizedBox(height: 16),
|
||||
DropdownButtonFormField<int>(
|
||||
initialValue: telemetryLocMode,
|
||||
isExpanded: true,
|
||||
decoration: InputDecoration(
|
||||
labelText: l10n.settings_telemetryLocationMode,
|
||||
border: const OutlineInputBorder(),
|
||||
@@ -1433,6 +1479,7 @@ void _privacySettings(BuildContext context, MeshCoreConnector connector) {
|
||||
const SizedBox(height: 16),
|
||||
DropdownButtonFormField<int>(
|
||||
initialValue: telemetryEnvMode,
|
||||
isExpanded: true,
|
||||
decoration: InputDecoration(
|
||||
labelText: l10n.settings_telemetryEnvironmentMode,
|
||||
border: const OutlineInputBorder(),
|
||||
@@ -1444,17 +1491,22 @@ void _privacySettings(BuildContext context, MeshCoreConnector connector) {
|
||||
}
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
l10n.settings_telemetryPerContactHint,
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
onPressed: () => Navigator.pop(dialogContext),
|
||||
child: Text(l10n.common_cancel),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
Navigator.pop(context);
|
||||
Navigator.pop(dialogContext);
|
||||
await connector.setTelemetryModeBase(
|
||||
telemetryMode,
|
||||
telemetryLocMode,
|
||||
@@ -1597,8 +1649,7 @@ class _RadioSettingsDialogState extends State<_RadioSettingsDialog> {
|
||||
if (preset.frequencyHz == snapshot.frequencyHz &&
|
||||
preset.bandwidth == snapshot.bandwidth &&
|
||||
preset.spreadingFactor == snapshot.spreadingFactor &&
|
||||
preset.codingRate == snapshot.codingRate &&
|
||||
preset.txPowerDbm == snapshot.txPowerDbm) {
|
||||
preset.codingRate == snapshot.codingRate) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
@@ -1632,9 +1683,15 @@ class _RadioSettingsDialogState extends State<_RadioSettingsDialog> {
|
||||
}
|
||||
|
||||
double _offGridFrequencyForBaseFrequency(double baseFrequencyMHz) {
|
||||
if (baseFrequencyMHz < 500) return 433.0;
|
||||
if (baseFrequencyMHz < 900) return 869.0;
|
||||
return 918.0;
|
||||
final baseKHz = (baseFrequencyMHz * 1000).round();
|
||||
final ranges = widget.connector.allowedRepeatFreqRanges;
|
||||
final candidates = ranges == null || ranges.isEmpty
|
||||
? _defaultRepeatFreqsKHz
|
||||
: {for (final r in ranges) baseKHz.clamp(r.lowKHz, r.highKHz)};
|
||||
final closestKHz = candidates.reduce(
|
||||
(a, b) => (a - baseKHz).abs() <= (b - baseKHz).abs() ? a : b,
|
||||
);
|
||||
return closestKHz / 1000.0;
|
||||
}
|
||||
|
||||
double _normalFrequencyForBand(double frequencyMHz) {
|
||||
@@ -1679,14 +1736,13 @@ class _RadioSettingsDialogState extends State<_RadioSettingsDialog> {
|
||||
if (offGridFreqHz == current.frequencyHz &&
|
||||
preset.bandwidth == current.bandwidth &&
|
||||
preset.spreadingFactor == current.spreadingFactor &&
|
||||
preset.codingRate == current.codingRate &&
|
||||
preset.txPowerDbm == current.txPowerDbm) {
|
||||
preset.codingRate == current.codingRate) {
|
||||
return _RadioSettingsSnapshot(
|
||||
frequencyMHz: preset.frequencyMHz,
|
||||
bandwidth: preset.bandwidth,
|
||||
spreadingFactor: preset.spreadingFactor,
|
||||
codingRate: preset.codingRate,
|
||||
txPowerDbm: preset.txPowerDbm,
|
||||
txPowerDbm: current.txPowerDbm,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1775,14 +1831,15 @@ class _RadioSettingsDialogState extends State<_RadioSettingsDialog> {
|
||||
void _validateFields() {
|
||||
final l10n = context.l10n;
|
||||
final freqMHz = double.tryParse(_frequencyController.text);
|
||||
_frequencyError = (freqMHz == null || freqMHz < 300 || freqMHz > 2500)
|
||||
_frequencyError = (freqMHz == null || freqMHz < 150 || freqMHz > 2500)
|
||||
? l10n.settings_frequencyInvalid
|
||||
: null;
|
||||
|
||||
final maxTxPower = widget.connector.maxTxPower ?? 22;
|
||||
final txPower = int.tryParse(_txPowerController.text);
|
||||
_txPowerError = (txPower == null || txPower < 0 || txPower > maxTxPower)
|
||||
? '${l10n.settings_txPowerInvalid} (0-$maxTxPower dBm)'
|
||||
_txPowerError =
|
||||
(txPower == null || txPower < _minTxPowerDbm || txPower > maxTxPower)
|
||||
? '${l10n.settings_txPowerInvalid} ($_minTxPowerDbm-$maxTxPower dBm)'
|
||||
: null;
|
||||
}
|
||||
|
||||
@@ -1819,7 +1876,7 @@ class _RadioSettingsDialogState extends State<_RadioSettingsDialog> {
|
||||
final freqMHz = double.tryParse(_frequencyController.text);
|
||||
final txPower = int.tryParse(_txPowerController.text);
|
||||
|
||||
if (freqMHz == null || freqMHz < 300 || freqMHz > 2500) {
|
||||
if (freqMHz == null || freqMHz < 150 || freqMHz > 2500) {
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(l10n.settings_frequencyInvalid),
|
||||
@@ -1828,10 +1885,12 @@ class _RadioSettingsDialogState extends State<_RadioSettingsDialog> {
|
||||
}
|
||||
|
||||
final maxTxPower = widget.connector.maxTxPower ?? 22;
|
||||
if (txPower == null || txPower < 0 || txPower > maxTxPower) {
|
||||
if (txPower == null || txPower < _minTxPowerDbm || txPower > maxTxPower) {
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text('${l10n.settings_txPowerInvalid} (0-$maxTxPower dBm)'),
|
||||
content: Text(
|
||||
'${l10n.settings_txPowerInvalid} ($_minTxPowerDbm-$maxTxPower dBm)',
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
@@ -1839,18 +1898,14 @@ class _RadioSettingsDialogState extends State<_RadioSettingsDialog> {
|
||||
final freqHz = (freqMHz * 1000).round();
|
||||
final bwHz = _bandwidth.hz;
|
||||
final sf = _spreadingFactor.value;
|
||||
final cr = _toDeviceCodingRate(
|
||||
_codingRate.value,
|
||||
widget.connector.currentCr,
|
||||
);
|
||||
final cr = _codingRate.value;
|
||||
|
||||
// if the client repeat isnt null then we know its supported
|
||||
//otherwise we leave it out of the frame to avoid accidentally enabling
|
||||
final knownRepeat = widget.connector.clientRepeat != null;
|
||||
|
||||
if (knownRepeat) {
|
||||
const validRepeatFreqsKHz = {433000, 869000, 918000};
|
||||
if (_clientRepeat && !validRepeatFreqsKHz.contains(freqHz)) {
|
||||
if (_clientRepeat && !_isAllowedRepeatFreqKHz(widget.connector, freqHz)) {
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(l10n.settings_clientRepeatFreqWarning),
|
||||
@@ -1861,23 +1916,53 @@ class _RadioSettingsDialogState extends State<_RadioSettingsDialog> {
|
||||
|
||||
try {
|
||||
_logRadioSettingsState('Saving radio settings');
|
||||
await widget.connector.sendFrame(
|
||||
buildSetRadioParamsFrame(
|
||||
freqHz,
|
||||
bwHz,
|
||||
sf,
|
||||
cr,
|
||||
final accepted = await widget.connector.setRadioParams(
|
||||
freqHz,
|
||||
bwHz,
|
||||
sf,
|
||||
cr,
|
||||
clientRepeat: knownRepeat ? _clientRepeat : null,
|
||||
);
|
||||
if (!accepted) {
|
||||
_logRadioSettingsState('Radio rejected requested settings');
|
||||
if (!mounted) return;
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(l10n.settings_radioSettingsNotApplied),
|
||||
);
|
||||
return;
|
||||
}
|
||||
await widget.connector.sendFrame(buildSetRadioTxPowerFrame(txPower));
|
||||
final selfInfo = widget.connector.receivedFrames
|
||||
.firstWhere((f) => f.isNotEmpty && f[0] == respCodeSelfInfo)
|
||||
.timeout(const Duration(seconds: 5));
|
||||
await widget.connector.refreshDeviceInfo();
|
||||
final applied = await selfInfo.then(
|
||||
(_) => _deviceMatches(
|
||||
freqHz: freqHz,
|
||||
bwHz: bwHz,
|
||||
sf: sf,
|
||||
cr: cr,
|
||||
txPower: txPower,
|
||||
clientRepeat: knownRepeat ? _clientRepeat : null,
|
||||
),
|
||||
onError: (_) => true,
|
||||
);
|
||||
await widget.connector.sendFrame(buildSetRadioTxPowerFrame(txPower));
|
||||
await widget.connector.refreshDeviceInfo();
|
||||
if (!applied) {
|
||||
_logRadioSettingsState('Radio did not apply requested settings');
|
||||
if (!mounted) return;
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(l10n.settings_radioSettingsNotApplied),
|
||||
);
|
||||
return;
|
||||
}
|
||||
final rememberedSnapshot = _clientRepeat
|
||||
? _lastNonRepeatSnapshot
|
||||
: _currentSnapshot();
|
||||
if (rememberedSnapshot != null) {
|
||||
widget.connector.rememberNonRepeatRadioState(
|
||||
rememberedSnapshot.toMeshCoreSnapshot(widget.connector.currentCr),
|
||||
rememberedSnapshot.toMeshCoreSnapshot(),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1899,6 +1984,27 @@ class _RadioSettingsDialogState extends State<_RadioSettingsDialog> {
|
||||
Navigator.pop(context);
|
||||
}
|
||||
|
||||
bool _deviceMatches({
|
||||
required int freqHz,
|
||||
required int bwHz,
|
||||
required int sf,
|
||||
required int cr,
|
||||
required int txPower,
|
||||
required bool? clientRepeat,
|
||||
}) {
|
||||
final c = widget.connector;
|
||||
// Firmware stores freq/bw as float MHz/kHz, so allow 1 unit of rounding.
|
||||
return c.currentFreqHz != null &&
|
||||
(c.currentFreqHz! - freqHz).abs() <= 1 &&
|
||||
c.currentBwHz != null &&
|
||||
(c.currentBwHz! - bwHz).abs() <= 1 &&
|
||||
c.currentSf == sf &&
|
||||
c.currentCr != null &&
|
||||
_toUiCodingRate(c.currentCr!) == cr &&
|
||||
c.currentTxPower == txPower &&
|
||||
(clientRepeat == null || c.clientRepeat == clientRepeat);
|
||||
}
|
||||
|
||||
String _presetLabel(int? index) {
|
||||
if (index == null) {
|
||||
return 'custom';
|
||||
@@ -1945,20 +2051,30 @@ class _RadioSettingsDialogState extends State<_RadioSettingsDialog> {
|
||||
children: [
|
||||
DropdownButtonFormField<int>(
|
||||
key: ValueKey<int?>(_selectedPresetIndex),
|
||||
initialValue: _selectedPresetIndex,
|
||||
initialValue: _selectedPresetIndex ?? -1,
|
||||
isExpanded: true,
|
||||
decoration: InputDecoration(
|
||||
labelText: l10n.settings_presets,
|
||||
border: const OutlineInputBorder(),
|
||||
),
|
||||
items: [
|
||||
if (_selectedPresetIndex == null)
|
||||
DropdownMenuItem(
|
||||
value: -1,
|
||||
child: Text(l10n.settings_presetCustom),
|
||||
),
|
||||
for (final i in _visiblePresetIndexes())
|
||||
DropdownMenuItem(
|
||||
value: i,
|
||||
child: Text(RadioSettings.presets[i].$1),
|
||||
child: Text(
|
||||
RadioSettings.presets[i].$1,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
],
|
||||
onChanged: (index) {
|
||||
if (index != null) {
|
||||
if (index != null && index >= 0) {
|
||||
_applyPreset(index);
|
||||
}
|
||||
},
|
||||
@@ -1970,7 +2086,11 @@ class _RadioSettingsDialogState extends State<_RadioSettingsDialog> {
|
||||
decoration: InputDecoration(
|
||||
labelText: l10n.settings_frequency,
|
||||
border: const OutlineInputBorder(),
|
||||
helperText: l10n.settings_frequencyHelper,
|
||||
helperText: _clientRepeat
|
||||
? l10n.settings_clientRepeatFrequencyNote(
|
||||
_frequencyController.text,
|
||||
)
|
||||
: l10n.settings_frequencyHelper,
|
||||
errorText: _frequencyError,
|
||||
),
|
||||
keyboardType: const TextInputType.numberWithOptions(
|
||||
@@ -2052,9 +2172,10 @@ class _RadioSettingsDialogState extends State<_RadioSettingsDialog> {
|
||||
decoration: InputDecoration(
|
||||
labelText: l10n.settings_txPower,
|
||||
border: const OutlineInputBorder(),
|
||||
helperText: widget.connector.maxTxPower != null
|
||||
? '${l10n.settings_txPowerHelper} (max: ${widget.connector.maxTxPower} dBm)'
|
||||
: l10n.settings_txPowerHelper,
|
||||
helperText: l10n.settings_txPowerRangeHelper(
|
||||
_minTxPowerDbm,
|
||||
widget.connector.maxTxPower ?? 22,
|
||||
),
|
||||
errorText: _txPowerError,
|
||||
),
|
||||
keyboardType: TextInputType.number,
|
||||
@@ -2069,6 +2190,11 @@ class _RadioSettingsDialogState extends State<_RadioSettingsDialog> {
|
||||
contentPadding: EdgeInsets.zero,
|
||||
),
|
||||
],
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
l10n.settings_radioMatchWarning,
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -2130,12 +2256,12 @@ class _RadioSettingsSnapshot {
|
||||
}
|
||||
|
||||
/// Convert back to the connector's raw-int snapshot.
|
||||
MeshCoreRadioStateSnapshot toMeshCoreSnapshot(int? deviceCr) {
|
||||
MeshCoreRadioStateSnapshot toMeshCoreSnapshot() {
|
||||
return MeshCoreRadioStateSnapshot(
|
||||
freqHz: frequencyHz,
|
||||
bwHz: bandwidth.hz,
|
||||
sf: spreadingFactor.value,
|
||||
cr: _toDeviceCodingRate(codingRate.value, deviceCr),
|
||||
cr: codingRate.value,
|
||||
txPowerDbm: txPowerDbm,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -22,10 +22,36 @@ import '../widgets/telemetry_location_map.dart';
|
||||
import '../theme/mesh_theme.dart';
|
||||
import '../widgets/mesh_ui.dart';
|
||||
|
||||
/// Opens the telemetry screen for the locally connected node.
|
||||
void pushSelfTelemetryScreen(BuildContext context) {
|
||||
final connector = Provider.of<MeshCoreConnector>(context, listen: false);
|
||||
final selfKey = connector.selfPublicKey;
|
||||
if (selfKey == null || selfKey.isEmpty) return;
|
||||
final selfContact = Contact(
|
||||
publicKey: selfKey,
|
||||
name: connector.selfName ?? '',
|
||||
type: advTypeChat,
|
||||
pathLength: 0,
|
||||
path: Uint8List(0),
|
||||
lastSeen: DateTime.now(),
|
||||
);
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute<void>(
|
||||
builder: (context) => TelemetryScreen(contact: selfContact, isSelf: true),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
class TelemetryScreen extends StatefulWidget {
|
||||
final Contact contact;
|
||||
final bool isSelf;
|
||||
|
||||
const TelemetryScreen({super.key, required this.contact});
|
||||
const TelemetryScreen({
|
||||
super.key,
|
||||
required this.contact,
|
||||
this.isSelf = false,
|
||||
});
|
||||
|
||||
@override
|
||||
State<TelemetryScreen> createState() => _TelemetryScreenState();
|
||||
@@ -40,6 +66,7 @@ class _TelemetryScreenState extends State<TelemetryScreen> {
|
||||
static const int _autoRefreshMaxQuantity = 10;
|
||||
|
||||
int _tagData = 0;
|
||||
bool _awaitingSent = false;
|
||||
|
||||
bool _isLoading = false;
|
||||
bool _isLoaded = false;
|
||||
@@ -101,7 +128,8 @@ class _TelemetryScreenState extends State<TelemetryScreen> {
|
||||
final reader = BufferReader(frame);
|
||||
try {
|
||||
final cmd = reader.readByte();
|
||||
if (cmd == respCodeSent) {
|
||||
if (cmd == respCodeSent && _awaitingSent) {
|
||||
_awaitingSent = false;
|
||||
reader.skipBytes(1); // Skip the reserved byte
|
||||
_tagData = reader.readUInt32LE();
|
||||
_tripTime = reader.readUInt32LE();
|
||||
@@ -158,7 +186,7 @@ class _TelemetryScreenState extends State<TelemetryScreen> {
|
||||
void _handleTelemetryResponse(Uint8List frame) {
|
||||
final parsedTelemetry = CayenneLpp.parseByChannel(frame);
|
||||
final batteryMv = _extractTelemetryBatteryMillivolts(parsedTelemetry);
|
||||
if (batteryMv != null) {
|
||||
if (batteryMv != null && !widget.isSelf) {
|
||||
final connector = Provider.of<MeshCoreConnector>(context, listen: false);
|
||||
connector.updateRepeaterBatterySnapshot(
|
||||
widget.contact.publicKeyHex,
|
||||
@@ -183,6 +211,7 @@ class _TelemetryScreenState extends State<TelemetryScreen> {
|
||||
);
|
||||
}
|
||||
_statusTimeout?.cancel();
|
||||
_recordTelemetryResult(true);
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
@@ -204,21 +233,55 @@ class _TelemetryScreenState extends State<TelemetryScreen> {
|
||||
});
|
||||
try {
|
||||
final connector = Provider.of<MeshCoreConnector>(context, listen: false);
|
||||
final selection = await connector.preparePathForContactSend(
|
||||
_resolveContact(connector),
|
||||
);
|
||||
_pendingStatusSelection = selection;
|
||||
Uint8List frame;
|
||||
if (widget.contact.type != advTypeChat) {
|
||||
frame = buildSendBinaryReq(
|
||||
widget.contact.publicKey,
|
||||
payload: buildTelemetryBinaryPayload(),
|
||||
);
|
||||
if (widget.isSelf) {
|
||||
// ask the connected node for its own telemetry, no mesh path involved
|
||||
frame = buildSendTelemetryReq(null);
|
||||
final isAutoRefreshRequest = _activeTelemetryRequestIsAutoRefresh;
|
||||
_statusTimeout?.cancel();
|
||||
_statusTimeout = Timer(const Duration(seconds: 5), () {
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
_isLoaded = false;
|
||||
if (isAutoRefreshRequest && _isAutoRefreshEnabled) {
|
||||
_autoRefreshLastAttemptFailed = true;
|
||||
}
|
||||
_activeTelemetryRequestIsAutoRefresh = false;
|
||||
});
|
||||
if (!isAutoRefreshRequest) {
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(context.l10n.telemetry_requestTimeout),
|
||||
backgroundColor: Theme.of(context).colorScheme.error,
|
||||
);
|
||||
}
|
||||
if (isAutoRefreshRequest && _isAutoRefreshEnabled) {
|
||||
_scheduleNextAutoRefreshAttempt();
|
||||
}
|
||||
_recordTelemetryResult(false);
|
||||
});
|
||||
} else {
|
||||
frame = buildSendTelemetryReq(widget.contact.publicKey);
|
||||
final selection = await connector.preparePathForContactSend(
|
||||
_resolveContact(connector),
|
||||
);
|
||||
_pendingStatusSelection = selection;
|
||||
if (widget.contact.type != advTypeChat) {
|
||||
frame = buildSendBinaryReq(
|
||||
widget.contact.publicKey,
|
||||
payload: buildTelemetryBinaryPayload(),
|
||||
);
|
||||
} else {
|
||||
frame = buildSendTelemetryReq(widget.contact.publicKey);
|
||||
}
|
||||
}
|
||||
// A local self request gets no respCodeSent, so any that arrives belongs
|
||||
// to another send and must not replace the 5s self timeout.
|
||||
_awaitingSent = !widget.isSelf;
|
||||
await connector.sendFrame(frame);
|
||||
} catch (e) {
|
||||
_awaitingSent = false;
|
||||
_statusTimeout?.cancel();
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
@@ -353,12 +416,13 @@ class _TelemetryScreenState extends State<TelemetryScreen> {
|
||||
centerTitle: true,
|
||||
bottom: const SyncProgressAppBarBottom(),
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: Icon(isFloodMode ? Icons.waves : Icons.route),
|
||||
tooltip: l10n.repeater_routingMode,
|
||||
onPressed: () =>
|
||||
ContactRoutingSheet.show(context, contact: widget.contact),
|
||||
),
|
||||
if (!widget.isSelf)
|
||||
IconButton(
|
||||
icon: Icon(isFloodMode ? Icons.waves : Icons.route),
|
||||
tooltip: l10n.repeater_routingMode,
|
||||
onPressed: () =>
|
||||
ContactRoutingSheet.show(context, contact: widget.contact),
|
||||
),
|
||||
IconButton(
|
||||
icon: _isLoading
|
||||
? const SizedBox(
|
||||
@@ -495,7 +559,7 @@ class _TelemetryScreenState extends State<TelemetryScreen> {
|
||||
_temperatureText(value, isImperialUnits),
|
||||
);
|
||||
case 'humidity':
|
||||
return _TelemetryFieldDisplay(l10n.telemetry_humidityLabel, text);
|
||||
return _TelemetryFieldDisplay(l10n.telemetry_humidityLabel, '$text%');
|
||||
case 'accelerometer':
|
||||
return _TelemetryFieldDisplay(
|
||||
l10n.telemetry_accelerometerLabel,
|
||||
@@ -912,10 +976,12 @@ class _TelemetryScreenState extends State<TelemetryScreen> {
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
value,
|
||||
style: MeshTheme.mono(fontSize: 13, color: scheme.onSurface),
|
||||
textAlign: TextAlign.end,
|
||||
Flexible(
|
||||
child: Text(
|
||||
value,
|
||||
style: MeshTheme.mono(fontSize: 13, color: scheme.onSurface),
|
||||
textAlign: TextAlign.end,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
Reference in new issue
Block a user