diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/components/StarterPack/ShareDialog.tsx | 2 | ||||
-rw-r--r-- | src/lib/media/manip.ts | 32 | ||||
-rw-r--r-- | src/view/com/lightbox/Lightbox.tsx | 2 |
3 files changed, 32 insertions, 4 deletions
diff --git a/src/components/StarterPack/ShareDialog.tsx b/src/components/StarterPack/ShareDialog.tsx index 1d92c623c..44d5eb816 100644 --- a/src/components/StarterPack/ShareDialog.tsx +++ b/src/components/StarterPack/ShareDialog.tsx @@ -73,7 +73,7 @@ function ShareDialogInner({ try { await saveImageToMediaLibrary({uri: imageUrl}) - Toast.show(_(msg`Image saved to your camera roll!`)) + Toast.show(_(msg`Image saved`)) control.close() } catch (e: unknown) { Toast.show(_(msg`An error occurred while saving the QR code!`), 'xmark') diff --git a/src/lib/media/manip.ts b/src/lib/media/manip.ts index 4578406e0..62cbc55ac 100644 --- a/src/lib/media/manip.ts +++ b/src/lib/media/manip.ts @@ -126,6 +126,8 @@ export async function shareImageModal({uri}: {uri: string}) { safeDeleteAsync(imagePath) } +const ALBUM_NAME = 'Bluesky' + export async function saveImageToMediaLibrary({uri}: {uri: string}) { // download the file to cache // NOTE @@ -139,8 +141,34 @@ export async function saveImageToMediaLibrary({uri}: {uri: string}) { imagePath = normalizePath(await moveToPermanentPath(imagePath, '.png'), true) // save - await MediaLibrary.createAssetAsync(imagePath) - safeDeleteAsync(imagePath) + try { + if (isAndroid) { + // android triggers an annoying permission prompt if you try and move an image + // between albums. therefore, we need to either create the album with the image + // as the starting image, or put it directly into the album + const album = await MediaLibrary.getAlbumAsync(ALBUM_NAME) + if (album) { + // if album exists, put the image straight in there + await MediaLibrary.createAssetAsync(imagePath, album) + } else { + // otherwise, create album with asset (albums must always have at least one asset) + await MediaLibrary.createAlbumAsync( + ALBUM_NAME, + undefined, + undefined, + imagePath, + ) + } + } else { + await MediaLibrary.createAssetAsync(imagePath) + } + } catch (err) { + logger.error(err instanceof Error ? err : String(err), { + message: 'Failed to save image to media library', + }) + } finally { + safeDeleteAsync(imagePath) + } } export function getImageDim(path: string): Promise<Dimensions> { diff --git a/src/view/com/lightbox/Lightbox.tsx b/src/view/com/lightbox/Lightbox.tsx index 628bd2b9a..677256191 100644 --- a/src/view/com/lightbox/Lightbox.tsx +++ b/src/view/com/lightbox/Lightbox.tsx @@ -41,7 +41,7 @@ export function Lightbox() { } try { await saveImageToMediaLibrary({uri}) - Toast.show(_(msg`Saved to your camera roll`)) + Toast.show(_(msg`Image saved`)) } catch (e: any) { Toast.show(_(msg`Failed to save image: ${String(e)}`), 'xmark') } |