Skip to content

An open-source cross-platform alternative to AirDrop

feat: tap to open received file

Tien Do Nam8e7c9f773640
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7349ca73..8a30a182 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,8 @@
## 1.3.0 (2023-01-)
- feat: enter custom target address
+- feat(windows): set destination folder
+- feat: tap to open received file
- fix: update nearby device attributes when scan again
## 1.2.0 (2022-12-31)
@@ -12,7 +14,7 @@
## 1.1.0 (2022-12-30)
- feat(android): add media picker
-- feat(iOS): merge image and video to common media picker
+- feat(ios): merge image and video to common media picker
- fix(android): missing internet permission
## 1.0.0 (2022-12-29)
diff --git a/assets/i18n/strings.i18n.json b/assets/i18n/strings.i18n.json
index d45105c9..88aa1a8d 100644
--- a/assets/i18n/strings.i18n.json
+++ b/assets/i18n/strings.i18n.json
@@ -101,6 +101,7 @@
"progressPage": {
"titleSending": "Sending files",
"titleReceiving": "Receiving files",
+ "savedToGallery": "Saved in Photos",
"total": {
"title": {
"sending": "Total progress ({time})",
diff --git a/assets/i18n/strings_de.i18n.json b/assets/i18n/strings_de.i18n.json
index 64799ba8..8cbb63ce 100644
--- a/assets/i18n/strings_de.i18n.json
+++ b/assets/i18n/strings_de.i18n.json
@@ -101,6 +101,7 @@
"progressPage": {
"titleSending": "Sende Dateien",
"titleReceiving": "Empfange Dateien",
+ "savedToGallery": "in Fotos gespeichert",
"total": {
"title": {
"sending": "Gesamtfortschritt ({time})",
diff --git a/lib/model/server/receiving_file.dart b/lib/model/server/receiving_file.dart
index 97208b1a..91e19622 100644
--- a/lib/model/server/receiving_file.dart
+++ b/lib/model/server/receiving_file.dart
@@ -10,6 +10,7 @@ class ReceivingFile with _$ReceivingFile {
required FileDto file,
required FileStatus status,
required String? token,
- required String? tempPath, // file is saved to a temporary path first
+ required String? path, // when finished
+ required bool savedToGallery, // when finished
}) = _ReceivingFile;
}
diff --git a/lib/pages/progress_page.dart b/lib/pages/progress_page.dart
index 6fd2b239..4ca886c6 100644
--- a/lib/pages/progress_page.dart
+++ b/lib/pages/progress_page.dart
@@ -13,6 +13,7 @@ import 'package:localsend_app/util/file_speed_helper.dart';
import 'package:localsend_app/util/platform_check.dart';
import 'package:localsend_app/widget/custom_progress_bar.dart';
import 'package:localsend_app/widget/dialogs/cancel_session_dialog.dart';
+import 'package:open_filex/open_filex.dart';
import 'package:routerino/routerino.dart';
class ProgressPage extends ConsumerStatefulWidget {
@@ -118,44 +119,57 @@ class _ProgressPageState extends ConsumerState<ProgressPage> {
final file = _files[index - 1];
final fileStatus = receiveState?.files[file.id]?.status ?? sendState!.files[file.id]!.status;
+ final savedToGallery = receiveState?.files[file.id]?.savedToGallery ?? false;
return Padding(
padding: const EdgeInsets.symmetric(vertical: 10),
- child: Row(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Icon(file.fileType.icon, size: 46),
- const SizedBox(width: 10),
- Expanded(
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Row(
- children: [
- Flexible(
- child: Text(
- file.fileName,
- style: const TextStyle(fontSize: 16),
- maxLines: 1,
- overflow: TextOverflow.ellipsis,
+ child: InkWell(
+ splashColor: Colors.transparent,
+ splashFactory: NoSplash.splashFactory,
+ highlightColor: Colors.transparent,
+ hoverColor: Colors.transparent,
+ onTap: fileStatus == FileStatus.finished && receiveState != null && !savedToGallery
+ ? () => OpenFilex.open(receiveState.files[file.id]!.path)
+ : null,
+ child: Row(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Icon(file.fileType.icon, size: 46),
+ const SizedBox(width: 10),
+ Expanded(
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Row(
+ children: [
+ Flexible(
+ child: Text(
+ file.fileName,
+ style: const TextStyle(fontSize: 16),
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ ),
),
+ Text(' (${file.size.asReadableFileSize})', style: const TextStyle(fontSize: 16)),
+ ],
+ ),
+ if (fileStatus == FileStatus.sending)
+ Padding(
+ padding: const EdgeInsets.only(top: 5),
+ child: CustomProgressBar(
+ progress: progressNotifier.getProgress(file.id),
+ ),
+ )
+ else
+ Text(
+ savedToGallery ? t.progressPage.savedToGallery : fileStatus.label,
+ style: TextStyle(color: fileStatus.getColor(context)),
),
- Text(' (${file.size.asReadableFileSize})', style: const TextStyle(fontSize: 16)),
- ],
- ),
- if (fileStatus == FileStatus.sending)
- Padding(
- padding: const EdgeInsets.only(top: 5),
- child: CustomProgressBar(
- progress: progressNotifier.getProgress(file.id),
- ),
- )
- else
- Text(fileStatus.label, style: TextStyle(color: fileStatus.getColor(context))),
- ],
+ ],
+ ),
),
- ),
- ],
+ ],
+ ),
),
);
},
diff --git a/lib/provider/network/server_provider.dart b/lib/provider/network/server_provider.dart
index 462a34c3..b191b289 100644
--- a/lib/provider/network/server_provider.dart
+++ b/lib/provider/network/server_provider.dart
@@ -137,7 +137,8 @@ class ServerNotifier extends StateNotifier<ServerState?> {
file: file,
status: FileStatus.queue,
token: null,
- tempPath: null,
+ path: null,
+ savedToGallery: false,
),
},
startTime: null,
@@ -215,10 +216,11 @@ class ServerNotifier extends StateNotifier<ServerState?> {
print('Saving ${receivingFile.file.fileName} to $destinationPath');
try {
+ final saveToGallery = checkPlatformWithGallery() && _ref.read(settingsProvider).saveToGallery &&
+ (receivingFile.file.fileType == FileType.image || receivingFile.file.fileType == FileType.video);
await saveFile(
destinationPath: destinationPath,
- saveToGallery: checkPlatformWithGallery() && _ref.read(settingsProvider).saveToGallery &&
- (receivingFile.file.fileType == FileType.image || receivingFile.file.fileType == FileType.video),
+ saveToGallery: saveToGallery,
stream: request.read(),
onProgress: (savedBytes) {
if (receivingFile.file.size != 0) {
@@ -230,12 +232,22 @@ class ServerNotifier extends StateNotifier<ServerState?> {
return Response.badRequest();
}
state = state?.copyWith(
- receiveState: state?.receiveState?.withFileStatus(fileId, FileStatus.finished),
+ receiveState: state?.receiveState?.fileFinished(
+ fileId: fileId,
+ status: FileStatus.finished,
+ path: saveToGallery ? null : destinationPath,
+ savedToGallery: saveToGallery,
+ ),
);
print('Saved ${receivingFile.file.fileName}.');
} catch (e, st) {
state = state?.copyWith(
- receiveState: state?.receiveState?.withFileStatus(fileId, FileStatus.failed),
+ receiveState: state?.receiveState?.fileFinished(
+ fileId: fileId,
+ status: FileStatus.failed,
+ path: null,
+ savedToGallery: false,
+ ),
);
print(e);
print(st);
@@ -298,7 +310,8 @@ class ServerNotifier extends StateNotifier<ServerState?> {
file: file.file,
status: fileIds.contains(file.file.id) ? FileStatus.queue : FileStatus.skipped,
token: fileIds.contains(file.file.id) ? _uuid.v4() : null,
- tempPath: null,
+ path: null,
+ savedToGallery: false,
),
},
responseHandler: null,
@@ -369,7 +382,16 @@ Future<String> _digestFilePath({required String dir, required String fileName})
}
extension on ReceiveState {
- ReceiveState withFileStatus(String fileId, FileStatus status) {
- return copyWith(files: {...files}..update(fileId, (file) => file.copyWith(status: status)));
+ ReceiveState fileFinished({
+ required String fileId,
+ required FileStatus status,
+ required String? path,
+ required bool savedToGallery,
+ }) {
+ return copyWith(files: {...files}..update(fileId, (file) => file.copyWith(
+ status: status,
+ path: path,
+ savedToGallery: savedToGallery,
+ )));
}
}
diff --git a/pubspec.lock b/pubspec.lock
index 291c0abf..b1f818f6 100644
--- a/pubspec.lock
+++ b/pubspec.lock
@@ -611,6 +611,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.5.0"
+ open_filex:
+ dependency: "direct main"
+ description:
+ name: open_filex
+ url: "https://pub.dartlang.org"
+ source: hosted
+ version: "4.3.2"
package_config:
dependency: transitive
description:
diff --git a/pubspec.yaml b/pubspec.yaml
index f3dcd354..dd045a92 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -27,6 +27,7 @@ dependencies:
image_picker: 0.8.6
json_annotation: 4.7.0
network_info_plus: 3.0.1
+ open_filex: 4.3.2
package_info_plus: 3.0.2
path_provider: 2.0.11
permission_handler: 10.2.0