From 92a9cd75a29d5e6e223c7b328fc9facf9e1387b8 Mon Sep 17 00:00:00 2001 From: diffwireauto <330573775+diffwireauto@users.noreply.github.com> Date: Wed, 28 Oct 2026 21:59:28 -0400 Subject: [PATCH] feat(#1030): reach Share logs and About from the connect screen A radio that will not connect is exactly when a user needs the log, and the only way to it ran through device Settings, which needs a connected radio. The scanner now has a settings icon that opens an app-only settings screen: App Settings, Debug (Share logs, the logging switch, both log viewers) and About. Navigation only. How logs are written is untouched: Share logs calls the same LogExport.shareLogs the log screens use, on the same on-disk file. The device Settings screen keeps every category. Its About pane and the app-level Debug rows moved into AboutView and DebugLogTiles, which both screens now share; Device CLI, Serial capture and Mesh topology need the radio and stay in device Settings only. Export failures now persist until dismissed and are logged: "No log available to export" was a 4-second snackbar, and a share or save that threw had no handler at all. New owner-approved string: debugLog_exportFailed. Other locales fall back to English per untranslated.json. Tests pin both sides with the radio disconnected: Share logs hands the on-disk file to the share sheet, About shows the version, no device category or radio row appears, both error messages persist, and device Settings still has everything. Each check was made to fail against a deliberately broken build first. Part of Epic #693. Agent: BrightDog (session 38fb0e08) Co-Authored-By: Claude Opus 5.5 --- lib/l10n/app_en.arb | 1 + lib/l10n/app_localizations.dart | 6 + lib/l10n/app_localizations_bg.dart | 4 + lib/l10n/app_localizations_de.dart | 4 + lib/l10n/app_localizations_en.dart | 4 + lib/l10n/app_localizations_es.dart | 4 + lib/l10n/app_localizations_fr.dart | 4 + lib/l10n/app_localizations_hu.dart | 4 + lib/l10n/app_localizations_it.dart | 4 + lib/l10n/app_localizations_ja.dart | 4 + lib/l10n/app_localizations_ko.dart | 4 + lib/l10n/app_localizations_nl.dart | 4 + lib/l10n/app_localizations_pl.dart | 4 + lib/l10n/app_localizations_pt.dart | 4 + lib/l10n/app_localizations_ru.dart | 4 + lib/l10n/app_localizations_sk.dart | 4 + lib/l10n/app_localizations_sl.dart | 4 + lib/l10n/app_localizations_sv.dart | 4 + lib/l10n/app_localizations_uk.dart | 4 + lib/l10n/app_localizations_zh.dart | 4 + lib/screens/app_debug_log_screen.dart | 14 +- lib/screens/scanner_screen.dart | 48 ++- lib/screens/settings/about_view.dart | 134 +++++++ .../settings/app_only_settings_screen.dart | 43 +++ lib/screens/settings/debug_logs_view.dart | 136 +++++++ lib/screens/settings_screen.dart | 187 +--------- lib/utils/log_export.dart | 116 +++--- test/screens/app_only_settings_test.dart | 333 ++++++++++++++++++ untranslated.json | 17 + 29 files changed, 862 insertions(+), 245 deletions(-) create mode 100644 lib/screens/settings/about_view.dart create mode 100644 lib/screens/settings/app_only_settings_screen.dart create mode 100644 lib/screens/settings/debug_logs_view.dart create mode 100644 test/screens/app_only_settings_test.dart diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index d039c6c7..8c5982c6 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -1049,6 +1049,7 @@ "debugLog_shareSubject": "Offband Meshcore logs", "debugLog_logSaved": "Log saved", "debugLog_logUnavailable": "No log available to export", + "debugLog_exportFailed": "Couldn't share the log. Please try again.", "debugLog_copied": "Debug log copied", "debugLog_bleCopied": "BLE log copied", "debugLog_noEntries": "No debug logs yet", diff --git a/lib/l10n/app_localizations.dart b/lib/l10n/app_localizations.dart index b7012c2e..183ec5ad 100644 --- a/lib/l10n/app_localizations.dart +++ b/lib/l10n/app_localizations.dart @@ -3454,6 +3454,12 @@ abstract class AppLocalizations { /// **'No log available to export'** String get debugLog_logUnavailable; + /// No description provided for @debugLog_exportFailed. + /// + /// In en, this message translates to: + /// **'Couldn\'t share the log. Please try again.'** + String get debugLog_exportFailed; + /// No description provided for @debugLog_copied. /// /// In en, this message translates to: diff --git a/lib/l10n/app_localizations_bg.dart b/lib/l10n/app_localizations_bg.dart index d35b52de..04b4f11e 100644 --- a/lib/l10n/app_localizations_bg.dart +++ b/lib/l10n/app_localizations_bg.dart @@ -1939,6 +1939,10 @@ class AppLocalizationsBg extends AppLocalizations { @override String get debugLog_logUnavailable => 'No log available to export'; + @override + String get debugLog_exportFailed => + 'Couldn\'t share the log. Please try again.'; + @override String get debugLog_copied => 'Копирано лого за отстраняване на грешки'; diff --git a/lib/l10n/app_localizations_de.dart b/lib/l10n/app_localizations_de.dart index 35cd8db8..3a6cf7d6 100644 --- a/lib/l10n/app_localizations_de.dart +++ b/lib/l10n/app_localizations_de.dart @@ -1936,6 +1936,10 @@ class AppLocalizationsDe extends AppLocalizations { @override String get debugLog_logUnavailable => 'No log available to export'; + @override + String get debugLog_exportFailed => + 'Couldn\'t share the log. Please try again.'; + @override String get debugLog_copied => 'Debug-Protokoll kopiert'; diff --git a/lib/l10n/app_localizations_en.dart b/lib/l10n/app_localizations_en.dart index 54bf3d39..89ec7ad9 100644 --- a/lib/l10n/app_localizations_en.dart +++ b/lib/l10n/app_localizations_en.dart @@ -1909,6 +1909,10 @@ class AppLocalizationsEn extends AppLocalizations { @override String get debugLog_logUnavailable => 'No log available to export'; + @override + String get debugLog_exportFailed => + 'Couldn\'t share the log. Please try again.'; + @override String get debugLog_copied => 'Debug log copied'; diff --git a/lib/l10n/app_localizations_es.dart b/lib/l10n/app_localizations_es.dart index 4e46d975..80f34f31 100644 --- a/lib/l10n/app_localizations_es.dart +++ b/lib/l10n/app_localizations_es.dart @@ -1935,6 +1935,10 @@ class AppLocalizationsEs extends AppLocalizations { @override String get debugLog_logUnavailable => 'No log available to export'; + @override + String get debugLog_exportFailed => + 'Couldn\'t share the log. Please try again.'; + @override String get debugLog_copied => 'Registro de depuración copiado'; diff --git a/lib/l10n/app_localizations_fr.dart b/lib/l10n/app_localizations_fr.dart index 219de29e..fad58955 100644 --- a/lib/l10n/app_localizations_fr.dart +++ b/lib/l10n/app_localizations_fr.dart @@ -1940,6 +1940,10 @@ class AppLocalizationsFr extends AppLocalizations { @override String get debugLog_logUnavailable => 'No log available to export'; + @override + String get debugLog_exportFailed => + 'Couldn\'t share the log. Please try again.'; + @override String get debugLog_copied => 'Journal de débogage copié'; diff --git a/lib/l10n/app_localizations_hu.dart b/lib/l10n/app_localizations_hu.dart index c08c1cb2..16bbd431 100644 --- a/lib/l10n/app_localizations_hu.dart +++ b/lib/l10n/app_localizations_hu.dart @@ -1943,6 +1943,10 @@ class AppLocalizationsHu extends AppLocalizations { @override String get debugLog_logUnavailable => 'No log available to export'; + @override + String get debugLog_exportFailed => + 'Couldn\'t share the log. Please try again.'; + @override String get debugLog_copied => 'Hibajelentő napló másolva'; diff --git a/lib/l10n/app_localizations_it.dart b/lib/l10n/app_localizations_it.dart index 91389a7e..c66334c6 100644 --- a/lib/l10n/app_localizations_it.dart +++ b/lib/l10n/app_localizations_it.dart @@ -1937,6 +1937,10 @@ class AppLocalizationsIt extends AppLocalizations { @override String get debugLog_logUnavailable => 'No log available to export'; + @override + String get debugLog_exportFailed => + 'Couldn\'t share the log. Please try again.'; + @override String get debugLog_copied => 'Log di debug copiato'; diff --git a/lib/l10n/app_localizations_ja.dart b/lib/l10n/app_localizations_ja.dart index d3010fdd..b00753e1 100644 --- a/lib/l10n/app_localizations_ja.dart +++ b/lib/l10n/app_localizations_ja.dart @@ -1874,6 +1874,10 @@ class AppLocalizationsJa extends AppLocalizations { @override String get debugLog_logUnavailable => 'No log available to export'; + @override + String get debugLog_exportFailed => + 'Couldn\'t share the log. Please try again.'; + @override String get debugLog_copied => 'デバッグログをコピー'; diff --git a/lib/l10n/app_localizations_ko.dart b/lib/l10n/app_localizations_ko.dart index 39187c25..1dc3e323 100644 --- a/lib/l10n/app_localizations_ko.dart +++ b/lib/l10n/app_localizations_ko.dart @@ -1869,6 +1869,10 @@ class AppLocalizationsKo extends AppLocalizations { @override String get debugLog_logUnavailable => 'No log available to export'; + @override + String get debugLog_exportFailed => + 'Couldn\'t share the log. Please try again.'; + @override String get debugLog_copied => '디버깅 로그 복사'; diff --git a/lib/l10n/app_localizations_nl.dart b/lib/l10n/app_localizations_nl.dart index b6236c72..e07c0332 100644 --- a/lib/l10n/app_localizations_nl.dart +++ b/lib/l10n/app_localizations_nl.dart @@ -1925,6 +1925,10 @@ class AppLocalizationsNl extends AppLocalizations { @override String get debugLog_logUnavailable => 'No log available to export'; + @override + String get debugLog_exportFailed => + 'Couldn\'t share the log. Please try again.'; + @override String get debugLog_copied => 'Debuglog gekopieerd'; diff --git a/lib/l10n/app_localizations_pl.dart b/lib/l10n/app_localizations_pl.dart index fe5b39ba..4617a92b 100644 --- a/lib/l10n/app_localizations_pl.dart +++ b/lib/l10n/app_localizations_pl.dart @@ -1947,6 +1947,10 @@ class AppLocalizationsPl extends AppLocalizations { @override String get debugLog_logUnavailable => 'No log available to export'; + @override + String get debugLog_exportFailed => + 'Couldn\'t share the log. Please try again.'; + @override String get debugLog_copied => 'Skopiowano dziennik debugowania'; diff --git a/lib/l10n/app_localizations_pt.dart b/lib/l10n/app_localizations_pt.dart index 7ce0252f..97c824e7 100644 --- a/lib/l10n/app_localizations_pt.dart +++ b/lib/l10n/app_localizations_pt.dart @@ -1934,6 +1934,10 @@ class AppLocalizationsPt extends AppLocalizations { @override String get debugLog_logUnavailable => 'No log available to export'; + @override + String get debugLog_exportFailed => + 'Couldn\'t share the log. Please try again.'; + @override String get debugLog_copied => 'Log de depuração copiado'; diff --git a/lib/l10n/app_localizations_ru.dart b/lib/l10n/app_localizations_ru.dart index 37a816a1..64167d98 100644 --- a/lib/l10n/app_localizations_ru.dart +++ b/lib/l10n/app_localizations_ru.dart @@ -1935,6 +1935,10 @@ class AppLocalizationsRu extends AppLocalizations { @override String get debugLog_logUnavailable => 'No log available to export'; + @override + String get debugLog_exportFailed => + 'Couldn\'t share the log. Please try again.'; + @override String get debugLog_copied => 'Журнал отладки скопирован'; diff --git a/lib/l10n/app_localizations_sk.dart b/lib/l10n/app_localizations_sk.dart index 25689cce..4f7a8e30 100644 --- a/lib/l10n/app_localizations_sk.dart +++ b/lib/l10n/app_localizations_sk.dart @@ -1925,6 +1925,10 @@ class AppLocalizationsSk extends AppLocalizations { @override String get debugLog_logUnavailable => 'No log available to export'; + @override + String get debugLog_exportFailed => + 'Couldn\'t share the log. Please try again.'; + @override String get debugLog_copied => 'Záznam ladenia skopírovaný'; diff --git a/lib/l10n/app_localizations_sl.dart b/lib/l10n/app_localizations_sl.dart index 3c70d749..ab714500 100644 --- a/lib/l10n/app_localizations_sl.dart +++ b/lib/l10n/app_localizations_sl.dart @@ -1923,6 +1923,10 @@ class AppLocalizationsSl extends AppLocalizations { @override String get debugLog_logUnavailable => 'No log available to export'; + @override + String get debugLog_exportFailed => + 'Couldn\'t share the log. Please try again.'; + @override String get debugLog_copied => 'Beležka kopirana.'; diff --git a/lib/l10n/app_localizations_sv.dart b/lib/l10n/app_localizations_sv.dart index 637ec25d..176b957f 100644 --- a/lib/l10n/app_localizations_sv.dart +++ b/lib/l10n/app_localizations_sv.dart @@ -1917,6 +1917,10 @@ class AppLocalizationsSv extends AppLocalizations { @override String get debugLog_logUnavailable => 'No log available to export'; + @override + String get debugLog_exportFailed => + 'Couldn\'t share the log. Please try again.'; + @override String get debugLog_copied => 'Felsökningslogg kopierad'; diff --git a/lib/l10n/app_localizations_uk.dart b/lib/l10n/app_localizations_uk.dart index 08d295ab..bff80ca7 100644 --- a/lib/l10n/app_localizations_uk.dart +++ b/lib/l10n/app_localizations_uk.dart @@ -1929,6 +1929,10 @@ class AppLocalizationsUk extends AppLocalizations { @override String get debugLog_logUnavailable => 'No log available to export'; + @override + String get debugLog_exportFailed => + 'Couldn\'t share the log. Please try again.'; + @override String get debugLog_copied => 'Журнал налагодження скопійовано'; diff --git a/lib/l10n/app_localizations_zh.dart b/lib/l10n/app_localizations_zh.dart index e7790698..9407d34c 100644 --- a/lib/l10n/app_localizations_zh.dart +++ b/lib/l10n/app_localizations_zh.dart @@ -1855,6 +1855,10 @@ class AppLocalizationsZh extends AppLocalizations { @override String get debugLog_logUnavailable => 'No log available to export'; + @override + String get debugLog_exportFailed => + 'Couldn\'t share the log. Please try again.'; + @override String get debugLog_copied => '调试日志已复制'; diff --git a/lib/screens/app_debug_log_screen.dart b/lib/screens/app_debug_log_screen.dart index 5a109208..8311c735 100644 --- a/lib/screens/app_debug_log_screen.dart +++ b/lib/screens/app_debug_log_screen.dart @@ -28,12 +28,7 @@ class AppDebugLogScreen extends StatelessWidget { icon: Icon(LogExport.icon), onPressed: () => LogExport.shareLogs( context, - webContent: () => entries - .map( - (entry) => - '[${entry.formattedTime}] [${entry.levelLabel}] [${entry.tag}] ${entry.message}', - ) - .join('\n'), + webContent: () => LogExport.appLogText(entries), ), ), IconButton( @@ -41,12 +36,7 @@ class AppDebugLogScreen extends StatelessWidget { icon: const Icon(Icons.copy), onPressed: hasEntries ? () async { - final text = entries - .map( - (entry) => - '[${entry.formattedTime}] [${entry.levelLabel}] [${entry.tag}] ${entry.message}', - ) - .join('\n'); + final text = LogExport.appLogText(entries); await Clipboard.setData(ClipboardData(text: text)); if (!context.mounted) return; showDismissibleSnackBar( diff --git a/lib/screens/scanner_screen.dart b/lib/screens/scanner_screen.dart index 47e67267..ed6dd7de 100644 --- a/lib/screens/scanner_screen.dart +++ b/lib/screens/scanner_screen.dart @@ -13,6 +13,7 @@ import '../widgets/battery_optimization_banner.dart'; import '../widgets/device_tile.dart'; import '../helpers/snack_bar_builder.dart'; import 'channels_screen.dart'; +import 'settings/app_only_settings_screen.dart'; import 'tcp_screen.dart'; import 'usb_screen.dart'; @@ -58,17 +59,7 @@ class _ScannerScreenState extends State { // out of it either. The first-connect path for those transports is not // affected: their own screen sits on top while connecting, so // isCurrentRoute is false here and they still navigate themselves. - _changedNavigation = true; - _routingIntoApp = true; - if (mounted) { - Navigator.of(context) - .push( - MaterialPageRoute(builder: (context) => const ChannelsScreen()), - ) - .then((_) { - if (mounted) _routingIntoApp = false; - }); - } + _routeIntoApp(); } }; @@ -92,6 +83,34 @@ class _ScannerScreenState extends State { ); } + void _routeIntoApp() { + _changedNavigation = true; + _routingIntoApp = true; + if (mounted) { + Navigator.of(context) + .push(MaterialPageRoute(builder: (context) => const ChannelsScreen())) + .then((_) { + if (mounted) _routingIntoApp = false; + }); + } + } + + /// App-level settings, reachable with no radio so a user whose radio will + /// not connect can still share the log (#693). + Future _openAppSettings() async { + await Navigator.of( + context, + ).push(MaterialPageRoute(builder: (_) => const AppOnlySettingsScreen())); + // A connection that completed while settings were open routed nowhere, + // because this screen was not the current route. Route in now, as the + // connection listener would have. + if (mounted && + _connector.state == MeshCoreConnectionState.connected && + !_routingIntoApp) { + _routeIntoApp(); + } + } + @override void dispose() { _connector.removeListener(_connectionListener); @@ -121,6 +140,13 @@ class _ScannerScreenState extends State { title: AdaptiveAppBarTitle(context.l10n.scanner_title), centerTitle: true, automaticallyImplyLeading: false, + actions: [ + IconButton( + icon: const Icon(Icons.settings), + tooltip: context.l10n.settings_title, + onPressed: _openAppSettings, + ), + ], ), body: BatteryOptimizationBanner( child: SafeArea( diff --git a/lib/screens/settings/about_view.dart b/lib/screens/settings/about_view.dart new file mode 100644 index 00000000..abef8267 --- /dev/null +++ b/lib/screens/settings/about_view.dart @@ -0,0 +1,134 @@ +import 'package:flutter/material.dart'; +import 'package:package_info_plus/package_info_plus.dart'; +import 'package:url_launcher/url_launcher.dart'; + +import '../../helpers/snack_bar_builder.dart'; +import '../../l10n/l10n.dart'; + +/// The About pane: app identity, version, outbound links and licenses. +/// +/// Needs no radio, so both the device Settings screen and the app-only +/// settings reachable from the scanner show it (#693). Outbound links +/// (offband.org / Play / donate) added by #527. +class AboutView extends StatefulWidget { + const AboutView({super.key}); + + @override + State createState() => _AboutViewState(); +} + +class _AboutViewState extends State { + String _appVersion = ''; + + @override + void initState() { + super.initState(); + _loadVersionInfo(); + } + + Future _loadVersionInfo() async { + final packageInfo = await PackageInfo.fromPlatform(); + if (!mounted) return; + setState(() { + _appVersion = '${packageInfo.version}+${packageInfo.buildNumber}'; + }); + } + + @override + Widget build(BuildContext context) { + final l10n = context.l10n; + return ListView( + padding: const EdgeInsets.all(16), + children: [ + Card( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + ListTile( + leading: const Icon(Icons.info_outline), + title: Text(l10n.appTitle), + subtitle: Text( + l10n.settings_aboutVersion( + _appVersion.isEmpty ? l10n.common_loading : _appVersion, + ), + ), + ), + Padding( + padding: const EdgeInsets.fromLTRB(16, 0, 16, 12), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text(l10n.settings_aboutDescription), + const SizedBox(height: 12), + Text( + l10n.settings_aboutLegalese, + style: Theme.of(context).textTheme.bodySmall, + ), + const SizedBox(height: 4), + Text( + l10n.settings_aboutPresetsAttribution, + style: Theme.of(context).textTheme.bodySmall, + ), + ], + ), + ), + const Divider(height: 1), + ListTile( + leading: const Icon(Icons.language), + title: Text(l10n.settings_aboutWebsite), + trailing: const Icon(Icons.open_in_new, size: 18), + onTap: () => _openExternalUrl('https://offband.org'), + ), + ListTile( + leading: const Icon(Icons.shop_outlined), + title: Text(l10n.settings_aboutPlayStore), + trailing: const Icon(Icons.open_in_new, size: 18), + onTap: () => _openExternalUrl( + 'https://play.google.com/store/apps/details?id=app.offband.meshcore', + ), + ), + ListTile( + leading: const Icon(Icons.favorite_outline), + title: Text(l10n.settings_aboutDonate), + trailing: const Icon(Icons.open_in_new, size: 18), + onTap: () => _openExternalUrl('https://offband.org/donate'), + ), + const Divider(height: 1), + ListTile( + leading: const Icon(Icons.description_outlined), + title: Text(l10n.settings_aboutLicenses), + trailing: const Icon(Icons.chevron_right), + onTap: () => showLicensePage( + context: context, + applicationName: l10n.appTitle, + applicationVersion: _appVersion.isEmpty ? null : _appVersion, + applicationLegalese: l10n.settings_aboutLegalese, + ), + ), + ], + ), + ), + ], + ); + } + + Future _openExternalUrl(String url) async { + try { + if (await launchUrl( + Uri.parse(url), + mode: LaunchMode.externalApplication, + )) { + return; + } + } catch (_) { + // fall through to the failure message + } + if (mounted) { + showDismissibleSnackBar( + context, + content: Text(context.l10n.settings_aboutLinkFailed), + persist: true, + ); + } + } +} diff --git a/lib/screens/settings/app_only_settings_screen.dart b/lib/screens/settings/app_only_settings_screen.dart new file mode 100644 index 00000000..4af8518c --- /dev/null +++ b/lib/screens/settings/app_only_settings_screen.dart @@ -0,0 +1,43 @@ +import 'package:flutter/material.dart'; + +import '../../l10n/l10n.dart'; +import 'about_view.dart'; +import 'app_settings_view.dart'; +import 'debug_logs_view.dart'; +import 'settings_shell.dart'; + +/// The settings that need no radio, opened from the scanner (#693). +/// +/// A user whose radio will not connect still has to be able to share the log, +/// so this offers only app-level categories. Everything that reads or writes +/// the radio stays in the device Settings screen, which is reachable only +/// while connected. Add a category here only if it works with no radio. +class AppOnlySettingsScreen extends StatelessWidget { + const AppOnlySettingsScreen({super.key}); + + @override + Widget build(BuildContext context) { + final l10n = context.l10n; + return SettingsShell( + title: l10n.settings_title, + categories: [ + SettingsCategory( + icon: Icons.tune, + title: l10n.settings_appSettings, + subtitle: l10n.settings_appSettingsSubtitle, + builder: (_) => const AppSettingsView(), + ), + SettingsCategory( + icon: Icons.build_outlined, + title: l10n.settings_debug, + builder: (_) => const DebugLogsView(), + ), + SettingsCategory( + icon: Icons.info_outline, + title: l10n.settings_about, + builder: (_) => const AboutView(), + ), + ], + ); + } +} diff --git a/lib/screens/settings/debug_logs_view.dart b/lib/screens/settings/debug_logs_view.dart new file mode 100644 index 00000000..c30d4b70 --- /dev/null +++ b/lib/screens/settings/debug_logs_view.dart @@ -0,0 +1,136 @@ +import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; + +import '../../helpers/snack_bar_builder.dart'; +import '../../l10n/l10n.dart'; +import '../../services/app_debug_log_service.dart'; +import '../../services/app_settings_service.dart'; +import '../../utils/log_export.dart'; +import '../app_debug_log_screen.dart'; +import '../ble_debug_log_screen.dart'; + +/// The radio-independent rows of the Debug pane: share the log, the app debug +/// logging switch, and the two log viewers. +/// +/// Split out of the device Settings Debug pane (#693) so the scanner's +/// app-only settings can offer them with no radio connected. The radio rows +/// (Device CLI, serial capture, mesh topology) stay in device Settings. +class DebugLogTiles extends StatelessWidget { + const DebugLogTiles({super.key}); + + @override + Widget build(BuildContext context) { + final l10n = context.l10n; + final settingsService = context.watch(); + return Column( + mainAxisSize: MainAxisSize.min, + children: [ + ListTile( + leading: Icon(LogExport.icon), + title: Text(LogExport.tooltip(context)), + onTap: () => LogExport.shareLogs( + context, + webContent: () => LogExport.appLogText( + context.read().entries.reversed, + ), + ), + ), + const Divider(height: 1), + SwitchListTile( + secondary: const Icon(Icons.bug_report_outlined), + title: Text(l10n.appSettings_appDebugLogging), + subtitle: Text(l10n.appSettings_appDebugLoggingSubtitle), + value: settingsService.settings.appDebugLogEnabled, + onChanged: (value) async { + try { + await settingsService.setAppDebugLogEnabled(value); + } catch (_) { + if (context.mounted) { + showDismissibleSnackBar( + context, + content: const Text( + 'Could not change debug logging. Please try again.', + ), + persist: true, + ); + } + return; + } + if (!context.mounted) return; + showDismissibleSnackBar( + context, + content: Text( + value + ? l10n.appSettings_appDebugLoggingEnabled + : l10n.appSettings_appDebugLoggingDisabled, + ), + duration: const Duration(seconds: 2), + ); + }, + ), + const Divider(height: 1), + ListTile( + leading: const Icon(Icons.bluetooth_outlined), + title: Text(l10n.settings_companionDebugLog), + subtitle: Text(l10n.settings_companionDebugLogSubtitle), + trailing: const Icon(Icons.chevron_right), + onTap: () { + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => const BleDebugLogScreen(), + ), + ); + }, + ), + const Divider(height: 1), + ListTile( + leading: const Icon(Icons.code_outlined), + title: Text(l10n.settings_appDebugLog), + subtitle: Text(l10n.settings_appDebugLogSubtitle), + trailing: const Icon(Icons.chevron_right), + onTap: () { + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => const AppDebugLogScreen(), + ), + ); + }, + ), + ], + ); + } +} + +/// The Debug pane of the app-only settings: the log rows in their own card. +class DebugLogsView extends StatelessWidget { + const DebugLogsView({super.key}); + + @override + Widget build(BuildContext context) { + return ListView( + padding: const EdgeInsets.all(16), + children: [ + Card( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Padding( + padding: const EdgeInsets.fromLTRB(16, 16, 16, 8), + child: Text( + context.l10n.settings_debug, + style: const TextStyle( + fontSize: 18, + fontWeight: FontWeight.bold, + ), + ), + ), + const DebugLogTiles(), + ], + ), + ), + ], + ); + } +} diff --git a/lib/screens/settings_screen.dart b/lib/screens/settings_screen.dart index 9c1d4414..27e4a2ef 100644 --- a/lib/screens/settings_screen.dart +++ b/lib/screens/settings_screen.dart @@ -5,8 +5,6 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:meshcore_open/utils/gpx_export.dart'; import 'package:provider/provider.dart'; -import 'package:package_info_plus/package_info_plus.dart'; -import 'package:url_launcher/url_launcher.dart'; import '../connector/meshcore_connector.dart'; import '../connector/meshcore_protocol.dart'; @@ -21,7 +19,9 @@ import '../connector/observer_config_client.dart'; import '../helpers/snack_bar_builder.dart'; import '../utils/build_info.dart'; import 'settings/settings_shell.dart'; +import 'settings/about_view.dart'; import 'settings/app_settings_view.dart'; +import 'settings/debug_logs_view.dart'; import 'settings/message_settings_view.dart'; import 'settings/observer_settings_view.dart'; import 'settings/blocked_view.dart'; @@ -30,8 +30,6 @@ import 'settings/badge_screen_view.dart'; import 'settings/device_ui_view.dart'; import 'settings/location_view.dart'; import '../helpers/device_name_validator.dart'; -import 'app_debug_log_screen.dart'; -import 'ble_debug_log_screen.dart'; import 'device_cli_screen.dart'; import 'export_config_screen.dart'; import 'import_config_screen.dart'; @@ -80,7 +78,6 @@ class SettingsScreen extends StatefulWidget { class _SettingsScreenState extends State { bool _showBatteryVoltage = false; - String _appVersion = ''; // #509 hidden unlock: 7 taps on the version row within a rolling window // reveals the Experimental settings section. @@ -93,26 +90,12 @@ class _SettingsScreenState extends State { String? _versionHint; Timer? _versionHintTimer; - @override - void initState() { - super.initState(); - _loadVersionInfo(); - } - @override void dispose() { _versionHintTimer?.cancel(); super.dispose(); } - Future _loadVersionInfo() async { - final packageInfo = await PackageInfo.fromPlatform(); - if (!mounted) return; - setState(() { - _appVersion = '${packageInfo.version}+${packageInfo.buildNumber}'; - }); - } - void _handleUnlockTap() { final l10n = context.l10n; final settingsService = context.read(); @@ -263,7 +246,7 @@ class _SettingsScreenState extends State { SettingsCategory( icon: Icons.info_outline, title: l10n.settings_about, - builder: _aboutPane, + builder: (_) => const AboutView(), ), ]; } @@ -877,108 +860,8 @@ class _SettingsScreenState extends State { ); } - // About is its own top-level Settings category (#525/#526), no longer a card - // in the Debug pane. Outbound links (offband.org / Play / donate) added by - // #527 between the info block and the licenses row. - Widget _aboutPane(BuildContext context) { - final l10n = context.l10n; - return ListView( - padding: const EdgeInsets.all(16), - children: [ - Card( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - ListTile( - leading: const Icon(Icons.info_outline), - title: Text(l10n.appTitle), - subtitle: Text( - l10n.settings_aboutVersion( - _appVersion.isEmpty ? l10n.common_loading : _appVersion, - ), - ), - ), - Padding( - padding: const EdgeInsets.fromLTRB(16, 0, 16, 12), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text(l10n.settings_aboutDescription), - const SizedBox(height: 12), - Text( - l10n.settings_aboutLegalese, - style: Theme.of(context).textTheme.bodySmall, - ), - const SizedBox(height: 4), - Text( - l10n.settings_aboutPresetsAttribution, - style: Theme.of(context).textTheme.bodySmall, - ), - ], - ), - ), - const Divider(height: 1), - ListTile( - leading: const Icon(Icons.language), - title: Text(l10n.settings_aboutWebsite), - trailing: const Icon(Icons.open_in_new, size: 18), - onTap: () => _openExternalUrl('https://offband.org'), - ), - ListTile( - leading: const Icon(Icons.shop_outlined), - title: Text(l10n.settings_aboutPlayStore), - trailing: const Icon(Icons.open_in_new, size: 18), - onTap: () => _openExternalUrl( - 'https://play.google.com/store/apps/details?id=app.offband.meshcore', - ), - ), - ListTile( - leading: const Icon(Icons.favorite_outline), - title: Text(l10n.settings_aboutDonate), - trailing: const Icon(Icons.open_in_new, size: 18), - onTap: () => _openExternalUrl('https://offband.org/donate'), - ), - const Divider(height: 1), - ListTile( - leading: const Icon(Icons.description_outlined), - title: Text(l10n.settings_aboutLicenses), - trailing: const Icon(Icons.chevron_right), - onTap: () => showLicensePage( - context: context, - applicationName: l10n.appTitle, - applicationVersion: _appVersion.isEmpty ? null : _appVersion, - applicationLegalese: l10n.settings_aboutLegalese, - ), - ), - ], - ), - ), - ], - ); - } - - Future _openExternalUrl(String url) async { - try { - if (await launchUrl( - Uri.parse(url), - mode: LaunchMode.externalApplication, - )) { - return; - } - } catch (_) { - // fall through to the failure message - } - if (mounted) { - showDismissibleSnackBar( - context, - content: Text(context.l10n.settings_aboutLinkFailed), - ); - } - } - Widget _buildDebugCard(BuildContext context) { final l10n = context.l10n; - final settingsService = context.watch(); // #884: the Device CLI console is offered only when the connected radio // speaks the frame-66 CLI (stock v14+ today; Offband flips allowsCliFrame // at the upstream-1.18 absorb). select() so only this gate flipping @@ -1010,67 +893,9 @@ class _SettingsScreenState extends State { ), const Divider(height: 1), ], - SwitchListTile( - secondary: const Icon(Icons.bug_report_outlined), - title: Text(l10n.appSettings_appDebugLogging), - subtitle: Text(l10n.appSettings_appDebugLoggingSubtitle), - value: settingsService.settings.appDebugLogEnabled, - onChanged: (value) async { - try { - await settingsService.setAppDebugLogEnabled(value); - } catch (_) { - if (context.mounted) { - showDismissibleSnackBar( - context, - content: const Text( - 'Could not change debug logging. Please try again.', - ), - ); - } - return; - } - if (!context.mounted) return; - showDismissibleSnackBar( - context, - content: Text( - value - ? l10n.appSettings_appDebugLoggingEnabled - : l10n.appSettings_appDebugLoggingDisabled, - ), - duration: const Duration(seconds: 2), - ); - }, - ), - const Divider(height: 1), - ListTile( - leading: const Icon(Icons.bluetooth_outlined), - title: Text(l10n.settings_companionDebugLog), - subtitle: Text(l10n.settings_companionDebugLogSubtitle), - trailing: const Icon(Icons.chevron_right), - onTap: () { - Navigator.push( - context, - MaterialPageRoute( - builder: (context) => const BleDebugLogScreen(), - ), - ); - }, - ), - const Divider(height: 1), - ListTile( - leading: const Icon(Icons.code_outlined), - title: Text(l10n.settings_appDebugLog), - subtitle: Text(l10n.settings_appDebugLogSubtitle), - trailing: const Icon(Icons.chevron_right), - onTap: () { - Navigator.push( - context, - MaterialPageRoute( - builder: (context) => const AppDebugLogScreen(), - ), - ); - }, - ), + // The app-level rows, shared with the scanner's app-only settings + // (#693). The rows below them need the radio and stay here only. + const DebugLogTiles(), const Divider(height: 1), // Serial capture (#430). English-only for now; localization follow-up. ListTile( diff --git a/lib/utils/log_export.dart b/lib/utils/log_export.dart index 8d17f319..15961d26 100644 --- a/lib/utils/log_export.dart +++ b/lib/utils/log_export.dart @@ -6,8 +6,10 @@ import 'package:flutter/material.dart'; import 'package:share_plus/share_plus.dart'; import '../l10n/l10n.dart'; +import '../services/app_debug_log_service.dart'; import '../services/app_exit_info_service.dart'; import '../services/file_log_service.dart'; +import 'app_logger.dart'; import 'log_web_download.dart'; /// Shared log export for the App-log and BLE-log screens (#393, #97) and any @@ -49,6 +51,23 @@ class LogExport { /// download), so "save" fits both. (#580) static String get actionVerb => (!kIsWeb && _isMobile) ? 'share' : 'save'; + /// The in-memory app log as text, one line per entry in the order given. + /// What a web export downloads and what the App log screen copies. + static String appLogText(Iterable entries) => entries + .map( + (entry) => + '[${entry.formattedTime}] [${entry.levelLabel}] [${entry.tag}] ${entry.message}', + ) + .join('\n'); + + /// An export that failed stays on screen until dismissed, because the user + /// needs to read it rather than glimpse it (SAFELANE 6). + static void _showError(ScaffoldMessengerState messenger, String message) { + messenger.showSnackBar( + SnackBar(content: Text(message), persist: true, showCloseIcon: true), + ); + } + /// Export the combined on-disk app+BLE log (the App/BLE log screens). On web /// there is no on-disk file, so [webContent] supplies the text to download. static Future shareLogs( @@ -67,30 +86,36 @@ class LogExport { // possibly-deactivated widget after the await. final messenger = ScaffoldMessenger.of(context); final l10n = context.l10n; - // On mobile, take every log file rather than just the active one, and the - // ANR traces with them (#906). Two reasons: a trace lives beside the log - // rather than inside it, and a pointer line written once at startup can - // rotate into `.1.log` before the user exports, which would hand over a - // trace with its metadata line missing. Desktop keeps its single-file Save - // As: there are no exit records off Android. - final List logs; - if (_isMobile) { - logs = await FileLogService.instance.flushAndGetAllFiles(); - } else { - final active = await FileLogService.instance.flushAndGetActiveFile(); - logs = active == null ? const [] : [active]; - } - final candidates = [ - ...logs, - if (_isMobile) ...await AppExitInfoService.traceFiles(), - ]; - // Last-moment existence check. Rotation renames files underneath us and a - // trace can be pruned, so a path collected a moment ago may already be - // gone; handing a missing path to the share sheet fails the whole export - // rather than one attachment. final present = []; - for (final f in candidates) { - if (await f.exists()) present.add(f); + try { + // On mobile, take every log file rather than just the active one, and + // the ANR traces with them (#906). Two reasons: a trace lives beside the + // log rather than inside it, and a pointer line written once at startup + // can rotate into `.1.log` before the user exports, which would hand + // over a trace with its metadata line missing. Desktop keeps its + // single-file Save As: there are no exit records off Android. + final List logs; + if (_isMobile) { + logs = await FileLogService.instance.flushAndGetAllFiles(); + } else { + final active = await FileLogService.instance.flushAndGetActiveFile(); + logs = active == null ? const [] : [active]; + } + final candidates = [ + ...logs, + if (_isMobile) ...await AppExitInfoService.traceFiles(), + ]; + // Last-moment existence check. Rotation renames files underneath us and + // a trace can be pruned, so a path collected a moment ago may already be + // gone; handing a missing path to the share sheet fails the whole export + // rather than one attachment. + for (final f in candidates) { + if (await f.exists()) present.add(f); + } + } catch (e) { + appLogger.error('Collecting log files failed: $e', tag: 'LogExport'); + _showError(messenger, l10n.debugLog_exportFailed); + return; } await _exportFile( messenger, @@ -98,6 +123,7 @@ class LogExport { fileName: _defaultFileName, subject: l10n.debugLog_shareSubject, unavailableMessage: l10n.debugLog_logUnavailable, + failedMessage: l10n.debugLog_exportFailed, savedMessage: l10n.debugLog_logSaved, extraFiles: present.skip(1).toList(), ); @@ -119,6 +145,7 @@ class LogExport { fileName: fileName ?? file.uri.pathSegments.last, subject: subject ?? l10n.debugLog_shareSubject, unavailableMessage: l10n.debugLog_logUnavailable, + failedMessage: l10n.debugLog_exportFailed, savedMessage: l10n.debugLog_logSaved, ); } @@ -129,29 +156,37 @@ class LogExport { required String fileName, required String subject, required String unavailableMessage, + required String failedMessage, required String savedMessage, List extraFiles = const [], }) async { if (file == null) { - messenger.showSnackBar(SnackBar(content: Text(unavailableMessage))); + appLogger.warn('No log file to export', tag: 'LogExport'); + _showError(messenger, unavailableMessage); return; } - if (_isMobile) { - await SharePlus.instance.share( - ShareParams( - subject: subject, - files: [ - XFile(file.path), - for (final extra in extraFiles) XFile(extra.path), - ], - ), - ); + try { + if (_isMobile) { + await SharePlus.instance.share( + ShareParams( + subject: subject, + files: [ + XFile(file.path), + for (final extra in extraFiles) XFile(extra.path), + ], + ), + ); + return; + } + // Desktop: let the user pick where to save the file. + final location = await getSaveLocation(suggestedName: fileName); + if (location == null) return; // user cancelled + await file.copy(location.path); + } catch (e) { + appLogger.error('Exporting ${file.path} failed: $e', tag: 'LogExport'); + _showError(messenger, failedMessage); return; } - // Desktop: let the user pick where to save the file. - final location = await getSaveLocation(suggestedName: fileName); - if (location == null) return; // user cancelled - await file.copy(location.path); messenger.showSnackBar(SnackBar(content: Text(savedMessage))); } @@ -162,9 +197,8 @@ class LogExport { }) async { final messenger = ScaffoldMessenger.of(context); if (content.isEmpty) { - messenger.showSnackBar( - SnackBar(content: Text(context.l10n.debugLog_logUnavailable)), - ); + appLogger.warn('No log text to download', tag: 'LogExport'); + _showError(messenger, context.l10n.debugLog_logUnavailable); return; } downloadTextFile(fileName, content); diff --git a/test/screens/app_only_settings_test.dart b/test/screens/app_only_settings_test.dart new file mode 100644 index 00000000..c77d9c32 --- /dev/null +++ b/test/screens/app_only_settings_test.dart @@ -0,0 +1,333 @@ +// Pins #693: with no radio connected, the scanner reaches the app-level +// settings (Share logs, the log viewers, About) and nothing that needs the +// radio. Share logs must hand over the same on-disk log file the log screens +// export, and an export that cannot happen must say so until dismissed. + +import 'dart:io'; + +import 'package:drift/native.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:meshcore_open/connector/meshcore_connector.dart'; +import 'package:meshcore_open/l10n/app_localizations.dart'; +import 'package:meshcore_open/screens/scanner_screen.dart'; +import 'package:meshcore_open/screens/settings/app_only_settings_screen.dart'; +import 'package:meshcore_open/screens/settings_screen.dart'; +import 'package:meshcore_open/services/app_debug_log_service.dart'; +import 'package:meshcore_open/services/app_settings_service.dart'; +import 'package:meshcore_open/services/file_log_service.dart'; +import 'package:meshcore_open/storage/drift/blob_store.dart'; +import 'package:meshcore_open/storage/drift/offband_database.dart'; +import 'package:meshcore_open/storage/prefs_manager.dart'; +import 'package:package_info_plus/package_info_plus.dart'; +import 'package:provider/provider.dart'; +import 'package:shared_preferences/shared_preferences.dart'; + +const _pathProvider = MethodChannel('plugins.flutter.io/path_provider'); +const _share = MethodChannel('dev.fluttercommunity.plus/share'); + +late Directory _supportDir; + +/// Every share the app asked the OS for, as the paths it handed over. +final List> _shared = []; + +/// When set, the share sheet fails the way a platform error would. +bool _shareThrows = false; + +Widget _app(MeshCoreConnector connector, Widget home) { + return MultiProvider( + providers: [ + ChangeNotifierProvider.value(value: connector), + ChangeNotifierProvider( + create: (_) => AppSettingsService(), + ), + ChangeNotifierProvider( + create: (_) => AppDebugLogService(), + ), + ], + child: MaterialApp( + locale: const Locale('en'), + localizationsDelegates: AppLocalizations.localizationsDelegates, + supportedLocales: AppLocalizations.supportedLocales, + home: home, + ), + ); +} + +void _narrowView(WidgetTester tester) { + tester.view.physicalSize = const Size(400, 900); + tester.view.devicePixelRatio = 1.0; + addTearDown(tester.view.resetPhysicalSize); + addTearDown(tester.view.resetDevicePixelRatio); +} + +AppLocalizations _l10n(WidgetTester tester, Type screen) => + AppLocalizations.of(tester.element(find.byType(screen))); + +/// From a scanner with no radio, open the settings gear. +Future _openFromScanner(WidgetTester tester) async { + _narrowView(tester); + final connector = MeshCoreConnector(); + expect(connector.state, MeshCoreConnectionState.disconnected); + await tester.pumpWidget(_app(connector, const ScannerScreen())); + await tester.pumpAndSettle(); + final l10n = _l10n(tester, ScannerScreen); + await tester.tap(find.byTooltip(l10n.settings_title)); + await tester.pumpAndSettle(); + expect(find.byType(AppOnlySettingsScreen), findsOneWidget); + return l10n; +} + +/// Run the real-IO export in the real zone and wait for it to settle, either +/// at the share sheet or at a message on screen. +Future _tapShareAndSettle(WidgetTester tester, String label) async { + final before = _shared.length; + await tester.runAsync(() async { + await tester.tap(find.text(label)); + for (var i = 0; i < 100 && _shared.length == before; i++) { + await Future.delayed(const Duration(milliseconds: 20)); + } + }); + await tester.pump(); +} + +/// Drain ScannerScreen's dispose-time disconnect before teardown. +Future _unmount(WidgetTester tester) async { + await tester.pumpWidget(const SizedBox.shrink()); + await tester.pump(const Duration(milliseconds: 60)); +} + +void main() { + TestWidgetsFlutterBinding.ensureInitialized(); + + setUpAll(() async { + _supportDir = Directory.systemTemp.createTempSync('offband_693_'); + final messenger = + TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger; + messenger.setMockMethodCallHandler(_pathProvider, (call) async { + if (call.method == 'getApplicationSupportDirectory') { + return _supportDir.path; + } + return null; + }); + messenger.setMockMethodCallHandler(_share, (call) async { + if (_shareThrows) { + throw PlatformException(code: 'share_failed'); + } + _shared.add(List.from((call.arguments as Map)['paths'] as List)); + return 'dev.fluttercommunity.plus/share/success'; + }); + await FileLogService.instance.init(); + }); + + tearDownAll(() async { + await FileLogService.instance.dispose(); + if (_supportDir.existsSync()) _supportDir.deleteSync(recursive: true); + }); + + setUp(() async { + SharedPreferences.setMockInitialValues({}); + PrefsManager.reset(); + await PrefsManager.initialize(); + PackageInfo.setMockInitialValues( + appName: 'Offband Meshcore', + packageName: 'app.offband.meshcore', + version: '9.9.9', + buildNumber: '99', + buildSignature: '', + ); + _shareThrows = false; + }); + + group('with no radio connected, the scanner', () { + testWidgets('opens app-only settings: App Settings, Debug, About', ( + tester, + ) async { + final l10n = await _openFromScanner(tester); + + expect(find.text(l10n.settings_appSettings), findsOneWidget); + expect(find.text(l10n.settings_debug), findsOneWidget); + expect(find.text(l10n.settings_about), findsOneWidget); + expect(find.byType(SettingsScreen), findsNothing); + await _unmount(tester); + }); + + testWidgets('offers no category that needs the radio', (tester) async { + final l10n = await _openFromScanner(tester); + + for (final deviceCategory in [ + l10n.settings_nodeSettings, + l10n.settings_radioSettings, + l10n.settings_location, + l10n.radioStats_settingsTile, + l10n.settings_privacy, + l10n.contacts_title, + l10n.block_settingsTitle, + l10n.settings_messageSettings, + 'Observer', + l10n.settings_deviceInfo, + l10n.settings_actions, + l10n.settings_experimental, + ]) { + expect(find.text(deviceCategory), findsNothing, reason: deviceCategory); + } + await _unmount(tester); + }); + + testWidgets('Debug has the log rows and none of the radio rows', ( + tester, + ) async { + final l10n = await _openFromScanner(tester); + await tester.tap(find.text(l10n.settings_debug)); + await tester.pumpAndSettle(); + + expect(find.text(l10n.debugLog_shareLog), findsOneWidget); + expect(find.text(l10n.appSettings_appDebugLogging), findsOneWidget); + expect(find.text(l10n.settings_companionDebugLog), findsOneWidget); + expect(find.text(l10n.settings_appDebugLog), findsOneWidget); + + expect(find.text(l10n.deviceCli_title), findsNothing); + expect(find.text('Serial capture'), findsNothing); + expect(find.text('Mesh topology'), findsNothing); + await _unmount(tester); + }); + + testWidgets('About shows the app version', (tester) async { + final l10n = await _openFromScanner(tester); + await tester.tap(find.text(l10n.settings_about)); + await tester.pumpAndSettle(); + + expect(find.text(l10n.settings_aboutVersion('9.9.9+99')), findsOneWidget); + await _unmount(tester); + }); + }); + + group('Share logs with no radio', () { + testWidgets('hands the on-disk log file to the share sheet', ( + tester, + ) async { + const marker = 'issue-693 marker line'; + FileLogService.instance.write(marker); + final l10n = await _openFromScanner(tester); + await tester.tap(find.text(l10n.settings_debug)); + await tester.pumpAndSettle(); + + final sharesBefore = _shared.length; + await _tapShareAndSettle(tester, l10n.debugLog_shareLog); + + expect(_shared.length, sharesBefore + 1); + final logDir = FileLogService.instance.logDir!.path; + final handedOver = _shared.last; + expect(handedOver, isNotEmpty); + expect(handedOver.first, startsWith(logDir)); + final text = await tester.runAsync( + () => File(handedOver.first).readAsString(), + ); + expect(text, contains(marker)); + expect(find.text(l10n.debugLog_logUnavailable), findsNothing); + expect(find.text(l10n.debugLog_exportFailed), findsNothing); + await _unmount(tester); + }); + + testWidgets('a failing share says so, and the message stays', ( + tester, + ) async { + FileLogService.instance.write('issue-693 failing share'); + _shareThrows = true; + final l10n = await _openFromScanner(tester); + await tester.tap(find.text(l10n.settings_debug)); + await tester.pumpAndSettle(); + + await _tapShareAndSettle(tester, l10n.debugLog_shareLog); + await tester.pump(const Duration(seconds: 1)); + expect(find.text(l10n.debugLog_exportFailed), findsOneWidget); + + // Well past the 4 second default: an error must wait to be dismissed. + // Settle afterwards, or a timed-out message is caught mid-exit and + // still found, and this check could never fail. + await tester.pump(const Duration(seconds: 10)); + await tester.pumpAndSettle(); + expect(find.text(l10n.debugLog_exportFailed), findsOneWidget); + await _unmount(tester); + }); + + testWidgets('no log on disk says so, and the message stays', ( + tester, + ) async { + await tester.runAsync(() async { + await FileLogService.instance.flushAndGetActiveFile(); + for (final f in FileLogService.instance.logDir!.listSync()) { + f.deleteSync(recursive: true); + } + }); + final l10n = await _openFromScanner(tester); + await tester.tap(find.text(l10n.settings_debug)); + await tester.pumpAndSettle(); + + final sharesBefore = _shared.length; + await _tapShareAndSettle(tester, l10n.debugLog_shareLog); + await tester.pump(const Duration(seconds: 1)); + expect(_shared.length, sharesBefore, reason: 'nothing to hand over'); + expect(find.text(l10n.debugLog_logUnavailable), findsOneWidget); + + await tester.pump(const Duration(seconds: 10)); + await tester.pumpAndSettle(); + expect(find.text(l10n.debugLog_logUnavailable), findsOneWidget); + await _unmount(tester); + }); + }); + + group('device Settings, connected, is unchanged by the split', () { + late OffbandDatabase db; + late MeshCoreConnector connector; + + setUp(() { + db = OffbandDatabase(NativeDatabase.memory()); + BlobStore.overrideForTest(BlobStore(db)); + connector = MeshCoreConnector(); + connector.sendFrameOverrideForTest = (_) {}; + connector.setConnectedForTest(); + }); + + tearDown(() async { + BlobStore.clearTestOverride(); + await db.close(); + }); + + testWidgets('keeps its device categories and its radio debug rows', ( + tester, + ) async { + _narrowView(tester); + await tester.pumpWidget(_app(connector, const SettingsScreen())); + await tester.pumpAndSettle(); + final l10n = _l10n(tester, SettingsScreen); + + for (final category in [ + l10n.settings_nodeSettings, + l10n.settings_radioSettings, + l10n.settings_deviceInfo, + l10n.settings_actions, + l10n.settings_debug, + l10n.settings_about, + ]) { + await tester.scrollUntilVisible(find.text(category), 200); + expect(find.text(category), findsOneWidget, reason: category); + } + + await tester.tap(find.text(l10n.settings_debug)); + await tester.pumpAndSettle(); + for (final row in [ + l10n.debugLog_shareLog, + l10n.appSettings_appDebugLogging, + l10n.settings_companionDebugLog, + l10n.settings_appDebugLog, + 'Serial capture', + 'Mesh topology', + ]) { + await tester.scrollUntilVisible(find.text(row), 200); + expect(find.text(row), findsOneWidget, reason: row); + } + }); + }); +} diff --git a/untranslated.json b/untranslated.json index 15068b60..4d9c3a10 100644 --- a/untranslated.json +++ b/untranslated.json @@ -141,6 +141,7 @@ "debugLog_shareSubject", "debugLog_logSaved", "debugLog_logUnavailable", + "debugLog_exportFailed", "channel_heardTooltip", "channel_coreScopeTooltip", "channel_coreScopeRefresh", @@ -477,6 +478,7 @@ "debugLog_shareSubject", "debugLog_logSaved", "debugLog_logUnavailable", + "debugLog_exportFailed", "channel_heardTooltip", "channel_coreScopeTooltip", "channel_coreScopeRefresh", @@ -813,6 +815,7 @@ "debugLog_shareSubject", "debugLog_logSaved", "debugLog_logUnavailable", + "debugLog_exportFailed", "channel_heardTooltip", "channel_coreScopeTooltip", "channel_coreScopeRefresh", @@ -1149,6 +1152,7 @@ "debugLog_shareSubject", "debugLog_logSaved", "debugLog_logUnavailable", + "debugLog_exportFailed", "channel_heardTooltip", "channel_coreScopeTooltip", "channel_coreScopeRefresh", @@ -1485,6 +1489,7 @@ "debugLog_shareSubject", "debugLog_logSaved", "debugLog_logUnavailable", + "debugLog_exportFailed", "channel_heardTooltip", "channel_coreScopeTooltip", "channel_coreScopeRefresh", @@ -1821,6 +1826,7 @@ "debugLog_shareSubject", "debugLog_logSaved", "debugLog_logUnavailable", + "debugLog_exportFailed", "channel_heardTooltip", "channel_coreScopeTooltip", "channel_coreScopeRefresh", @@ -2157,6 +2163,7 @@ "debugLog_shareSubject", "debugLog_logSaved", "debugLog_logUnavailable", + "debugLog_exportFailed", "channel_heardTooltip", "channel_coreScopeTooltip", "channel_coreScopeRefresh", @@ -2493,6 +2500,7 @@ "debugLog_shareSubject", "debugLog_logSaved", "debugLog_logUnavailable", + "debugLog_exportFailed", "channel_heardTooltip", "channel_coreScopeTooltip", "channel_coreScopeRefresh", @@ -2829,6 +2837,7 @@ "debugLog_shareSubject", "debugLog_logSaved", "debugLog_logUnavailable", + "debugLog_exportFailed", "channel_heardTooltip", "channel_coreScopeTooltip", "channel_coreScopeRefresh", @@ -3165,6 +3174,7 @@ "debugLog_shareSubject", "debugLog_logSaved", "debugLog_logUnavailable", + "debugLog_exportFailed", "channel_heardTooltip", "channel_coreScopeTooltip", "channel_coreScopeRefresh", @@ -3501,6 +3511,7 @@ "debugLog_shareSubject", "debugLog_logSaved", "debugLog_logUnavailable", + "debugLog_exportFailed", "channel_heardTooltip", "channel_coreScopeTooltip", "channel_coreScopeRefresh", @@ -3837,6 +3848,7 @@ "debugLog_shareSubject", "debugLog_logSaved", "debugLog_logUnavailable", + "debugLog_exportFailed", "channel_heardTooltip", "channel_coreScopeTooltip", "channel_coreScopeRefresh", @@ -4173,6 +4185,7 @@ "debugLog_shareSubject", "debugLog_logSaved", "debugLog_logUnavailable", + "debugLog_exportFailed", "channel_heardTooltip", "channel_coreScopeTooltip", "channel_coreScopeRefresh", @@ -4509,6 +4522,7 @@ "debugLog_shareSubject", "debugLog_logSaved", "debugLog_logUnavailable", + "debugLog_exportFailed", "channel_heardTooltip", "channel_coreScopeTooltip", "channel_coreScopeRefresh", @@ -4845,6 +4859,7 @@ "debugLog_shareSubject", "debugLog_logSaved", "debugLog_logUnavailable", + "debugLog_exportFailed", "channel_heardTooltip", "channel_coreScopeTooltip", "channel_coreScopeRefresh", @@ -5181,6 +5196,7 @@ "debugLog_shareSubject", "debugLog_logSaved", "debugLog_logUnavailable", + "debugLog_exportFailed", "channel_heardTooltip", "channel_coreScopeTooltip", "channel_coreScopeRefresh", @@ -5517,6 +5533,7 @@ "debugLog_shareSubject", "debugLog_logSaved", "debugLog_logUnavailable", + "debugLog_exportFailed", "channel_heardTooltip", "channel_coreScopeTooltip", "channel_coreScopeRefresh",