diff --git a/lib/connector/meshcore_protocol.dart b/lib/connector/meshcore_protocol.dart index f1d8100e..14d181a1 100644 --- a/lib/connector/meshcore_protocol.dart +++ b/lib/connector/meshcore_protocol.dart @@ -739,6 +739,23 @@ int maxChannelMessageBytes(String? senderName, {int? maxFrameBytes}) { return _minPositive(byPayload, byFrame); } +/// Fewest bytes a composer needs before it is worth calling usable. +/// +/// Judgement call, not a protocol constant: below this a user cannot say +/// anything meaningful, so an apparently-normal text field is misleading and +/// the guard in #684 explains itself instead. Deliberately larger than the +/// degenerate values #592 produced (DM 4, channel 1 or 0) so the guard also +/// catches the near-miss cases, not only the literal zero. +const int minUsableComposerBytes = 16; + +/// Whether [maxBytes] leaves a composer able to carry a real message. +/// +/// A budget of 0 rejects every keystroke, which is the #592 symptom that read +/// as a dead keyboard. A budget of 1-15 accepts input but cannot carry a +/// sentence. Both are cases the user must be told about rather than left to +/// discover by typing into a field that ignores them (SAFELANE 6). +bool isComposerBudgetUsable(int maxBytes) => maxBytes >= minUsableComposerBytes; + int _senderNameBytes(String? senderName) { if (senderName == null || senderName.isEmpty) return maxNameSize - 1; final bytes = utf8.encode(senderName); diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index 24495d29..7b8d4516 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -764,6 +764,17 @@ } } }, + "composerBudgetBlockedTitle": "Can't send messages on this connection", + "composerBudgetLimitedTitle": "Only {maxBytes} characters will fit", + "@composerBudgetLimitedTitle": { + "placeholders": { + "maxBytes": { + "type": "int" + } + } + }, + "composerBudgetBluetoothCause": "The Bluetooth link negotiated a very small packet size, which leaves no room for message text. Try reconnecting, or connect by USB or Wi-Fi instead.", + "composerBudgetGenericCause": "The connection to the radio left no room for message text. Try reconnecting.", "chat_messageCopied": "Message copied", "chat_messageDeleted": "Message deleted", "chat_retryingMessage": "Retrying message", diff --git a/lib/l10n/app_localizations.dart b/lib/l10n/app_localizations.dart index a0c90594..1a3084b3 100644 --- a/lib/l10n/app_localizations.dart +++ b/lib/l10n/app_localizations.dart @@ -2776,6 +2776,30 @@ abstract class AppLocalizations { /// **'Message too long (max {maxBytes} bytes).'** String chat_messageTooLong(int maxBytes); + /// No description provided for @composerBudgetBlockedTitle. + /// + /// In en, this message translates to: + /// **'Can\'t send messages on this connection'** + String get composerBudgetBlockedTitle; + + /// No description provided for @composerBudgetLimitedTitle. + /// + /// In en, this message translates to: + /// **'Only {maxBytes} characters will fit'** + String composerBudgetLimitedTitle(int maxBytes); + + /// No description provided for @composerBudgetBluetoothCause. + /// + /// In en, this message translates to: + /// **'The Bluetooth link negotiated a very small packet size, which leaves no room for message text. Try reconnecting, or connect by USB or Wi-Fi instead.'** + String get composerBudgetBluetoothCause; + + /// No description provided for @composerBudgetGenericCause. + /// + /// In en, this message translates to: + /// **'The connection to the radio left no room for message text. Try reconnecting.'** + String get composerBudgetGenericCause; + /// No description provided for @chat_messageCopied. /// /// In en, this message translates to: diff --git a/lib/l10n/app_localizations_bg.dart b/lib/l10n/app_localizations_bg.dart index dc0a1c06..7f1d2892 100644 --- a/lib/l10n/app_localizations_bg.dart +++ b/lib/l10n/app_localizations_bg.dart @@ -1518,6 +1518,23 @@ class AppLocalizationsBg extends AppLocalizations { return 'Съобщението е твърде дълго (макс $maxBytes байта).'; } + @override + String get composerBudgetBlockedTitle => + 'Can\'t send messages on this connection'; + + @override + String composerBudgetLimitedTitle(int maxBytes) { + return 'Only $maxBytes characters will fit'; + } + + @override + String get composerBudgetBluetoothCause => + 'The Bluetooth link negotiated a very small packet size, which leaves no room for message text. Try reconnecting, or connect by USB or Wi-Fi instead.'; + + @override + String get composerBudgetGenericCause => + 'The connection to the radio left no room for message text. Try reconnecting.'; + @override String get chat_messageCopied => 'Съобщението е копирано'; diff --git a/lib/l10n/app_localizations_de.dart b/lib/l10n/app_localizations_de.dart index 0726908d..d6e33ed5 100644 --- a/lib/l10n/app_localizations_de.dart +++ b/lib/l10n/app_localizations_de.dart @@ -1516,6 +1516,23 @@ class AppLocalizationsDe extends AppLocalizations { return 'Nachricht ist zu lang (max $maxBytes Bytes).'; } + @override + String get composerBudgetBlockedTitle => + 'Can\'t send messages on this connection'; + + @override + String composerBudgetLimitedTitle(int maxBytes) { + return 'Only $maxBytes characters will fit'; + } + + @override + String get composerBudgetBluetoothCause => + 'The Bluetooth link negotiated a very small packet size, which leaves no room for message text. Try reconnecting, or connect by USB or Wi-Fi instead.'; + + @override + String get composerBudgetGenericCause => + 'The connection to the radio left no room for message text. Try reconnecting.'; + @override String get chat_messageCopied => 'Nachricht kopiert'; diff --git a/lib/l10n/app_localizations_en.dart b/lib/l10n/app_localizations_en.dart index 29b507bd..a9fb23b9 100644 --- a/lib/l10n/app_localizations_en.dart +++ b/lib/l10n/app_localizations_en.dart @@ -1489,6 +1489,23 @@ class AppLocalizationsEn extends AppLocalizations { return 'Message too long (max $maxBytes bytes).'; } + @override + String get composerBudgetBlockedTitle => + 'Can\'t send messages on this connection'; + + @override + String composerBudgetLimitedTitle(int maxBytes) { + return 'Only $maxBytes characters will fit'; + } + + @override + String get composerBudgetBluetoothCause => + 'The Bluetooth link negotiated a very small packet size, which leaves no room for message text. Try reconnecting, or connect by USB or Wi-Fi instead.'; + + @override + String get composerBudgetGenericCause => + 'The connection to the radio left no room for message text. Try reconnecting.'; + @override String get chat_messageCopied => 'Message copied'; diff --git a/lib/l10n/app_localizations_es.dart b/lib/l10n/app_localizations_es.dart index bbd42ccd..1b11ca95 100644 --- a/lib/l10n/app_localizations_es.dart +++ b/lib/l10n/app_localizations_es.dart @@ -1515,6 +1515,23 @@ class AppLocalizationsEs extends AppLocalizations { return 'Mensaje demasiado largo (máximo $maxBytes bytes).'; } + @override + String get composerBudgetBlockedTitle => + 'Can\'t send messages on this connection'; + + @override + String composerBudgetLimitedTitle(int maxBytes) { + return 'Only $maxBytes characters will fit'; + } + + @override + String get composerBudgetBluetoothCause => + 'The Bluetooth link negotiated a very small packet size, which leaves no room for message text. Try reconnecting, or connect by USB or Wi-Fi instead.'; + + @override + String get composerBudgetGenericCause => + 'The connection to the radio left no room for message text. Try reconnecting.'; + @override String get chat_messageCopied => 'Mensaje copiado'; diff --git a/lib/l10n/app_localizations_fr.dart b/lib/l10n/app_localizations_fr.dart index a7e24f4c..709974b8 100644 --- a/lib/l10n/app_localizations_fr.dart +++ b/lib/l10n/app_localizations_fr.dart @@ -1520,6 +1520,23 @@ class AppLocalizationsFr extends AppLocalizations { return 'Message trop long (max $maxBytes octets).'; } + @override + String get composerBudgetBlockedTitle => + 'Can\'t send messages on this connection'; + + @override + String composerBudgetLimitedTitle(int maxBytes) { + return 'Only $maxBytes characters will fit'; + } + + @override + String get composerBudgetBluetoothCause => + 'The Bluetooth link negotiated a very small packet size, which leaves no room for message text. Try reconnecting, or connect by USB or Wi-Fi instead.'; + + @override + String get composerBudgetGenericCause => + 'The connection to the radio left no room for message text. Try reconnecting.'; + @override String get chat_messageCopied => 'Message copié'; diff --git a/lib/l10n/app_localizations_hu.dart b/lib/l10n/app_localizations_hu.dart index 800ab400..10446599 100644 --- a/lib/l10n/app_localizations_hu.dart +++ b/lib/l10n/app_localizations_hu.dart @@ -1523,6 +1523,23 @@ class AppLocalizationsHu extends AppLocalizations { return 'A üzenet túl hosszú (a maximális $maxBytes bájt).'; } + @override + String get composerBudgetBlockedTitle => + 'Can\'t send messages on this connection'; + + @override + String composerBudgetLimitedTitle(int maxBytes) { + return 'Only $maxBytes characters will fit'; + } + + @override + String get composerBudgetBluetoothCause => + 'The Bluetooth link negotiated a very small packet size, which leaves no room for message text. Try reconnecting, or connect by USB or Wi-Fi instead.'; + + @override + String get composerBudgetGenericCause => + 'The connection to the radio left no room for message text. Try reconnecting.'; + @override String get chat_messageCopied => 'Üzenet másolva'; diff --git a/lib/l10n/app_localizations_it.dart b/lib/l10n/app_localizations_it.dart index ded7e8ad..93a93df0 100644 --- a/lib/l10n/app_localizations_it.dart +++ b/lib/l10n/app_localizations_it.dart @@ -1517,6 +1517,23 @@ class AppLocalizationsIt extends AppLocalizations { return 'Messaggio troppo lungo (massimo $maxBytes byte).'; } + @override + String get composerBudgetBlockedTitle => + 'Can\'t send messages on this connection'; + + @override + String composerBudgetLimitedTitle(int maxBytes) { + return 'Only $maxBytes characters will fit'; + } + + @override + String get composerBudgetBluetoothCause => + 'The Bluetooth link negotiated a very small packet size, which leaves no room for message text. Try reconnecting, or connect by USB or Wi-Fi instead.'; + + @override + String get composerBudgetGenericCause => + 'The connection to the radio left no room for message text. Try reconnecting.'; + @override String get chat_messageCopied => 'Messaggio copiato'; diff --git a/lib/l10n/app_localizations_ja.dart b/lib/l10n/app_localizations_ja.dart index c99d396b..d776a58c 100644 --- a/lib/l10n/app_localizations_ja.dart +++ b/lib/l10n/app_localizations_ja.dart @@ -1454,6 +1454,23 @@ class AppLocalizationsJa extends AppLocalizations { return 'メッセージが長すぎる($maxBytes バイトを超える)。'; } + @override + String get composerBudgetBlockedTitle => + 'Can\'t send messages on this connection'; + + @override + String composerBudgetLimitedTitle(int maxBytes) { + return 'Only $maxBytes characters will fit'; + } + + @override + String get composerBudgetBluetoothCause => + 'The Bluetooth link negotiated a very small packet size, which leaves no room for message text. Try reconnecting, or connect by USB or Wi-Fi instead.'; + + @override + String get composerBudgetGenericCause => + 'The connection to the radio left no room for message text. Try reconnecting.'; + @override String get chat_messageCopied => 'メッセージがコピーされました'; diff --git a/lib/l10n/app_localizations_ko.dart b/lib/l10n/app_localizations_ko.dart index e553a758..d10ff019 100644 --- a/lib/l10n/app_localizations_ko.dart +++ b/lib/l10n/app_localizations_ko.dart @@ -1449,6 +1449,23 @@ class AppLocalizationsKo extends AppLocalizations { return '메시지가 너무 길어서 (최대 $maxBytes 바이트).'; } + @override + String get composerBudgetBlockedTitle => + 'Can\'t send messages on this connection'; + + @override + String composerBudgetLimitedTitle(int maxBytes) { + return 'Only $maxBytes characters will fit'; + } + + @override + String get composerBudgetBluetoothCause => + 'The Bluetooth link negotiated a very small packet size, which leaves no room for message text. Try reconnecting, or connect by USB or Wi-Fi instead.'; + + @override + String get composerBudgetGenericCause => + 'The connection to the radio left no room for message text. Try reconnecting.'; + @override String get chat_messageCopied => '메시지가 복사되었습니다'; diff --git a/lib/l10n/app_localizations_nl.dart b/lib/l10n/app_localizations_nl.dart index 4c5ce455..f2882e9e 100644 --- a/lib/l10n/app_localizations_nl.dart +++ b/lib/l10n/app_localizations_nl.dart @@ -1505,6 +1505,23 @@ class AppLocalizationsNl extends AppLocalizations { return 'Bericht is te lang (max $maxBytes bytes).'; } + @override + String get composerBudgetBlockedTitle => + 'Can\'t send messages on this connection'; + + @override + String composerBudgetLimitedTitle(int maxBytes) { + return 'Only $maxBytes characters will fit'; + } + + @override + String get composerBudgetBluetoothCause => + 'The Bluetooth link negotiated a very small packet size, which leaves no room for message text. Try reconnecting, or connect by USB or Wi-Fi instead.'; + + @override + String get composerBudgetGenericCause => + 'The connection to the radio left no room for message text. Try reconnecting.'; + @override String get chat_messageCopied => 'Bericht gekopieerd'; diff --git a/lib/l10n/app_localizations_pl.dart b/lib/l10n/app_localizations_pl.dart index e4b7d679..40a0ea4d 100644 --- a/lib/l10n/app_localizations_pl.dart +++ b/lib/l10n/app_localizations_pl.dart @@ -1527,6 +1527,23 @@ class AppLocalizationsPl extends AppLocalizations { return 'Wiadomość jest za długa (maksymalnie $maxBytes bajtów).'; } + @override + String get composerBudgetBlockedTitle => + 'Can\'t send messages on this connection'; + + @override + String composerBudgetLimitedTitle(int maxBytes) { + return 'Only $maxBytes characters will fit'; + } + + @override + String get composerBudgetBluetoothCause => + 'The Bluetooth link negotiated a very small packet size, which leaves no room for message text. Try reconnecting, or connect by USB or Wi-Fi instead.'; + + @override + String get composerBudgetGenericCause => + 'The connection to the radio left no room for message text. Try reconnecting.'; + @override String get chat_messageCopied => 'Wiadomość skopiowana'; diff --git a/lib/l10n/app_localizations_pt.dart b/lib/l10n/app_localizations_pt.dart index 2dbc209e..a37f99fe 100644 --- a/lib/l10n/app_localizations_pt.dart +++ b/lib/l10n/app_localizations_pt.dart @@ -1514,6 +1514,23 @@ class AppLocalizationsPt extends AppLocalizations { return 'Mensagem muito longa (máximo $maxBytes bytes).'; } + @override + String get composerBudgetBlockedTitle => + 'Can\'t send messages on this connection'; + + @override + String composerBudgetLimitedTitle(int maxBytes) { + return 'Only $maxBytes characters will fit'; + } + + @override + String get composerBudgetBluetoothCause => + 'The Bluetooth link negotiated a very small packet size, which leaves no room for message text. Try reconnecting, or connect by USB or Wi-Fi instead.'; + + @override + String get composerBudgetGenericCause => + 'The connection to the radio left no room for message text. Try reconnecting.'; + @override String get chat_messageCopied => 'Mensagem copiada'; diff --git a/lib/l10n/app_localizations_ru.dart b/lib/l10n/app_localizations_ru.dart index 4da6d973..a0be6a21 100644 --- a/lib/l10n/app_localizations_ru.dart +++ b/lib/l10n/app_localizations_ru.dart @@ -1515,6 +1515,23 @@ class AppLocalizationsRu extends AppLocalizations { return 'Сообщение слишком длинное (макс. $maxBytes байт).'; } + @override + String get composerBudgetBlockedTitle => + 'Can\'t send messages on this connection'; + + @override + String composerBudgetLimitedTitle(int maxBytes) { + return 'Only $maxBytes characters will fit'; + } + + @override + String get composerBudgetBluetoothCause => + 'The Bluetooth link negotiated a very small packet size, which leaves no room for message text. Try reconnecting, or connect by USB or Wi-Fi instead.'; + + @override + String get composerBudgetGenericCause => + 'The connection to the radio left no room for message text. Try reconnecting.'; + @override String get chat_messageCopied => 'Сообщение скопировано'; diff --git a/lib/l10n/app_localizations_sk.dart b/lib/l10n/app_localizations_sk.dart index 8c287cdc..ae0aca00 100644 --- a/lib/l10n/app_localizations_sk.dart +++ b/lib/l10n/app_localizations_sk.dart @@ -1505,6 +1505,23 @@ class AppLocalizationsSk extends AppLocalizations { return 'Správa je príliš dlhá (max $maxBytes bytov).'; } + @override + String get composerBudgetBlockedTitle => + 'Can\'t send messages on this connection'; + + @override + String composerBudgetLimitedTitle(int maxBytes) { + return 'Only $maxBytes characters will fit'; + } + + @override + String get composerBudgetBluetoothCause => + 'The Bluetooth link negotiated a very small packet size, which leaves no room for message text. Try reconnecting, or connect by USB or Wi-Fi instead.'; + + @override + String get composerBudgetGenericCause => + 'The connection to the radio left no room for message text. Try reconnecting.'; + @override String get chat_messageCopied => 'Správa skopírovaná'; diff --git a/lib/l10n/app_localizations_sl.dart b/lib/l10n/app_localizations_sl.dart index ac29adf7..b3a14158 100644 --- a/lib/l10n/app_localizations_sl.dart +++ b/lib/l10n/app_localizations_sl.dart @@ -1503,6 +1503,23 @@ class AppLocalizationsSl extends AppLocalizations { return 'Pošiljanje sporočila je onemogočeno, saj je preveliko (maksimalno $maxBytes byte-ov).'; } + @override + String get composerBudgetBlockedTitle => + 'Can\'t send messages on this connection'; + + @override + String composerBudgetLimitedTitle(int maxBytes) { + return 'Only $maxBytes characters will fit'; + } + + @override + String get composerBudgetBluetoothCause => + 'The Bluetooth link negotiated a very small packet size, which leaves no room for message text. Try reconnecting, or connect by USB or Wi-Fi instead.'; + + @override + String get composerBudgetGenericCause => + 'The connection to the radio left no room for message text. Try reconnecting.'; + @override String get chat_messageCopied => 'Sporočilo poslano'; diff --git a/lib/l10n/app_localizations_sv.dart b/lib/l10n/app_localizations_sv.dart index 08d73d0f..54581ed9 100644 --- a/lib/l10n/app_localizations_sv.dart +++ b/lib/l10n/app_localizations_sv.dart @@ -1497,6 +1497,23 @@ class AppLocalizationsSv extends AppLocalizations { return 'Meddelandet är för långt (max $maxBytes byte).'; } + @override + String get composerBudgetBlockedTitle => + 'Can\'t send messages on this connection'; + + @override + String composerBudgetLimitedTitle(int maxBytes) { + return 'Only $maxBytes characters will fit'; + } + + @override + String get composerBudgetBluetoothCause => + 'The Bluetooth link negotiated a very small packet size, which leaves no room for message text. Try reconnecting, or connect by USB or Wi-Fi instead.'; + + @override + String get composerBudgetGenericCause => + 'The connection to the radio left no room for message text. Try reconnecting.'; + @override String get chat_messageCopied => 'Meddelandet kopierades'; diff --git a/lib/l10n/app_localizations_uk.dart b/lib/l10n/app_localizations_uk.dart index 89f4b2ba..a58d4b85 100644 --- a/lib/l10n/app_localizations_uk.dart +++ b/lib/l10n/app_localizations_uk.dart @@ -1509,6 +1509,23 @@ class AppLocalizationsUk extends AppLocalizations { return 'Повідомлення занадто довге (макс. $maxBytes байт).'; } + @override + String get composerBudgetBlockedTitle => + 'Can\'t send messages on this connection'; + + @override + String composerBudgetLimitedTitle(int maxBytes) { + return 'Only $maxBytes characters will fit'; + } + + @override + String get composerBudgetBluetoothCause => + 'The Bluetooth link negotiated a very small packet size, which leaves no room for message text. Try reconnecting, or connect by USB or Wi-Fi instead.'; + + @override + String get composerBudgetGenericCause => + 'The connection to the radio left no room for message text. Try reconnecting.'; + @override String get chat_messageCopied => 'Повідомлення скопійовано'; diff --git a/lib/l10n/app_localizations_zh.dart b/lib/l10n/app_localizations_zh.dart index 0e349d89..60e535e9 100644 --- a/lib/l10n/app_localizations_zh.dart +++ b/lib/l10n/app_localizations_zh.dart @@ -1435,6 +1435,23 @@ class AppLocalizationsZh extends AppLocalizations { return '消息过长(最多 $maxBytes 字节)'; } + @override + String get composerBudgetBlockedTitle => + 'Can\'t send messages on this connection'; + + @override + String composerBudgetLimitedTitle(int maxBytes) { + return 'Only $maxBytes characters will fit'; + } + + @override + String get composerBudgetBluetoothCause => + 'The Bluetooth link negotiated a very small packet size, which leaves no room for message text. Try reconnecting, or connect by USB or Wi-Fi instead.'; + + @override + String get composerBudgetGenericCause => + 'The connection to the radio left no room for message text. Try reconnecting.'; + @override String get chat_messageCopied => '消息已复制'; diff --git a/lib/screens/channel_chat_screen.dart b/lib/screens/channel_chat_screen.dart index aa292f32..501ac775 100644 --- a/lib/screens/channel_chat_screen.dart +++ b/lib/screens/channel_chat_screen.dart @@ -39,6 +39,7 @@ import 'settings_screen.dart'; import '../utils/dialog_utils.dart'; import '../widgets/app_shell.dart'; import '../widgets/channel_drawer_list.dart'; +import '../widgets/composer_budget_notice.dart'; import '../widgets/mention_autocomplete.dart'; import '../helpers/emoji_shortcodes.dart'; import '../widgets/chat_zoom_wrapper.dart'; @@ -1429,6 +1430,12 @@ class _ChannelChatScreenState extends State { return Column( mainAxisSize: MainAxisSize.min, children: [ + // Says so out loud when the link leaves no room for text, instead of + // presenting a field that silently rejects every keystroke (#684). + ComposerBudgetNotice( + maxBytes: maxBytes, + transport: connector.activeTransport, + ), if (_replyingToMessage != null) Builder( builder: (context) { diff --git a/lib/screens/chat_screen.dart b/lib/screens/chat_screen.dart index 768a54f8..b9e93599 100644 --- a/lib/screens/chat_screen.dart +++ b/lib/screens/chat_screen.dart @@ -32,6 +32,7 @@ import '../services/chat_text_scale_service.dart'; import '../services/path_history_service.dart'; import '../services/translation_service.dart'; import '../widgets/chat_zoom_wrapper.dart'; +import '../widgets/composer_budget_notice.dart'; import '../widgets/contact_settings_dialog.dart'; import '../widgets/elements_ui.dart'; import '../widgets/mention_autocomplete.dart'; @@ -600,6 +601,27 @@ class _ChatScreenState extends State { ); final colorScheme = Theme.of(context).colorScheme; final settings = context.watch().settings; + return Column( + mainAxisSize: MainAxisSize.min, + children: [ + // Says so out loud when the link leaves no room for text, instead of + // presenting a field that silently rejects every keystroke (#684). + ComposerBudgetNotice( + maxBytes: maxBytes, + transport: connector.activeTransport, + ), + _buildComposerBar(context, colorScheme, settings, maxBytes, connector), + ], + ); + } + + Widget _buildComposerBar( + BuildContext context, + ColorScheme colorScheme, + AppSettings settings, + int maxBytes, + MeshCoreConnector connector, + ) { return Container( padding: const EdgeInsets.all(8), decoration: BoxDecoration( diff --git a/lib/widgets/composer_budget_notice.dart b/lib/widgets/composer_budget_notice.dart new file mode 100644 index 00000000..ac8403bd --- /dev/null +++ b/lib/widgets/composer_budget_notice.dart @@ -0,0 +1,90 @@ +import 'package:flutter/material.dart'; + +import '../connector/meshcore_connector.dart'; +import '../connector/meshcore_protocol.dart'; +import '../l10n/l10n.dart'; + +/// Explains a composer whose byte budget is too small to carry a message. +/// +/// #592 was reported twice as "the keyboard doesn't respond". It was not an +/// input bug: the byte budget had collapsed to 0, so the length limiter +/// rejected every keystroke while the field still focused and blinked. Nothing +/// on screen said why. +/// +/// This is a persistent inline notice rather than a toast on purpose. The +/// condition is a *state* that lasts as long as the link does, not an event, so +/// a transient snackbar would scroll away and leave the same dead field behind. +/// SAFELANE 6 requires a user-facing error to persist; sitting directly above +/// the composer it also lands where the confusion is (#684). +/// +/// Renders nothing when the budget is healthy, so both composers can include it +/// unconditionally. +class ComposerBudgetNotice extends StatelessWidget { + /// The composer's computed limit, from `maxChannelMessageBytes` or + /// `maxContactMessageBytes`. + final int maxBytes; + + /// Transport in use, so the cause can be named plainly instead of described + /// as generic failure. + final MeshCoreTransportType transport; + + const ComposerBudgetNotice({ + super.key, + required this.maxBytes, + required this.transport, + }); + + @override + Widget build(BuildContext context) { + if (isComposerBudgetUsable(maxBytes)) return const SizedBox.shrink(); + + final l10n = context.l10n; + final scheme = Theme.of(context).colorScheme; + + // A budget of 0 blocks every keystroke; 1-15 accepts input but cannot carry + // a sentence. The user needs those described differently: the first is + // "you cannot send", the second is "you have almost no room". + final title = maxBytes <= 0 + ? l10n.composerBudgetBlockedTitle + : l10n.composerBudgetLimitedTitle(maxBytes); + + final cause = transport == MeshCoreTransportType.bluetooth + ? l10n.composerBudgetBluetoothCause + : l10n.composerBudgetGenericCause; + + return Container( + width: double.infinity, + padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 10), + color: scheme.errorContainer, + child: Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Icon(Icons.error_outline, size: 18, color: scheme.onErrorContainer), + const SizedBox(width: 10), + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + title, + style: TextStyle( + fontWeight: FontWeight.w600, + color: scheme.onErrorContainer, + ), + ), + const SizedBox(height: 2), + Text( + cause, + style: TextStyle( + fontSize: 12, + color: scheme.onErrorContainer, + ), + ), + ], + ), + ), + ], + ), + ); + } +} diff --git a/test/connector/mtu_composer_budget_test.dart b/test/connector/mtu_composer_budget_test.dart index 075a7c41..8c21cd67 100644 --- a/test/connector/mtu_composer_budget_test.dart +++ b/test/connector/mtu_composer_budget_test.dart @@ -77,4 +77,63 @@ void main() { ); }); }); + + /// The guard #684 adds. These are the assertions that were left out of this + /// file while it lived on a throwaway branch, because the behaviour they + /// describe did not exist yet. + group('the composer guard recognises an unusable budget (#684)', () { + test('a zero budget is not usable', () { + // The literal #592 symptom: every keystroke rejected, field looks alive. + expect(isComposerBudgetUsable(0), isFalse); + }); + + test('the degenerate #592 budgets are all caught', () { + // DM 4 and channel 1 at the unknown-MTU floor. A field that accepts four + // characters is as misleading as one that accepts none, so the guard has + // to catch the near-misses, not just zero. + expect( + isComposerBudgetUsable( + maxContactMessageBytes(maxFrameBytes: unknownMtuFrameBudget), + ), + isFalse, + reason: 'the 4-byte DM budget must trigger the notice', + ); + expect( + isComposerBudgetUsable( + maxChannelMessageBytes( + 'WSMJ89', + maxFrameBytes: unknownMtuFrameBudget, + ), + ), + isFalse, + reason: 'the 1-byte channel budget must trigger the notice', + ); + }); + + test('the threshold boundary is exact', () { + expect(isComposerBudgetUsable(minUsableComposerBytes - 1), isFalse); + expect(isComposerBudgetUsable(minUsableComposerBytes), isTrue); + }); + + test('a healthy link does NOT trigger the notice', () { + // The negative test: the guard must stay invisible on a working link, or + // it becomes noise that trains users to ignore it. + expect(isComposerBudgetUsable(maxContactMessageBytes()), isTrue); + expect(isComposerBudgetUsable(maxChannelMessageBytes('WSMJ898')), isTrue); + // And at the MTU actually measured on hardware: 247 on Android, 176 on + // Windows once the vendored plugin reports it (#686). + expect( + isComposerBudgetUsable( + maxChannelMessageBytes('WSMJ898', maxFrameBytes: 247 - 3), + ), + isTrue, + ); + expect( + isComposerBudgetUsable( + maxChannelMessageBytes('WSMJ898', maxFrameBytes: 176 - 3), + ), + isTrue, + ); + }); + }); }