π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Add V2 support for videos and live photos
Prateek Sunal50e01c1b3e34
diff --git a/mobile/apps/photos/lib/services/home_widget_service.dart b/mobile/apps/photos/lib/services/home_widget_service.dartindex bcfbde9c00..1f0d553257 100644--- a/mobile/apps/photos/lib/services/home_widget_service.dart+++ b/mobile/apps/photos/lib/services/home_widget_service.dart@@ -226,14 +226,41 @@ class HomeWidgetService {String? mainKey,) async {try {- // Only process image files with V2- if (file.fileType != FileType.image) {- _logger.info(- "Skipping V2 for non-image file type: ${file.fileType}",- );- return false;+ // For images, use full file decoding for highest quality+ if (file.fileType == FileType.image) {+ return await _captureImageV2(file, key, title, mainKey);+ }++ // For videos and live photos, use high-res thumbnails (local only)+ if (file.fileType == FileType.video || file.fileType == FileType.livePhoto) {+ // Only local files can get high-res thumbnails from PhotoManager+ // Remote files would require downloading full video, which is too expensive+ if (!file.isRemoteFile) {+ return await _captureVideoOrLivePhotoV2(file, key, title, mainKey);+ } else {+ _logger.info(+ "Skipping V2 for remote ${file.fileType} file: ${file.displayName}",+ );+ return false;+ }}+ // Other file types fall back to V1+ _logger.info("Skipping V2 for file type: ${file.fileType}");+ return false;+ } catch (error, stackTrace) {+ _logger.severe("Failed to save V2 widget", error, stackTrace);+ return false;+ }+ }++ Future<bool> _captureImageV2(+ EnteFile file,+ String key,+ String title,+ String? mainKey,+ ) async {+ try {// Get full image file or high quality versionfinal File? imageFile = file.isRemoteFile? await getFileFromServer(file)@@ -305,7 +332,90 @@ class HomeWidgetService {return true;} catch (error, stackTrace) {- _logger.severe("Failed to save the image V2", error, stackTrace);+ _logger.severe("Failed to save image V2", error, stackTrace);+ return false;+ }+ }++ Future<bool> _captureVideoOrLivePhotoV2(+ EnteFile file,+ String key,+ String title,+ String? mainKey,+ ) async {+ try {+ // Request high-quality thumbnail from PhotoManager (1024px instead of 512px)+ final Uint8List? thumbnail = await getThumbnailFromLocal(+ file,+ size: THUMBNAIL_SIZE_V2.toInt(),+ );++ if (thumbnail == null) {+ _logger.warning(+ "Failed to get high-res thumbnail for V2 widget ${file.displayName}",+ );+ return false;+ }++ // Decode thumbnail to get dimensions+ final ui.Image decodedImage = await compute(+ _decodeImageInIsolate,+ thumbnail,+ );++ final width = decodedImage.width.toDouble();+ final height = decodedImage.height.toDouble();+ final minDimension = width < height ? width : height;+ final size = minDimension < THUMBNAIL_SIZE_V2 ? minDimension : THUMBNAIL_SIZE_V2;++ // Clean up decoded image+ decodedImage.dispose();++ // Create image provider from thumbnail bytes+ final imageProvider = MemoryImage(thumbnail);++ // Create widget with image+ final widget = ClipRRect(+ borderRadius: BorderRadius.circular(32),+ child: Container(+ width: size,+ height: size,+ decoration: BoxDecoration(+ color: Colors.black,+ image: DecorationImage(+ image: imageProvider,+ fit: BoxFit.cover,+ ),+ ),+ ),+ );++ // Render widget using home_widget package+ await hw.HomeWidget.renderFlutterWidget(+ widget,+ logicalSize: Size(size, size),+ key: key,+ );++ // Format date for display+ final subText = await SmartMemoriesService.getDateFormattedLocale(+ creationTime: file.creationTime!,+ );++ // Create metadata+ final Map<String, dynamic> metadata = {+ "title": title,+ "subText": subText,+ "generatedId": file.generatedID!,+ if (mainKey != null) "mainKey": mainKey,+ };++ // Save metadata in platform-specific format+ await _saveWidgetMetadata(key, metadata);++ return true;+ } catch (error, stackTrace) {+ _logger.severe("Failed to save video/live photo V2", error, stackTrace);return false;}}