From aac0dc15135a1d0bc2d529a4f0715652495cde8d Mon Sep 17 00:00:00 2001 From: Savya Bikram Shah Date: Wed, 27 May 2026 15:09:05 +0545 Subject: [PATCH] Updates --- .../Core/Contracts/Services/Gallery/IGalleryService.cs | 4 +++- .../Code/Services/Gallery/Core/GalleryService.cs | 8 ++++++-- .../Code/Services/Gallery/Services.Gallery.asmdef | 3 ++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/Assets/Darkmatter/Code/Core/Contracts/Services/Gallery/IGalleryService.cs b/Assets/Darkmatter/Code/Core/Contracts/Services/Gallery/IGalleryService.cs index 4274987..c83ab65 100644 --- a/Assets/Darkmatter/Code/Core/Contracts/Services/Gallery/IGalleryService.cs +++ b/Assets/Darkmatter/Code/Core/Contracts/Services/Gallery/IGalleryService.cs @@ -1,3 +1,4 @@ +using System.Threading; using Cysharp.Threading.Tasks; using UnityEngine; @@ -5,6 +6,7 @@ namespace Darkmatter.Core.Contracts.Services.Gallery { public interface IGalleryService { - UniTask SaveImageAsync(Texture2D sprite, string fileName, string albumName = "Colorbook"); + UniTask SaveImageAsync(Texture2D sprite, string fileName, + CancellationToken cancellationToken); } } \ No newline at end of file diff --git a/Assets/Darkmatter/Code/Services/Gallery/Core/GalleryService.cs b/Assets/Darkmatter/Code/Services/Gallery/Core/GalleryService.cs index f3a454a..61217ad 100644 --- a/Assets/Darkmatter/Code/Services/Gallery/Core/GalleryService.cs +++ b/Assets/Darkmatter/Code/Services/Gallery/Core/GalleryService.cs @@ -1,4 +1,5 @@ using System; +using System.Threading; using Cysharp.Threading.Tasks; using Darkmatter.Core.Contracts.Services.Gallery; using UnityEngine; @@ -7,7 +8,7 @@ namespace Darkmatter.Services.Gallery { public class GalleryService : IGalleryService { - public async UniTask SaveImageAsync(Texture2D image, string fileName, string albumName = "Colorbook") + public async UniTask SaveImageAsync(Texture2D image, string fileName, CancellationToken cancellationToken) { var permission = await NativeGallery.RequestPermissionAsync(NativeGallery.PermissionType.Write, NativeGallery.MediaType.Image); @@ -18,10 +19,12 @@ namespace Darkmatter.Services.Gallery } var tcs = new UniTaskCompletionSource(); + var registration = cancellationToken.Register(() => tcs.TrySetCanceled(cancellationToken)); - NativeGallery.SaveImageToGallery(image, albumName, + NativeGallery.SaveImageToGallery(image, "Colorbook", filename: $"colorbook_{DateTime.UtcNow:yyyyMMdd_HHmmss}.png", callback: (success, path) => { + registration.Dispose(); if (!success) { Debug.LogError("Failed to save image to gallery."); @@ -30,6 +33,7 @@ namespace Darkmatter.Services.Gallery { Debug.Log($"Image saved to gallery at: {path}"); } + tcs.TrySetResult(); }); diff --git a/Assets/Darkmatter/Code/Services/Gallery/Services.Gallery.asmdef b/Assets/Darkmatter/Code/Services/Gallery/Services.Gallery.asmdef index d8d9b33..177f280 100644 --- a/Assets/Darkmatter/Code/Services/Gallery/Services.Gallery.asmdef +++ b/Assets/Darkmatter/Code/Services/Gallery/Services.Gallery.asmdef @@ -5,7 +5,8 @@ "GUID:6a0a834eb41764f12ba55c3fb04a40cb", "GUID:c1c03c0e5b2f4412b9f2be1c20d6a9b1", "GUID:b0214a6008ed146ff8f122a6a9c2f6cc", - "GUID:6e5063adab271564ba0098a06a8cebda" + "GUID:6e5063adab271564ba0098a06a8cebda", + "GUID:f51ebe6a0ceec4240a699833d6309b23" ], "includePlatforms": [], "excludePlatforms": [],