Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

androidNotifications.ts

53 lines1.7 KB

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;
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";
20​
21function appScheme(): string {
22 const scheme = Constants.expoConfig?.scheme;
23 return (Array.isArray(scheme) ? scheme[0] : scheme) ?? "t3code";
25​
26export function configureAndroidAgentNotifications(
27 deviceId: string,
28 userId: string,
29 ongoingEnabled: boolean,
30): void {
31 native?.configure?.(deviceId, userId, appScheme(), ongoingEnabled);
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;
40​
41export function clearAndroidAgentNotifications(): void {
42 native?.clear?.();
44​
45export function supportsAndroidLiveUpdateSettings(): boolean {
46 return Platform.OS === "android" && Number(Platform.Version) >= 36;
48​
49export async function openAndroidLiveUpdateSettings(): Promise<void> {
50 if (!native?.openLiveUpdateSettings?.()) {
51 await Linking.openSettings();
52 }