fix: go back to expo tokens

This commit is contained in:
Fredrik Burmester
2025-11-11 10:56:50 +01:00
parent 222ba13529
commit 5765793d79

View File

@@ -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<DevicePushToken>();
const [expoPushToken, setExpoPushToken] = useState<ExpoPushToken>();
const notificationListener = useRef<EventSubscription>(null);
const responseListener = useRef<EventSubscription>(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]);