Skip to content

An open-source cross-platform alternative to AirDrop

feat: add additional buttons to receive history

Tien Do Nama6d2fd9a3d83
diff --git a/assets/CHANGELOG.md b/assets/CHANGELOG.md
index 4a06fec2..9e6129ee 100644
--- a/assets/CHANGELOG.md
+++ b/assets/CHANGELOG.md
@@ -1,6 +1,7 @@
## 1.8.0 (2023-)
- feat: add troubleshoot page
+- feat: add 2 buttons to receive history: open folder + delete history
- feat: cleanup scan UI by hiding multiple network interfaces inside the scan button
- feat(android): share apk and install apk
- feat(android): Android TV support
diff --git a/lib/pages/receive_history_page.dart b/lib/pages/receive_history_page.dart
index f299a8c5..3773d0cf 100644
--- a/lib/pages/receive_history_page.dart
+++ b/lib/pages/receive_history_page.dart
@@ -3,8 +3,12 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:localsend_app/gen/strings.g.dart';
import 'package:localsend_app/model/receive_history_entry.dart';
import 'package:localsend_app/provider/receive_history_provider.dart';
+import 'package:localsend_app/provider/settings_provider.dart';
import 'package:localsend_app/util/file_size_helper.dart';
+import 'package:localsend_app/util/native/get_destination_directory.dart';
import 'package:localsend_app/util/native/open_file.dart';
+import 'package:localsend_app/util/native/open_folder.dart';
+import 'package:localsend_app/util/platform_check.dart';
import 'package:localsend_app/widget/dialogs/file_info_dialog.dart';
import 'package:localsend_app/widget/file_thumbnail.dart';
import 'package:localsend_app/widget/responsive_list_view.dart';
@@ -46,16 +50,34 @@ class ReceiveHistoryPage extends ConsumerWidget {
appBar: AppBar(
title: Text(t.receiveHistoryPage.title),
),
- body: Builder(builder: (context) {
- if (entries.isEmpty) {
- return Center(
- child: Text(t.receiveHistoryPage.empty, style: Theme.of(context).textTheme.headlineMedium),
- );
- }
-
- return ResponsiveListView(
- padding: const EdgeInsets.symmetric(horizontal: 15, vertical: 20),
- children: [
+ body: ResponsiveListView(
+ padding: const EdgeInsets.symmetric(horizontal: 15, vertical: 20),
+ children: [
+ Row(
+ children: [
+ ElevatedButton.icon(
+ onPressed: checkPlatform([TargetPlatform.iOS]) ? null : () async {
+ final destination = ref.read(settingsProvider.select((s) => s.destination)) ?? await getDefaultDestinationDirectory();
+ openFolder(destination);
+ },
+ icon: const Icon(Icons.folder),
+ label: Text(t.receiveHistoryPage.openFolder),
+ ),
+ const SizedBox(width: 20),
+ ElevatedButton.icon(
+ onPressed: entries.isEmpty ? null : () => ref.read(receiveHistoryProvider.notifier).removeAll(),
+ icon: const Icon(Icons.delete),
+ label: Text(t.receiveHistoryPage.deleteHistory),
+ ),
+ ],
+ ),
+ const SizedBox(height: 20),
+ if (entries.isEmpty)
+ Padding(
+ padding: const EdgeInsets.only(top: 100),
+ child: Center(child: Text(t.receiveHistoryPage.empty, style: Theme.of(context).textTheme.headlineMedium)),
+ )
+ else
...entries.map((entry) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 8),
@@ -127,9 +149,8 @@ class ReceiveHistoryPage extends ConsumerWidget {
),
);
}),
- ],
- );
- }),
+ ],
+ ),
);
}
}
diff --git a/lib/provider/network/server_provider.dart b/lib/provider/network/server_provider.dart
index 12741ef5..80d88501 100644
--- a/lib/provider/network/server_provider.dart
+++ b/lib/provider/network/server_provider.dart
@@ -2,7 +2,6 @@ import 'dart:async';
import 'dart:convert';
import 'dart:io';
-import 'package:flutter/foundation.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:localsend_app/constants.dart';
import 'package:localsend_app/model/dto/info_dto.dart';
@@ -25,10 +24,10 @@ import 'package:localsend_app/util/api_route_builder.dart';
import 'package:localsend_app/util/device_info_helper.dart';
import 'package:localsend_app/util/file_path_helper.dart';
import 'package:localsend_app/util/file_saver.dart';
+import 'package:localsend_app/util/native/get_destination_directory.dart';
import 'package:localsend_app/util/platform_check.dart';
import 'package:localsend_app/util/security_helper.dart';
import 'package:localsend_app/util/tray_helper.dart';
-import 'package:path_provider/path_provider.dart' as path;
import 'package:routerino/routerino.dart';
import 'package:shelf/shelf.dart';
import 'package:shelf/shelf_io.dart';
@@ -150,23 +149,7 @@ class ServerNotifier extends StateNotifier<ServerState?> {
}
final settings = _ref.read(settingsProvider);
- String? destinationDir = settings.destination;
- if (destinationDir == null) {
- switch (defaultTargetPlatform) {
- case TargetPlatform.android:
- destinationDir = '/storage/emulated/0/Download';
- break;
- case TargetPlatform.iOS:
- destinationDir = (await path.getApplicationDocumentsDirectory()).path;
- break;
- case TargetPlatform.linux:
- case TargetPlatform.macOS:
- case TargetPlatform.windows:
- case TargetPlatform.fuchsia:
- destinationDir = (await path.getDownloadsDirectory())!.path.replaceAll('\\', '/');
- break;
- }
- }
+ final destinationDir = settings.destination ?? await getDefaultDestinationDirectory();
print('Destination Directory: $destinationDir');
diff --git a/lib/provider/receive_history_provider.dart b/lib/provider/receive_history_provider.dart
index ef9c66e8..ec23b105 100644
--- a/lib/provider/receive_history_provider.dart
+++ b/lib/provider/receive_history_provider.dart
@@ -45,4 +45,9 @@ class ReceiveHistoryNotifier extends StateNotifier<List<ReceiveHistoryEntry>> {
await _service.setReceiveHistory(updated);
state = updated;
}
+
+ Future<void> removeAll() async {
+ await _service.setReceiveHistory([]);
+ state = [];
+ }
}
diff --git a/lib/util/native/get_destination_directory.dart b/lib/util/native/get_destination_directory.dart
new file mode 100644
index 00000000..e1ed289d
--- /dev/null
+++ b/lib/util/native/get_destination_directory.dart
@@ -0,0 +1,16 @@
+import 'package:flutter/foundation.dart';
+import 'package:path_provider/path_provider.dart' as path;
+
+Future<String> getDefaultDestinationDirectory() async {
+ switch (defaultTargetPlatform) {
+ case TargetPlatform.android:
+ return '/storage/emulated/0/Download';
+ case TargetPlatform.iOS:
+ return (await path.getApplicationDocumentsDirectory()).path;
+ case TargetPlatform.linux:
+ case TargetPlatform.macOS:
+ case TargetPlatform.windows:
+ case TargetPlatform.fuchsia:
+ return (await path.getDownloadsDirectory())!.path.replaceAll('\\', '/');
+ }
+}
diff --git a/lib/util/native/open_folder.dart b/lib/util/native/open_folder.dart
new file mode 100644
index 00000000..89f6d4c1
--- /dev/null
+++ b/lib/util/native/open_folder.dart
@@ -0,0 +1,10 @@
+import 'package:open_filex/open_filex.dart';
+
+/// Opens the selected file which is stored on the device.
+Future<void> openFolder(String path) async {
+ if (!path.endsWith('/')) {
+ path = '$path/';
+ }
+ final result = await OpenFilex.open(path);
+ print('Open folder result: ${result.message}, path: $path');
+}
diff --git a/lib/util/platform_check.dart b/lib/util/platform_check.dart
index a4609618..5a580d59 100644
--- a/lib/util/platform_check.dart
+++ b/lib/util/platform_check.dart
@@ -7,6 +7,10 @@ bool checkPlatform(List<TargetPlatform> platforms, {bool web = false}) {
return platforms.contains(defaultTargetPlatform);
}
+bool checkPlatformIsNot(List<TargetPlatform> platforms, {bool web = false}) {
+ return !checkPlatform(platforms, web: web);
+}
+
/// This platform runs on a "traditional" computer
bool checkPlatformIsDesktop() {
return checkPlatform([TargetPlatform.linux, TargetPlatform.windows, TargetPlatform.macOS]);