Skip to content

Commit

Permalink
Support file/image transfer by pasting files from the clipboard.
Browse files Browse the repository at this point in the history
  • Loading branch information
gitstart committed Sep 8, 2023
1 parent 3e92c0c commit 7d242cf
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
6 changes: 4 additions & 2 deletions assets/i18n/strings.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
"stop": "Stop",
"save": "Save",
"unchanged": "Unchanged",
"unknown": "Unknown"
"unknown": "Unknown",
"noItemInClipboard": "No item in Clipboard"
},
"receiveTab": {
"title": "Receive",
Expand All @@ -58,7 +59,8 @@
"folder": "Folder",
"media": "Media",
"text": "Text",
"app": "App"
"app": "App",
"clipboard": "Clipboard"
},
"shareIntentInfo": "You can also use the \"Share\" feature of your mobile device to select files more easily.",
"nearbyDevices": "Nearby devices",
Expand Down
24 changes: 23 additions & 1 deletion lib/util/native/file_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:async';

import 'package:file_picker/file_picker.dart';
import 'package:file_selector/file_selector.dart' as file_selector;
import 'package:file_selector/file_selector.dart';
import 'package:flutter/material.dart';
import 'package:localsend_app/gen/strings.g.dart';
import 'package:localsend_app/pages/apk_picker_page.dart';
Expand All @@ -15,6 +16,7 @@ import 'package:localsend_app/widget/dialogs/loading_dialog.dart';
import 'package:localsend_app/widget/dialogs/message_input_dialog.dart';
import 'package:localsend_app/widget/dialogs/no_permission_dialog.dart';
import 'package:logging/logging.dart';
import 'package:pasteboard/pasteboard.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:riverpie_flutter/riverpie_flutter.dart';
import 'package:routerino/routerino.dart';
Expand All @@ -27,7 +29,8 @@ enum FilePickerOption {
folder(Icons.folder),
media(Icons.image),
text(Icons.subject),
app(Icons.apps);
app(Icons.apps),
clipboard(Icons.paste);

const FilePickerOption(this.icon);

Expand All @@ -45,6 +48,8 @@ enum FilePickerOption {
return t.sendTab.picker.text;
case FilePickerOption.app:
return t.sendTab.picker.app;
case FilePickerOption.clipboard:
return t.sendTab.picker.clipboard;
}
}

Expand Down Expand Up @@ -74,6 +79,7 @@ enum FilePickerOption {
FilePickerOption.file,
FilePickerOption.folder,
FilePickerOption.text,
FilePickerOption.clipboard,
];
}
}
Expand Down Expand Up @@ -187,6 +193,22 @@ enum FilePickerOption {
ref.notifier(selectedSendingFilesProvider).addMessage(result);
}
break;
case FilePickerOption.clipboard:
// ignore: use_build_context_synchronously
late List<String> files = [];
await Pasteboard.files().then((value) => {for (final file in value) files.add(file)});
if (files.isNotEmpty) {
await ref.notifier(selectedSendingFilesProvider).addFiles<file_selector.XFile>(
files: files.map((e) => XFile(e)).toList(),
converter: CrossFileConverters.convertXFile,
);
} else {
if (!context.mounted) return;
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(t.general.noItemInClipboard),
));
}
break;
case FilePickerOption.app:
// Currently, only Android APK
// ignore: use_build_context_synchronously
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ dependencies:
network_info_plus: 4.0.2
open_filex: 4.3.2
package_info_plus: 4.1.0
pasteboard: ^0.2.0
path: 1.8.3
path_provider: 2.1.0
permission_handler: 10.4.3
Expand Down

0 comments on commit 7d242cf

Please sign in to comment.