fix: task not registered properly

This commit is contained in:
Fredrik Burmester
2025-02-20 20:34:02 +01:00
parent 82ced0f101
commit 8fe0089131

View File

@@ -294,6 +294,32 @@ function Layout() {
checkAndRequestPermissions();
}, []);
const checkStatusAsync = async () => {
if (Platform.isTV) return;
await BackgroundFetch.getStatusAsync();
return await TaskManager.isTaskRegisteredAsync(
BACKGROUND_FETCH_TASK_RECENTLY_ADDED
);
};
useEffect(() => {
(async () => {
const isRegistered = await checkStatusAsync();
if (settings.recentlyAddedNotifications === false && isRegistered) {
console.log("unregisterBackgroundFetchAsyncRecentlyAdded");
unregisterBackgroundFetchAsyncRecentlyAdded();
} else if (
settings.recentlyAddedNotifications === true &&
!isRegistered
) {
console.log("registerBackgroundFetchAsyncRecentlyAdded");
registerBackgroundFetchAsyncRecentlyAdded();
}
})();
}, [settings.recentlyAddedNotifications]);
useEffect(() => {
// If the user has auto rotate enabled, unlock the orientation
if (settings.autoRotate === true) {
@@ -304,12 +330,6 @@ function Layout() {
ScreenOrientation.OrientationLock.PORTRAIT_UP
);
}
if (settings.recentlyAddedNotifications === true) {
registerBackgroundFetchAsyncRecentlyAdded();
} else {
unregisterBackgroundFetchAsyncRecentlyAdded();
}
}, [settings]);
useEffect(() => {