feat(#97): Share logs / Open logs folder action on the debug log screen

Platform-adaptive export on the BLE/frame log screen: the system share sheet on
mobile (the priority path), or open the logs folder in the file manager on
desktop. Web-safe (defaultTargetPlatform, no dart:io); flushes the file first so
it is current. Completes #97.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
feat/64-observer-config
Strycher 4 weeks ago
parent a50133f76d
commit a7fcb3e9a4

@ -1,4 +1,5 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/foundation.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import '../l10n/l10n.dart'; import '../l10n/l10n.dart';
@ -6,6 +7,9 @@ import '../services/ble_debug_log_service.dart';
import '../connector/meshcore_protocol.dart'; import '../connector/meshcore_protocol.dart';
import '../widgets/adaptive_app_bar_title.dart'; import '../widgets/adaptive_app_bar_title.dart';
import '../helpers/snack_bar_builder.dart'; import '../helpers/snack_bar_builder.dart';
import 'package:share_plus/share_plus.dart';
import 'package:url_launcher/url_launcher.dart';
import '../services/file_log_service.dart';
enum _BleLogView { frames, rawLogRx } enum _BleLogView { frames, rawLogRx }
@ -29,10 +33,18 @@ class _BleDebugLogScreenState extends State<BleDebugLogScreen> {
final hasEntries = showingFrames final hasEntries = showingFrames
? entries.isNotEmpty ? entries.isNotEmpty
: rawEntries.isNotEmpty; : rawEntries.isNotEmpty;
final isMobile =
defaultTargetPlatform == TargetPlatform.android ||
defaultTargetPlatform == TargetPlatform.iOS;
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
title: AdaptiveAppBarTitle(context.l10n.debugLog_bleTitle), title: AdaptiveAppBarTitle(context.l10n.debugLog_bleTitle),
actions: [ actions: [
IconButton(
tooltip: isMobile ? 'Share logs' : 'Open logs folder',
icon: Icon(isMobile ? Icons.ios_share : Icons.folder_open),
onPressed: () => _exportLogs(context),
),
IconButton( IconButton(
tooltip: context.l10n.debugLog_copyLog, tooltip: context.l10n.debugLog_copyLog,
icon: const Icon(Icons.copy), icon: const Icon(Icons.copy),
@ -160,6 +172,36 @@ class _BleDebugLogScreenState extends State<BleDebugLogScreen> {
); );
} }
/// Export the on-disk log (#97): the system share sheet on mobile, or open the
/// logs folder in the file manager on desktop. The file holds both the app log
/// and BLE frames, flushed first so it's current.
Future<void> _exportLogs(BuildContext context) async {
final messenger = ScaffoldMessenger.of(context);
final file = await FileLogService.instance.flushAndGetActiveFile();
if (file == null) {
messenger.showSnackBar(
const SnackBar(
content: Text('File logging is unavailable on this platform'),
),
);
return;
}
final isMobile =
defaultTargetPlatform == TargetPlatform.android ||
defaultTargetPlatform == TargetPlatform.iOS;
if (isMobile) {
await SharePlus.instance.share(
ShareParams(
subject: 'Offband Meshcore logs',
files: [XFile(file.path)],
),
);
} else {
final dir = FileLogService.instance.logDir;
if (dir != null) await launchUrl(Uri.file(dir.path));
}
}
void _showRawDialog(BuildContext context, _RawPacketInfo info) { void _showRawDialog(BuildContext context, _RawPacketInfo info) {
showDialog( showDialog(
context: context, context: context,

Loading…
Cancel
Save

Powered by TurnKey Linux.