Skip to content

An open-source cross-platform alternative to AirDrop

feat: add folder should include the folder itself

Tien Do Nam2e5f923e5925
diff --git a/assets/CHANGELOG.md b/assets/CHANGELOG.md
index a133a0fa..13b5d1ff 100644
--- a/assets/CHANGELOG.md
+++ b/assets/CHANGELOG.md
@@ -1,5 +1,6 @@
## 1.9.1 (2023-)
+- feat: add folder should include the folder itself
- fix: handle file names with special characters in link share mode
- fix(android): fix status bar icon color after picking a media file
- fix(linux): add libayatana-appindicator3-1 to AppImage dependencies (by @TheGB0077)
diff --git a/lib/pages/home_page.dart b/lib/pages/home_page.dart
index 0b648694..db4b9f19 100644
--- a/lib/pages/home_page.dart
+++ b/lib/pages/home_page.dart
@@ -93,7 +93,7 @@ class _HomePageState extends ConsumerState<HomePage> {
onDragDone: (event) async {
if (event.files.length == 1 && Directory(event.files.first.path).existsSync()) {
// user dropped a directory
- await ref.read(selectedSendingFilesProvider.notifier).addDirectory(event.files.first.path, includeDirectory: true);
+ await ref.read(selectedSendingFilesProvider.notifier).addDirectory(event.files.first.path);
} else {
// user dropped one or more files
await ref.read(selectedSendingFilesProvider.notifier).addFiles(
diff --git a/lib/provider/selection/selected_sending_files_provider.dart b/lib/provider/selection/selected_sending_files_provider.dart
index 007e6759..b3af789b 100644
--- a/lib/provider/selection/selected_sending_files_provider.dart
+++ b/lib/provider/selection/selected_sending_files_provider.dart
@@ -67,16 +67,13 @@ class SelectedSendingFilesNotifier extends Notifier<List<CrossFile>> {
/// Adds files inside the directory recursively.
/// If [includeDirectory] is true, the directory itself will be added as part of each file path.
- Future<void> addDirectory(String directoryPath, {required bool includeDirectory}) async {
+ Future<void> addDirectory(String directoryPath) async {
print('Reading files in $directoryPath');
final newFiles = <CrossFile>[];
final directoryName = p.basename(directoryPath);
await for (final entity in Directory(directoryPath).list(recursive: true)) {
if (entity is File) {
- String relative = p.relative(entity.path, from: directoryPath).replaceAll('\\', '/');
- if (includeDirectory) {
- relative = '$directoryName/$relative';
- }
+ final relative = '$directoryName/${p.relative(entity.path, from: directoryPath).replaceAll('\\', '/')}';
print('Add file $relative');
final file = CrossFile(
name: relative,
diff --git a/lib/util/native/file_picker.dart b/lib/util/native/file_picker.dart
index 561359a0..f691afbe 100644
--- a/lib/util/native/file_picker.dart
+++ b/lib/util/native/file_picker.dart
@@ -124,7 +124,7 @@ enum FilePickerOption {
try {
final directoryPath = await FilePicker.platform.getDirectoryPath();
if (directoryPath != null) {
- await ref.read(selectedSendingFilesProvider.notifier).addDirectory(directoryPath, includeDirectory: false);
+ await ref.read(selectedSendingFilesProvider.notifier).addDirectory(directoryPath);
}
} catch (e) {
print(e);