refactor: migrate to expo-background-task (#3679)
This commit is contained in:
parent
e7f88b7788
commit
70474b9154
|
|
@ -144,6 +144,7 @@ export default ({ config }: ConfigContext): ExpoConfig => {
|
|||
enableBackgroundRemoteNotifications: true,
|
||||
},
|
||||
],
|
||||
"expo-background-task",
|
||||
],
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@
|
|||
"expo": "53.0.4",
|
||||
"expo-apple-authentication": "7.2.4",
|
||||
"expo-application": "6.1.4",
|
||||
"expo-background-fetch": "13.1.5",
|
||||
"expo-background-task": "0.2.6",
|
||||
"expo-blur": "14.1.4",
|
||||
"expo-build-properties": "0.14.6",
|
||||
"expo-clipboard": "7.1.4",
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import * as BackgroundFetch from "expo-background-fetch"
|
||||
import * as BackgroundTask from "expo-background-task"
|
||||
import * as TaskManager from "expo-task-manager"
|
||||
|
||||
import { getUISettings } from "../atoms/settings/ui"
|
||||
|
|
@ -7,28 +7,26 @@ import { whoami } from "../store/user/getters"
|
|||
|
||||
const BACKGROUND_FETCH_TASK = "background-fetch"
|
||||
|
||||
export async function initBackgroundFetch() {
|
||||
export async function initBackgroundTask() {
|
||||
TaskManager.defineTask(BACKGROUND_FETCH_TASK, async () => {
|
||||
// const now = Date.now()
|
||||
// console.log(`Got background fetch call at date: ${new Date(now).toISOString()}`)
|
||||
const user = whoami()
|
||||
const { showUnreadCountBadgeMobile } = getUISettings()
|
||||
if (!user || !showUnreadCountBadgeMobile) {
|
||||
return BackgroundFetch.BackgroundFetchResult.NoData
|
||||
return BackgroundTask.BackgroundTaskResult.Success
|
||||
}
|
||||
|
||||
try {
|
||||
const res = await unreadSyncService.updateBadgeAtBackground()
|
||||
return res
|
||||
? BackgroundFetch.BackgroundFetchResult.NewData
|
||||
: BackgroundFetch.BackgroundFetchResult.NoData
|
||||
await unreadSyncService.updateBadgeAtBackground()
|
||||
return BackgroundTask.BackgroundTaskResult.Success
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
return BackgroundFetch.BackgroundFetchResult.Failed
|
||||
return BackgroundTask.BackgroundTaskResult.Failed
|
||||
}
|
||||
})
|
||||
|
||||
return BackgroundFetch.registerTaskAsync(BACKGROUND_FETCH_TASK, {
|
||||
return BackgroundTask.registerTaskAsync(BACKGROUND_FETCH_TASK, {
|
||||
minimumInterval: 60 * 15, // 15 minutes
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import { initializeDb } from "../database"
|
|||
import { settingSyncQueue } from "../modules/settings/sync-queue"
|
||||
import { initAnalytics } from "./analytics"
|
||||
import { initializeAppCheck } from "./app-check"
|
||||
import { initBackgroundFetch } from "./background"
|
||||
import { initBackgroundTask } from "./background"
|
||||
import { initCrashlytics } from "./crashlytics"
|
||||
import { initializeDayjs } from "./dayjs"
|
||||
import { initDeviceType } from "./device"
|
||||
|
|
@ -50,7 +50,7 @@ export const initializeApp = async () => {
|
|||
using_indexed_db: true,
|
||||
})
|
||||
initCrashlytics()
|
||||
initBackgroundFetch()
|
||||
initBackgroundTask()
|
||||
console.log(`Initialize done,`, `${loadingTime}ms`)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -849,9 +849,9 @@ importers:
|
|||
expo-application:
|
||||
specifier: 6.1.4
|
||||
version: 6.1.4(expo@53.0.4(@babel/core@7.26.10)(@expo/metro-runtime@5.0.4(react-native@0.79.1(@babel/core@7.26.10)(@types/react@19.1.3)(bufferutil@4.0.9)(react@19.0.0)(utf-8-validate@6.0.5)))(bufferutil@4.0.9)(graphql@16.8.1)(react-native-webview@13.13.5(react-native@0.79.1(@babel/core@7.26.10)(@types/react@19.1.3)(bufferutil@4.0.9)(react@19.0.0)(utf-8-validate@6.0.5))(react@19.0.0))(react-native@0.79.1(@babel/core@7.26.10)(@types/react@19.1.3)(bufferutil@4.0.9)(react@19.0.0)(utf-8-validate@6.0.5))(react@19.0.0)(utf-8-validate@6.0.5))
|
||||
expo-background-fetch:
|
||||
specifier: 13.1.5
|
||||
version: 13.1.5(expo@53.0.4(@babel/core@7.26.10)(@expo/metro-runtime@5.0.4(react-native@0.79.1(@babel/core@7.26.10)(@types/react@19.1.3)(bufferutil@4.0.9)(react@19.0.0)(utf-8-validate@6.0.5)))(bufferutil@4.0.9)(graphql@16.8.1)(react-native-webview@13.13.5(react-native@0.79.1(@babel/core@7.26.10)(@types/react@19.1.3)(bufferutil@4.0.9)(react@19.0.0)(utf-8-validate@6.0.5))(react@19.0.0))(react-native@0.79.1(@babel/core@7.26.10)(@types/react@19.1.3)(bufferutil@4.0.9)(react@19.0.0)(utf-8-validate@6.0.5))(react@19.0.0)(utf-8-validate@6.0.5))(react-native@0.79.1(@babel/core@7.26.10)(@types/react@19.1.3)(bufferutil@4.0.9)(react@19.0.0)(utf-8-validate@6.0.5))
|
||||
expo-background-task:
|
||||
specifier: 0.2.6
|
||||
version: 0.2.6(expo@53.0.4(@babel/core@7.26.10)(@expo/metro-runtime@5.0.4(react-native@0.79.1(@babel/core@7.26.10)(@types/react@19.1.3)(bufferutil@4.0.9)(react@19.0.0)(utf-8-validate@6.0.5)))(bufferutil@4.0.9)(graphql@16.8.1)(react-native-webview@13.13.5(react-native@0.79.1(@babel/core@7.26.10)(@types/react@19.1.3)(bufferutil@4.0.9)(react@19.0.0)(utf-8-validate@6.0.5))(react@19.0.0))(react-native@0.79.1(@babel/core@7.26.10)(@types/react@19.1.3)(bufferutil@4.0.9)(react@19.0.0)(utf-8-validate@6.0.5))(react@19.0.0)(utf-8-validate@6.0.5))(react-native@0.79.1(@babel/core@7.26.10)(@types/react@19.1.3)(bufferutil@4.0.9)(react@19.0.0)(utf-8-validate@6.0.5))
|
||||
expo-blur:
|
||||
specifier: 14.1.4
|
||||
version: 14.1.4(expo@53.0.4(@babel/core@7.26.10)(@expo/metro-runtime@5.0.4(react-native@0.79.1(@babel/core@7.26.10)(@types/react@19.1.3)(bufferutil@4.0.9)(react@19.0.0)(utf-8-validate@6.0.5)))(bufferutil@4.0.9)(graphql@16.8.1)(react-native-webview@13.13.5(react-native@0.79.1(@babel/core@7.26.10)(@types/react@19.1.3)(bufferutil@4.0.9)(react@19.0.0)(utf-8-validate@6.0.5))(react@19.0.0))(react-native@0.79.1(@babel/core@7.26.10)(@types/react@19.1.3)(bufferutil@4.0.9)(react@19.0.0)(utf-8-validate@6.0.5))(react@19.0.0)(utf-8-validate@6.0.5))(react-native@0.79.1(@babel/core@7.26.10)(@types/react@19.1.3)(bufferutil@4.0.9)(react@19.0.0)(utf-8-validate@6.0.5))(react@19.0.0)
|
||||
|
|
@ -9209,8 +9209,8 @@ packages:
|
|||
react: 19.0.0
|
||||
react-native: '*'
|
||||
|
||||
expo-background-fetch@13.1.5:
|
||||
resolution: {integrity: sha512-tQiQEH68o6iduDDOKdlTx7oa1cWf8d+RsT4vm2dFzoSEIr1gJtdNojN4U2qBxwTGYttJI1ug5/PYKpQUIS5VmA==}
|
||||
expo-background-task@0.2.6:
|
||||
resolution: {integrity: sha512-ZP7qurzAaOisfZRGIDnrAncVYynPQcLZqmWoaCeuBQNtHTUc5prnp7iRWRZo/OccPEiXuZNyZSJ/VMtw83Cfzw==}
|
||||
peerDependencies:
|
||||
expo: '*'
|
||||
|
||||
|
|
@ -24979,7 +24979,7 @@ snapshots:
|
|||
transitivePeerDependencies:
|
||||
- supports-color
|
||||
|
||||
expo-background-fetch@13.1.5(expo@53.0.4(@babel/core@7.26.10)(@expo/metro-runtime@5.0.4(react-native@0.79.1(@babel/core@7.26.10)(@types/react@19.1.3)(bufferutil@4.0.9)(react@19.0.0)(utf-8-validate@6.0.5)))(bufferutil@4.0.9)(graphql@16.8.1)(react-native-webview@13.13.5(react-native@0.79.1(@babel/core@7.26.10)(@types/react@19.1.3)(bufferutil@4.0.9)(react@19.0.0)(utf-8-validate@6.0.5))(react@19.0.0))(react-native@0.79.1(@babel/core@7.26.10)(@types/react@19.1.3)(bufferutil@4.0.9)(react@19.0.0)(utf-8-validate@6.0.5))(react@19.0.0)(utf-8-validate@6.0.5))(react-native@0.79.1(@babel/core@7.26.10)(@types/react@19.1.3)(bufferutil@4.0.9)(react@19.0.0)(utf-8-validate@6.0.5)):
|
||||
expo-background-task@0.2.6(expo@53.0.4(@babel/core@7.26.10)(@expo/metro-runtime@5.0.4(react-native@0.79.1(@babel/core@7.26.10)(@types/react@19.1.3)(bufferutil@4.0.9)(react@19.0.0)(utf-8-validate@6.0.5)))(bufferutil@4.0.9)(graphql@16.8.1)(react-native-webview@13.13.5(react-native@0.79.1(@babel/core@7.26.10)(@types/react@19.1.3)(bufferutil@4.0.9)(react@19.0.0)(utf-8-validate@6.0.5))(react@19.0.0))(react-native@0.79.1(@babel/core@7.26.10)(@types/react@19.1.3)(bufferutil@4.0.9)(react@19.0.0)(utf-8-validate@6.0.5))(react@19.0.0)(utf-8-validate@6.0.5))(react-native@0.79.1(@babel/core@7.26.10)(@types/react@19.1.3)(bufferutil@4.0.9)(react@19.0.0)(utf-8-validate@6.0.5)):
|
||||
dependencies:
|
||||
expo: 53.0.4(@babel/core@7.26.10)(@expo/metro-runtime@5.0.4(react-native@0.79.1(@babel/core@7.26.10)(@types/react@19.1.3)(bufferutil@4.0.9)(react@19.0.0)(utf-8-validate@6.0.5)))(bufferutil@4.0.9)(graphql@16.8.1)(react-native-webview@13.13.5(react-native@0.79.1(@babel/core@7.26.10)(@types/react@19.1.3)(bufferutil@4.0.9)(react@19.0.0)(utf-8-validate@6.0.5))(react@19.0.0))(react-native@0.79.1(@babel/core@7.26.10)(@types/react@19.1.3)(bufferutil@4.0.9)(react@19.0.0)(utf-8-validate@6.0.5))(react@19.0.0)(utf-8-validate@6.0.5)
|
||||
expo-task-manager: 13.1.5(expo@53.0.4(@babel/core@7.26.10)(@expo/metro-runtime@5.0.4(react-native@0.79.1(@babel/core@7.26.10)(@types/react@19.1.3)(bufferutil@4.0.9)(react@19.0.0)(utf-8-validate@6.0.5)))(bufferutil@4.0.9)(graphql@16.8.1)(react-native-webview@13.13.5(react-native@0.79.1(@babel/core@7.26.10)(@types/react@19.1.3)(bufferutil@4.0.9)(react@19.0.0)(utf-8-validate@6.0.5))(react@19.0.0))(react-native@0.79.1(@babel/core@7.26.10)(@types/react@19.1.3)(bufferutil@4.0.9)(react@19.0.0)(utf-8-validate@6.0.5))(react@19.0.0)(utf-8-validate@6.0.5))(react-native@0.79.1(@babel/core@7.26.10)(@types/react@19.1.3)(bufferutil@4.0.9)(react@19.0.0)(utf-8-validate@6.0.5))
|
||||
|
|
|
|||
Loading…
Reference in New Issue