Bluesky app fork with some witchin' additions 💫
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

[Android] Save photos to "Bluesky" folder (#8018)

authored by

Samuel Newman and committed by
GitHub
207527f1 36697755

+32 -4
+1 -1
src/components/StarterPack/ShareDialog.tsx
··· 73 73 74 74 try { 75 75 await saveImageToMediaLibrary({uri: imageUrl}) 76 - Toast.show(_(msg`Image saved to your camera roll!`)) 76 + Toast.show(_(msg`Image saved`)) 77 77 control.close() 78 78 } catch (e: unknown) { 79 79 Toast.show(_(msg`An error occurred while saving the QR code!`), 'xmark')
+30 -2
src/lib/media/manip.ts
··· 126 126 safeDeleteAsync(imagePath) 127 127 } 128 128 129 + const ALBUM_NAME = 'Bluesky' 130 + 129 131 export async function saveImageToMediaLibrary({uri}: {uri: string}) { 130 132 // download the file to cache 131 133 // NOTE ··· 139 141 imagePath = normalizePath(await moveToPermanentPath(imagePath, '.png'), true) 140 142 141 143 // save 142 - await MediaLibrary.createAssetAsync(imagePath) 143 - safeDeleteAsync(imagePath) 144 + try { 145 + if (isAndroid) { 146 + // android triggers an annoying permission prompt if you try and move an image 147 + // between albums. therefore, we need to either create the album with the image 148 + // as the starting image, or put it directly into the album 149 + const album = await MediaLibrary.getAlbumAsync(ALBUM_NAME) 150 + if (album) { 151 + // if album exists, put the image straight in there 152 + await MediaLibrary.createAssetAsync(imagePath, album) 153 + } else { 154 + // otherwise, create album with asset (albums must always have at least one asset) 155 + await MediaLibrary.createAlbumAsync( 156 + ALBUM_NAME, 157 + undefined, 158 + undefined, 159 + imagePath, 160 + ) 161 + } 162 + } else { 163 + await MediaLibrary.createAssetAsync(imagePath) 164 + } 165 + } catch (err) { 166 + logger.error(err instanceof Error ? err : String(err), { 167 + message: 'Failed to save image to media library', 168 + }) 169 + } finally { 170 + safeDeleteAsync(imagePath) 171 + } 144 172 } 145 173 146 174 export function getImageDim(path: string): Promise<Dimensions> {
+1 -1
src/view/com/lightbox/Lightbox.tsx
··· 41 41 } 42 42 try { 43 43 await saveImageToMediaLibrary({uri}) 44 - Toast.show(_(msg`Saved to your camera roll`)) 44 + Toast.show(_(msg`Image saved`)) 45 45 } catch (e: any) { 46 46 Toast.show(_(msg`Failed to save image: ${String(e)}`), 'xmark') 47 47 }