@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
ts 23 lines 965 Bytes
Raw
1 import { requireNativeModule } from "expo";
2 import { Platform } from "react-native";
3
4 const SAVABLE_IMAGE_MIME_TYPE = /^image\/(png|jpe?g|gif|webp|heic|heif)$/i;
5
6 function baseMimeType(mimeType: string): string {
7 return mimeType.split(";", 1)[0]?.trim() ?? "";
8 }
9
10 // Android 9 and older need a storage permission to add photos, so they keep the share sheet.
11 export function canSaveImageToLibrary(mimeType: string): boolean {
12 return (
13 SAVABLE_IMAGE_MIME_TYPE.test(baseMimeType(mimeType)) &&
14 (Platform.OS === "ios" || (Platform.OS === "android" && Platform.Version >= 29))
15 );
16 }
17
18 /** Adds a local image file to Photos on iOS or Pictures/T3 Code on Android. */
19 export function saveImageToLibrary(uri: string, mimeType: string, name: string): Promise<void> {
20 return requireNativeModule<{
21 saveImageToLibrary(uri: string, mimeType: string, name: string): Promise<void>;
22 }>("T3NativeControls").saveImageToLibrary(uri, baseMimeType(mimeType), name);
23 }