You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
meshcore-client/lib/utils/log_export.dart

57 lines
1.9 KiB

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));
}
}
}

Powered by TurnKey Linux.