This commit is contained in:
Savya Bikram Shah
2026-05-27 15:09:05 +05:45
parent 848b176953
commit aac0dc1513
3 changed files with 11 additions and 4 deletions

View File

@@ -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);
}
}

View File

@@ -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();
});

View File

@@ -5,7 +5,8 @@
"GUID:6a0a834eb41764f12ba55c3fb04a40cb",
"GUID:c1c03c0e5b2f4412b9f2be1c20d6a9b1",
"GUID:b0214a6008ed146ff8f122a6a9c2f6cc",
"GUID:6e5063adab271564ba0098a06a8cebda"
"GUID:6e5063adab271564ba0098a06a8cebda",
"GUID:f51ebe6a0ceec4240a699833d6309b23"
],
"includePlatforms": [],
"excludePlatforms": [],