Skip to content

An open-source cross-platform alternative to AirDrop

feat: add a copy button to the log screens (#3591)

Shlomo06ff5c5d538b
diff --git a/app/lib/pages/debug/discovery_debug_page.dart b/app/lib/pages/debug/discovery_debug_page.dart
index 43258083..93171f23 100644
--- a/app/lib/pages/debug/discovery_debug_page.dart
+++ b/app/lib/pages/debug/discovery_debug_page.dart
@@ -1,7 +1,9 @@
import 'package:flutter/material.dart';
+import 'package:flutter/services.dart';
import 'package:intl/intl.dart';
import 'package:localsend_app/provider/logging/discovery_logs_provider.dart';
import 'package:localsend_app/provider/network/nearby_devices_provider.dart';
+import 'package:localsend_app/util/ui/snackbar.dart';
import 'package:localsend_app/widget/copyable_text.dart';
import 'package:localsend_app/widget/responsive_list_view.dart';
import 'package:refena_flutter/refena_flutter.dart';
@@ -18,6 +20,30 @@ class DiscoveryDebugPage extends StatelessWidget {
return Scaffold(
appBar: AppBar(
title: const Text('Discovery Debugging'),
+ actions: [
+ IconButton(
+ tooltip: 'Copy all logs',
+ icon: const Icon(Icons.copy),
+ onPressed: logs.isEmpty
+ ? null
+ : () async {
+ try {
+ await Clipboard.setData(
+ ClipboardData(
+ text: logs.map((log) => '[${_dateFormat.format(log.timestamp)}] ${log.log}').join('\n'),
+ ),
+ );
+ if (context.mounted) {
+ context.showSnackBar('Copied discovery logs to clipboard');
+ }
+ } catch (e) {
+ if (context.mounted) {
+ context.showSnackBar('Failed to copy logs: $e');
+ }
+ }
+ },
+ ),
+ ],
),
body: ResponsiveListView(
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 30),
diff --git a/app/lib/pages/debug/http_logs_page.dart b/app/lib/pages/debug/http_logs_page.dart
index d28af532..cb57d984 100644
--- a/app/lib/pages/debug/http_logs_page.dart
+++ b/app/lib/pages/debug/http_logs_page.dart
@@ -1,6 +1,8 @@
import 'package:flutter/material.dart';
+import 'package:flutter/services.dart';
import 'package:intl/intl.dart';
import 'package:localsend_app/provider/logging/http_logs_provider.dart';
+import 'package:localsend_app/util/ui/snackbar.dart';
import 'package:localsend_app/widget/copyable_text.dart';
import 'package:localsend_app/widget/responsive_list_view.dart';
import 'package:refena_flutter/refena_flutter.dart';
@@ -16,6 +18,30 @@ class HttpLogsPage extends StatelessWidget {
return Scaffold(
appBar: AppBar(
title: const Text('HTTP Logs'),
+ actions: [
+ IconButton(
+ tooltip: 'Copy all logs',
+ icon: const Icon(Icons.copy),
+ onPressed: logs.isEmpty
+ ? null
+ : () async {
+ try {
+ await Clipboard.setData(
+ ClipboardData(
+ text: logs.map((log) => '[${_dateFormat.format(log.timestamp)}] ${log.log}').join('\n'),
+ ),
+ );
+ if (context.mounted) {
+ context.showSnackBar('Copied HTTP logs to clipboard');
+ }
+ } catch (e) {
+ if (context.mounted) {
+ context.showSnackBar('Failed to copy logs: $e');
+ }
+ }
+ },
+ ),
+ ],
),
body: ResponsiveListView(
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 30),
diff --git a/app/lib/pages/device_details_page.dart b/app/lib/pages/device_details_page.dart
index 343f13cb..17b9772a 100644
--- a/app/lib/pages/device_details_page.dart
+++ b/app/lib/pages/device_details_page.dart
@@ -1,10 +1,12 @@
import 'package:flutter/material.dart';
+import 'package:flutter/services.dart';
import 'package:localsend_app/gen/strings.g.dart';
import 'package:localsend_app/model/persistence/favorite_device.dart';
import 'package:localsend_app/pages/verify_page.dart';
import 'package:localsend_app/provider/favorites_provider.dart';
import 'package:localsend_app/util/favorites.dart';
import 'package:localsend_app/util/system_date_time_formatter.dart';
+import 'package:localsend_app/util/ui/snackbar.dart';
import 'package:localsend_app/widget/big_button.dart';
import 'package:localsend_app/widget/dialogs/favorite_delete_dialog.dart';
import 'package:localsend_app/widget/dialogs/favorite_edit_dialog.dart';
@@ -121,7 +123,33 @@ class _DeviceDetailsPageState extends State<DeviceDetailsPage> with Refena {
],
),
const SizedBox(height: 20),
- Text(t.deviceDetailsPage.logs.title, style: Theme.of(context).textTheme.titleMedium),
+ Row(
+ children: [
+ Expanded(child: Text(t.deviceDetailsPage.logs.title, style: Theme.of(context).textTheme.titleMedium)),
+ IconButton(
+ tooltip: t.general.copy,
+ icon: const Icon(Icons.copy),
+ onPressed: _logs.isEmpty
+ ? null
+ : () async {
+ try {
+ await Clipboard.setData(
+ ClipboardData(
+ text: _logs.map((log) => '[${SystemDateTimeFormatter.time(context, log.timestamp)}] ${log.description}').join('\n'),
+ ),
+ );
+ if (context.mounted) {
+ context.showSnackBar(t.general.copiedToClipboard);
+ }
+ } catch (e) {
+ if (context.mounted) {
+ context.showSnackBar('${t.general.error}: $e');
+ }
+ }
+ },
+ ),
+ ],
+ ),
const SizedBox(height: 10),
if (_logs.isEmpty)
Text(t.deviceDetailsPage.logs.empty, style: const TextStyle(color: Colors.grey))