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 <noreply@anthropic.com>
fix/1033-scan-location-message
diffwireauto 4 weeks ago committed by Strycher
parent 3ed11e00e4
commit 92a9cd75a2

@ -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",

@ -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:

@ -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 => 'Копирано лого за отстраняване на грешки';

@ -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';

@ -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';

@ -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';

@ -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é';

@ -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';

@ -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';

@ -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 => 'デバッグログをコピー';

@ -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 => '디버깅 로그 복사';

@ -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';

@ -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';

@ -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';

@ -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 => 'Журнал отладки скопирован';

@ -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ý';

@ -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.';

@ -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';

@ -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 => 'Журнал налагодження скопійовано';

@ -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 => '调试日志已复制';

@ -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(

@ -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<ScannerScreen> {
// 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<ScannerScreen> {
);
}
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<void> _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<ScannerScreen> {
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(

@ -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<AboutView> createState() => _AboutViewState();
}
class _AboutViewState extends State<AboutView> {
String _appVersion = '';
@override
void initState() {
super.initState();
_loadVersionInfo();
}
Future<void> _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<void> _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,
);
}
}
}

@ -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(),
),
],
);
}
}

@ -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<AppSettingsService>();
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<AppDebugLogService>().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(),
],
),
),
],
);
}
}

@ -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<SettingsScreen> {
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<SettingsScreen> {
String? _versionHint;
Timer? _versionHintTimer;
@override
void initState() {
super.initState();
_loadVersionInfo();
}
@override
void dispose() {
_versionHintTimer?.cancel();
super.dispose();
}
Future<void> _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<AppSettingsService>();
@ -263,7 +246,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
SettingsCategory(
icon: Icons.info_outline,
title: l10n.settings_about,
builder: _aboutPane,
builder: (_) => const AboutView(),
),
];
}
@ -877,108 +860,8 @@ class _SettingsScreenState extends State<SettingsScreen> {
);
}
// 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<void> _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<AppSettingsService>();
// #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<SettingsScreen> {
),
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(

@ -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<AppDebugLogEntry> 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<void> 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<File> logs;
if (_isMobile) {
logs = await FileLogService.instance.flushAndGetAllFiles();
} else {
final active = await FileLogService.instance.flushAndGetActiveFile();
logs = active == null ? const <File>[] : <File>[active];
}
final candidates = <File>[
...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 = <File>[];
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<File> logs;
if (_isMobile) {
logs = await FileLogService.instance.flushAndGetAllFiles();
} else {
final active = await FileLogService.instance.flushAndGetActiveFile();
logs = active == null ? const <File>[] : <File>[active];
}
final candidates = <File>[
...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<File> 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);

@ -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<List<String>> _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<MeshCoreConnector>.value(value: connector),
ChangeNotifierProvider<AppSettingsService>(
create: (_) => AppSettingsService(),
),
ChangeNotifierProvider<AppDebugLogService>(
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<AppLocalizations> _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<void> _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<void>.delayed(const Duration(milliseconds: 20));
}
});
await tester.pump();
}
/// Drain ScannerScreen's dispose-time disconnect before teardown.
Future<void> _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<String>.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);
}
});
});
}

@ -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",

Loading…
Cancel
Save

Powered by TurnKey Linux.