Skip to content

Commit

Permalink
fix: download motion photos on ios
Browse files Browse the repository at this point in the history
  • Loading branch information
alextran1502 committed Oct 20, 2024
1 parent bfba697 commit fa469a7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 16 deletions.
2 changes: 1 addition & 1 deletion mobile/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ Future<void> initApp() async {
};

PlatformDispatcher.instance.onError = (error, stack) {
debugPrint("FlutterError - Catch all: $error");
debugPrint("FlutterError - Catch all: $error \n $stack");
log.severe('PlatformDispatcher - Catch all', error, stack);
return true;
};
Expand Down
33 changes: 19 additions & 14 deletions mobile/lib/services/download.service.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:io';

import 'package:background_downloader/background_downloader.dart';
import 'package:flutter/services.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:immich_mobile/entities/store.entity.dart';
import 'package:immich_mobile/entities/asset.entity.dart';
Expand Down Expand Up @@ -114,38 +115,42 @@ class DownloadService {
_findTaskRecord(records, livePhotosId, LivePhotosPart.video);
final imageFilePath = await imageRecord.task.filePath();
final videoFilePath = await videoRecord.task.filePath();
Asset? resultAsset;

try {
resultAsset = await _fileMediaRepository.saveLivePhoto(
final result = await _fileMediaRepository.saveLivePhoto(
image: File(imageFilePath),
video: File(videoFilePath),
title: task.filename,
);
if (resultAsset == null) {
_log.warning(
"Asset cannot be saved as a live photo. This is most likely a motion photo. Saving only the image file",
);
resultAsset = await _fileMediaRepository

return result != null;
} on PlatformException catch (error, stack) {
// Handle saving MotionPhotos on iOS
if (error.code == 'PHPhotosErrorDomain (-1)') {
final result = await _fileMediaRepository
.saveImageWithFile(imageFilePath, title: task.filename);
return result != null;
}
await _downloadRepository.deleteRecordsWithIds([
imageRecord.task.taskId,
videoRecord.task.taskId,
]);

return resultAsset != null;
_log.severe("Error saving live photo", error, stack);
return false;
} catch (error, stack) {
_log.severe("Error saving live photo", error, stack);
return false;
} finally {
final imageFile = File(imageFilePath);
final videoFile = File(videoFilePath);
if (await imageFile.exists()) {
await imageFile.delete();
}

final videoFile = File(videoFilePath);
if (await videoFile.exists()) {
await videoFile.delete();
}

await _downloadRepository.deleteRecordsWithIds([
imageRecord.task.taskId,
videoRecord.task.taskId,
]);
}
}

Expand Down
2 changes: 1 addition & 1 deletion mobile/lib/widgets/forms/login/login_form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ class LoginForm extends HookConsumerWidget {
populateTestLoginInfo1() {
usernameController.text = 'testuser@email.com';
passwordController.text = 'password';
serverEndpointController.text = 'http://192.168.1.118:2283/api';
serverEndpointController.text = 'http://10.1.15.216:2283/api';
}

login() async {
Expand Down

0 comments on commit fa469a7

Please sign in to comment.