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

main
ts 57 lines 1.75 KB
Raw
1 import Constants from "expo-constants";
2 import { requireOptionalNativeModule } from "expo";
3 import { Linking, Platform } from "react-native";
4
5 interface AndroidAgentNotifications {
6 configure(deviceId: string, userId: string, scheme: string, ongoingEnabled: boolean): void;
7 clear(): void;
8 setThreadOnScreen?(path: string | null): void;
9 openLiveUpdateSettings?(): boolean;
10 showShowcaseActivity?(scheme: string, data: Record<string, string>): void;
11 }
12
13 const native =
14 Platform.OS === "android"
15 ? requireOptionalNativeModule<AndroidAgentNotifications>("T3AgentNotifications")
16 : null;
17
18 export function supportsAndroidAgentNotifications(): boolean {
19 return typeof native?.configure === "function" && typeof native?.clear === "function";
20 }
21
22 function appScheme(): string {
23 const scheme = Constants.expoConfig?.scheme;
24 return (Array.isArray(scheme) ? scheme[0] : scheme) ?? "t3code";
25 }
26
27 export function configureAndroidAgentNotifications(
28 deviceId: string,
29 userId: string,
30 ongoingEnabled: boolean,
31 ): void {
32 native?.configure?.(deviceId, userId, appScheme(), ongoingEnabled);
33 }
34
35 export function showAndroidShowcaseAgentActivity(data: Record<string, string>): boolean {
36 if (!native?.showShowcaseActivity) return false;
37 native.showShowcaseActivity(appScheme(), data);
38 return true;
39 }
40
41 export function clearAndroidAgentNotifications(): void {
42 native?.clear?.();
43 }
44
45 export function setAndroidThreadOnScreen(path: string | null): void {
46 native?.setThreadOnScreen?.(path);
47 }
48
49 export function supportsAndroidLiveUpdateSettings(): boolean {
50 return Platform.OS === "android" && Number(Platform.Version) >= 36;
51 }
52
53 export async function openAndroidLiveUpdateSettings(): Promise<void> {
54 if (!native?.openLiveUpdateSettings?.()) {
55 await Linking.openSettings();
56 }
57 }