Files
sofa/apps/native/modules/sofa-widgets-support/index.ts
T
jake 34b9ae3620 fix(native): fix widget image management and add tests
- Fix `copyBundledAsset` to accept a URI instead of a named bundle asset, resolving via `resolveAssetURL` with support for remote downloads
- Read app group identifier from Info.plist (`ExpoWidgetsAppGroupIdentifier`) instead of a hardcoded string
- Add `pruneWidgetImages(maxAgeSeconds)` to age-based cache cleanup, skipping the widget icon file
- Add `normalizedFileName` helper to sanitize cache keys and a `log` helper with consistent prefix
- Extract `getWidgetIconAsset()` into `widget-assets.ts` so the asset require is testable in isolation
- Add Vitest config for the native app and unit tests covering widget data-fetch, image download, and prune logic
2026-03-24 11:13:09 -04:00

26 lines
829 B
TypeScript

import { Platform } from "react-native";
function getModule() {
return require("./src/SofaWidgetsSupportModule").default;
}
export async function downloadWidgetImage(url: string, key: string): Promise<string | null> {
if (Platform.OS !== "ios") return null;
return getModule().downloadWidgetImage(url, key);
}
export async function copyBundledAsset(assetUri: string, key: string): Promise<string | null> {
if (Platform.OS !== "ios") return null;
return getModule().copyBundledAsset(assetUri, key);
}
export async function clearWidgetImages(): Promise<void> {
if (Platform.OS !== "ios") return;
return getModule().clearWidgetImages();
}
export async function pruneWidgetImages(maxAgeSeconds: number): Promise<void> {
if (Platform.OS !== "ios") return;
return getModule().pruneWidgetImages(maxAgeSeconds);
}