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

androidNotifications.ts

46 lines1.3 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}
10​
11const native =
12 Platform.OS === "android"
13 ? requireOptionalNativeModule<AndroidAgentNotifications>("T3AgentNotifications")
14 : null;
15​
16export function supportsAndroidAgentNotifications(): boolean {
17 return typeof native?.configure === "function" && typeof native?.clear === "function";
19​
20export function configureAndroidAgentNotifications(
21 deviceId: string,
22 userId: string,
23 ongoingEnabled: boolean,
24): void {
25 const scheme = Constants.expoConfig?.scheme;
26 native?.configure?.(
27 deviceId,
28 userId,
29 (Array.isArray(scheme) ? scheme[0] : scheme) ?? "t3code",
30 ongoingEnabled,
31 );
33​
34export function clearAndroidAgentNotifications(): void {
35 native?.clear?.();
37​
38export function supportsAndroidLiveUpdateSettings(): boolean {
39 return Platform.OS === "android" && Number(Platform.Version) >= 36;
41​
42export async function openAndroidLiveUpdateSettings(): Promise<void> {
43 if (!native?.openLiveUpdateSettings?.()) {
44 await Linking.openSettings();
45 }