1
0
mirror of https://github.com/immich-app/immich.git synced 2024-11-24 08:52:28 +02:00

fix(mobile): LivePhoto video not uploaded during manual asset upload (#3732)

This commit is contained in:
shalong-tanwen 2023-08-17 12:29:49 +00:00 committed by GitHub
parent 78a2a9e666
commit d1e74a28d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 19 deletions

View File

@ -149,16 +149,30 @@ class ManualUploadNotifier extends StateNotifier<ManualUploadState> {
} }
Future<bool> _startUpload(Iterable<Asset> allManualUploads) async { Future<bool> _startUpload(Iterable<Asset> allManualUploads) async {
bool hasErrors = false;
try { try {
_backupProvider.updateBackupProgress(BackUpProgressEnum.manualInProgress); _backupProvider.updateBackupProgress(BackUpProgressEnum.manualInProgress);
if (ref.read(galleryPermissionNotifier.notifier).hasPermission) { if (ref.read(galleryPermissionNotifier.notifier).hasPermission) {
await PhotoManager.clearFileCache(); await PhotoManager.clearFileCache();
Set<AssetEntity> allUploadAssets = allManualUploads // We do not have 1:1 mapping of all AssetEntity fields to Asset. This results in cases
.where((e) => e.isLocal && e.local != null) // where platform specific fields such as `subtype` used to detect platform specific assets such as
.map((e) => e.local!) // LivePhoto in iOS is lost when we directly fetch the local asset from Asset using Asset.local
.toSet(); List<AssetEntity?> allAssetsFromDevice = await Future.wait(
allManualUploads
// Filter local only assets
.where((e) => e.isLocal && !e.isRemote)
.map((e) => e.local!.obtainForNewProperties()),
);
if (allAssetsFromDevice.length != allManualUploads.length) {
_log.warning(
'[_startUpload] Refreshed upload list -> ${allManualUploads.length - allAssetsFromDevice.length} asset will not be uploaded',
);
}
Set<AssetEntity> allUploadAssets = allAssetsFromDevice.nonNulls.toSet();
if (allUploadAssets.isEmpty) { if (allUploadAssets.isEmpty) {
debugPrint("[_startUpload] No Assets to upload - Abort Process"); debugPrint("[_startUpload] No Assets to upload - Abort Process");
@ -213,7 +227,7 @@ class ManualUploadNotifier extends StateNotifier<ManualUploadState> {
'[_startUpload] Manual Upload Completed - success: ${state.successfulUploads},' '[_startUpload] Manual Upload Completed - success: ${state.successfulUploads},'
' failed: ${state.totalAssetsToUpload - state.successfulUploads}', ' failed: ${state.totalAssetsToUpload - state.successfulUploads}',
); );
bool hasErrors = false;
// User cancelled upload // User cancelled upload
if (!ok && state.cancelToken.isCancelled) { if (!ok && state.cancelToken.isCancelled) {
await _localNotificationService.showOrUpdateManualUploadStatus( await _localNotificationService.showOrUpdateManualUploadStatus(
@ -237,32 +251,29 @@ class ManualUploadNotifier extends StateNotifier<ManualUploadState> {
presentBanner: true, presentBanner: true,
); );
} }
_backupProvider.updateBackupProgress(BackUpProgressEnum.idle);
_handleAppInActivity();
await _backupProvider.notifyBackgroundServiceCanRun();
return !hasErrors;
} else { } else {
openAppSettings(); openAppSettings();
debugPrint("[_startUpload] Do not have permission to the gallery"); debugPrint("[_startUpload] Do not have permission to the gallery");
} }
} catch (e) { } catch (e) {
debugPrint("ERROR _startUpload: ${e.toString()}"); debugPrint("ERROR _startUpload: ${e.toString()}");
} hasErrors = true;
} finally {
_backupProvider.updateBackupProgress(BackUpProgressEnum.idle); _backupProvider.updateBackupProgress(BackUpProgressEnum.idle);
_handleAppInActivity(); _handleAppInActivity();
await _localNotificationService.closeNotification( await _localNotificationService.closeNotification(
LocalNotificationService.manualUploadDetailedNotificationID, LocalNotificationService.manualUploadDetailedNotificationID,
); );
await _backupProvider.notifyBackgroundServiceCanRun(); await _backupProvider.notifyBackgroundServiceCanRun();
return false; }
return !hasErrors;
} }
void _handleAppInActivity() { void _handleAppInActivity() {
final appState = ref.read(appStateProvider.notifier).getAppState(); final appState = ref.read(appStateProvider.notifier).getAppState();
// The app is currently in background. Perform the necessary cleanups which // The app is currently in background. Perform the necessary cleanups which
// are on-hold for upload completion // are on-hold for upload completion
if (appState != AppStateEnum.active || appState != AppStateEnum.resumed) { if (appState != AppStateEnum.active && appState != AppStateEnum.resumed) {
ref.read(appStateProvider.notifier).handleAppInactivity(); ref.read(appStateProvider.notifier).handleAppInactivity();
} }
} }

View File

@ -6,7 +6,7 @@ version: 1.73.0+96
isar_version: &isar_version 3.1.0+1 isar_version: &isar_version 3.1.0+1
environment: environment:
sdk: ">=3.0.0-0 <4.0.0" sdk: ">=3.0.0 <4.0.0"
dependencies: dependencies:
flutter: flutter: