feat(#393): add Share action to App-log screen (shared export helper)
Extract the BLE screen's on-disk log export into lib/utils/log_export.dart and reuse it on the App-log screen, so both log screens have one consistent Share action: OS share sheet on mobile, open logs folder on desktop. The shared file already holds the app log and BLE frames combined. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>feat/393-app-log-share
parent
d3fd110509
commit
331e454178
@ -0,0 +1,56 @@
|
|||||||
|
import 'package:flutter/foundation.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:share_plus/share_plus.dart';
|
||||||
|
import 'package:url_launcher/url_launcher.dart';
|
||||||
|
|
||||||
|
import '../services/file_log_service.dart';
|
||||||
|
|
||||||
|
/// Shared log export for the App-log and BLE-log screens (#393, #97).
|
||||||
|
///
|
||||||
|
/// The on-disk log file ([FileLogService]) holds both the app log and BLE
|
||||||
|
/// frames as one combined stream, so either screen exports the same complete
|
||||||
|
/// file. Both screens use these helpers so their Share action can't drift.
|
||||||
|
class LogExport {
|
||||||
|
const LogExport._();
|
||||||
|
|
||||||
|
static bool get _isMobile =>
|
||||||
|
defaultTargetPlatform == TargetPlatform.android ||
|
||||||
|
defaultTargetPlatform == TargetPlatform.iOS;
|
||||||
|
|
||||||
|
/// Platform-standard glyph: Android share (connected nodes), iOS square+arrow,
|
||||||
|
/// desktop reveals the saved file (folder). #396
|
||||||
|
static IconData get icon => defaultTargetPlatform == TargetPlatform.android
|
||||||
|
? Icons.share
|
||||||
|
: _isMobile
|
||||||
|
? Icons.ios_share
|
||||||
|
: Icons.folder_open;
|
||||||
|
|
||||||
|
static String get tooltip => _isMobile ? 'Share logs' : 'Open logs folder';
|
||||||
|
|
||||||
|
/// Flush the on-disk log and hand it to the OS share sheet (mobile), or open
|
||||||
|
/// the logs folder in the file manager (desktop). Shows a snackbar if file
|
||||||
|
/// logging is unavailable (e.g. web).
|
||||||
|
static Future<void> shareLogs(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;
|
||||||
|
}
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in new issue