Open History to see the last commit
1import Constants from "expo-constants";
2import { requireOptionalNativeModule } from "expo";
3import { Linking, Platform } from "react-native";
4
5interface AndroidAgentNotifications {
6 configure(deviceId: string, userId: string, scheme: string, ongoingEnabled: boolean): void;
7 clear(): void;
8 openLiveUpdateSettings?(): boolean;
9 showShowcaseActivity?(scheme: string, data: Record<string, string>): void;
10}
11
12const native =
13 Platform.OS === "android"
14 ? requireOptionalNativeModule<AndroidAgentNotifications>("T3AgentNotifications")
15 : null;
16
17export function supportsAndroidAgentNotifications(): boolean {
18 return typeof native?.configure === "function" && typeof native?.clear === "function";
19}
20
21function appScheme(): string {
22 const scheme = Constants.expoConfig?.scheme;
23 return (Array.isArray(scheme) ? scheme[0] : scheme) ?? "t3code";
24}
25
26export function configureAndroidAgentNotifications(
27 deviceId: string,
28 userId: string,
29 ongoingEnabled: boolean,
30): void {
31 native?.configure?.(deviceId, userId, appScheme(), ongoingEnabled);
32}
33
34/** Posts a staged relay payload for the showcase capture; false when unsupported. */
35export function showAndroidShowcaseAgentActivity(data: Record<string, string>): boolean {
36 if (!native?.showShowcaseActivity) return false;
37 native.showShowcaseActivity(appScheme(), data);
38 return true;
39}
40
41export function clearAndroidAgentNotifications(): void {
42 native?.clear?.();
43}
44
45export function supportsAndroidLiveUpdateSettings(): boolean {
46 return Platform.OS === "android" && Number(Platform.Version) >= 36;
47}
48
49export async function openAndroidLiveUpdateSettings(): Promise<void> {
50 if (!native?.openLiveUpdateSettings?.()) {
51 await Linking.openSettings();
52 }
53}