diff --git a/app/_layout.tsx b/app/_layout.tsx index 1a04ae9b..11bc63a6 100644 --- a/app/_layout.tsx +++ b/app/_layout.tsx @@ -36,12 +36,11 @@ const Notifications = !Platform.isTV ? require("expo-notifications") : null; import { getSessionApi } from "@jellyfin/sdk/lib/utils/api/session-api"; import { getLocales } from "expo-localization"; import type { EventSubscription } from "expo-modules-core"; -import { getDevicePushTokenAsync } from "expo-notifications"; import type { Notification, NotificationResponse, } from "expo-notifications/build/Notifications.types"; -import type { DevicePushToken } from "expo-notifications/build/Tokens.types"; +import type { ExpoPushToken } from "expo-notifications/build/Tokens.types"; import { router, Stack, useSegments } from "expo-router"; import * as SplashScreen from "expo-splash-screen"; import * as TaskManager from "expo-task-manager"; @@ -206,24 +205,24 @@ function Layout() { useNotificationObserver(); - const [pushToken, setPushToken] = useState(); + const [expoPushToken, setExpoPushToken] = useState(); const notificationListener = useRef(null); const responseListener = useRef(null); useEffect(() => { - if (!Platform.isTV && pushToken && api && user) { + if (!Platform.isTV && expoPushToken && api && user) { api ?.post("/Streamyfin/device", { - token: pushToken.data, + token: expoPushToken.data, deviceId: getOrSetDeviceId(), userId: user.Id, }) - .then((_) => console.log("Posted device push token")) + .then((_) => console.log("Posted expo push token")) .catch((_) => - writeErrorLog("Failed to push device push token to plugin"), + writeErrorLog("Failed to push expo push token to plugin"), ); } else console.log("No token available"); - }, [api, pushToken, user]); + }, [api, expoPushToken, user]); const registerNotifications = useCallback(async () => { if (Platform.OS === "android") { @@ -256,8 +255,8 @@ function Layout() { // only create push token for real devices (pointless for emulators) if (Device.isDevice) { - getDevicePushTokenAsync() - .then((token: DevicePushToken) => token && setPushToken(token)) + Notifications?.getExpoPushTokenAsync() + .then((token: ExpoPushToken) => token && setExpoPushToken(token)) .catch((reason: any) => console.log("Failed to get token", reason)); } }, [user]);