Skip to content

Commit

Permalink
Migrate image_gallery_saver to gal (#625)
Browse files Browse the repository at this point in the history
* Migrate `image_gallery_saver` to `gal`

* chore: polish

---------

Co-authored-by: Tien Do Nam <dev.tien.donam@gmail.com>
  • Loading branch information
natsuk4ze and Tienisto committed Aug 22, 2023
1 parent f74b3ae commit 5997b72
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 18 deletions.
3 changes: 1 addition & 2 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
android:name="${applicationName}"
android:usesCleartextTraffic="true"
android:banner="@drawable/banner"
android:icon="@mipmap/ic_launcher"
android:requestLegacyExternalStorage="true"> <!-- localsend: image_gallery_saver requires requestLegacyExternalStorage -->
android:icon="@mipmap/ic_launcher">

<!-- localsend: prevent multiple instances by android:launchMode="singleTask" -->
<activity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,12 +384,13 @@ class ReceiveController {

_logger.info('Saving ${receivingFile.file.fileName} to $destinationPath');

final saveToGallery =
receiveState.saveToGallery && (receivingFile.file.fileType == FileType.image || receivingFile.file.fileType == FileType.video);
final fileType = receivingFile.file.fileType;
final saveToGallery = receiveState.saveToGallery && (fileType == FileType.image || fileType == FileType.video);
await saveFile(
destinationPath: destinationPath,
name: receivingFile.desiredName!,
saveToGallery: saveToGallery,
isImage: fileType == FileType.image,
stream: request.read(),
onProgress: (savedBytes) {
if (receivingFile.file.size != 0) {
Expand Down
8 changes: 3 additions & 5 deletions lib/util/native/file_saver.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'dart:io';

import 'package:flutter/foundation.dart';
import 'package:image_gallery_saver/image_gallery_saver.dart';
import 'package:gal/gal.dart';
import 'package:localsend_app/util/native/platform_check.dart';
import 'package:logging/logging.dart';
import 'package:permission_handler/permission_handler.dart';
Expand All @@ -14,6 +14,7 @@ Future<void> saveFile({
required String destinationPath,
required String name,
required bool saveToGallery,
required bool isImage,
required Stream<List<int>> stream,
required void Function(int savedBytes) onProgress,
}) async {
Expand Down Expand Up @@ -42,10 +43,7 @@ Future<void> saveFile({
await sink.close();

if (saveToGallery) {
final result = await ImageGallerySaver.saveFile(destinationPath, name: name);
if (result is Map && result['isSuccess'] == false) {
throw 'Could not save media to gallery. Has permission been granted?\n\nTechnical error:\n${result['errorMessage']}';
}
isImage ? await Gal.putImage(destinationPath) : await Gal.putVideo(destinationPath);
await File(destinationPath).delete();
}

Expand Down
16 changes: 8 additions & 8 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "3.2.0"
gal:
dependency: "direct main"
description:
name: gal
sha256: "612a2bb6268a8eefc520cdd38d4df03a5938adb81766dce1e3f1e7238d099020"
url: "https://pub.dev"
source: hosted
version: "1.8.6"
get_it:
dependency: transitive
description:
Expand Down Expand Up @@ -629,14 +637,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "4.0.16"
image_gallery_saver:
dependency: "direct main"
description:
name: image_gallery_saver
sha256: "467de169167b5c4e1ddde65395e4653c336a82f760b6700ea295085b7f2dd248"
url: "https://pub.dev"
source: hosted
version: "2.0.2"
image_picker:
dependency: "direct main"
description:
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ dependencies:
flutter_markdown: 0.6.14
flutter_riverpod: 2.3.6
freezed_annotation: 2.2.0
image_gallery_saver: 2.0.2
gal: 1.8.6
image_picker: 0.8.9
intl: 0.18.0
json_annotation: 4.8.1
Expand Down

0 comments on commit 5997b72

Please sign in to comment.