chore: update dependencies and refactor config plugin imports (#993)

This commit is contained in:
Gauvain
2025-08-29 22:06:50 +02:00
committed by GitHub
parent f54da12fdb
commit a68d8500a6
35 changed files with 591 additions and 302 deletions

View File

@@ -1,50 +1,110 @@
import * as BackgroundTask from "expo-background-task";
import * as TaskManager from "expo-task-manager";
import { Platform } from "react-native";
import { writeErrorLog } from "@/utils/log";
const BackgroundFetch = !Platform.isTV
? require("expo-background-fetch")
: null;
const BackgroundTaskModule = !Platform.isTV ? BackgroundTask : null;
export const BACKGROUND_FETCH_TASK = "background-fetch";
export async function registerBackgroundFetchAsync() {
try {
BackgroundFetch.registerTaskAsync(BACKGROUND_FETCH_TASK, {
minimumInterval: 60 * 1, // 1 minutes
stopOnTerminate: false, // android only,
startOnBoot: false, // android only
});
} catch (error) {
console.log("Error registering background fetch task", error);
}
}
export async function unregisterBackgroundFetchAsync() {
try {
BackgroundFetch.unregisterTaskAsync(BACKGROUND_FETCH_TASK);
} catch (error) {
console.log("Error unregistering background fetch task", error);
}
}
export const BACKGROUND_FETCH_TASK_SESSIONS = "background-fetch-sessions";
export async function registerBackgroundFetchAsyncSessions() {
export async function registerBackgroundFetchAsync(): Promise<boolean> {
if (!BackgroundTaskModule) {
console.log(
"BackgroundTask module not available (TV platform or not supported)",
);
return false;
}
try {
console.log("Registering background fetch sessions");
BackgroundFetch.registerTaskAsync(BACKGROUND_FETCH_TASK_SESSIONS, {
minimumInterval: 1 * 60, // 1 minutes
stopOnTerminate: false, // android only,
startOnBoot: true, // android only
// Check if task is already registered
const isRegistered = await TaskManager.isTaskRegisteredAsync(
BACKGROUND_FETCH_TASK,
);
if (isRegistered) {
console.log("Background fetch task already registered");
return true;
}
await BackgroundTaskModule!.unregisterTaskAsync(BACKGROUND_FETCH_TASK);
const minimumInterval = Platform.OS === "android" ? 600 : 900;
await BackgroundTaskModule!.registerTaskAsync(BACKGROUND_FETCH_TASK, {
minimumInterval,
});
console.log("Successfully registered background fetch task");
return true;
} catch (error) {
console.log("Error registering background fetch task", error);
// Log error but don't throw - background fetch is not critical
console.warn("Failed to register background fetch task:", error);
writeErrorLog("Error registering background fetch task", error);
return false;
}
}
export async function unregisterBackgroundFetchAsyncSessions() {
export async function unregisterBackgroundFetchAsync(): Promise<boolean> {
if (!BackgroundTaskModule) return false;
try {
BackgroundFetch.unregisterTaskAsync(BACKGROUND_FETCH_TASK_SESSIONS);
await BackgroundTaskModule!.unregisterTaskAsync(BACKGROUND_FETCH_TASK);
console.log("Successfully unregistered background fetch task");
return true;
} catch (error) {
console.log("Error unregistering background fetch task", error);
// Log error but don't throw - unregistering is not critical
console.warn("Failed to unregister background fetch task:", error);
writeErrorLog("Error unregistering background fetch task", error);
return false;
}
}
export async function unregisterBackgroundFetchAsyncSessions(): Promise<boolean> {
if (!BackgroundTaskModule) return false;
try {
await BackgroundTaskModule!.unregisterTaskAsync(
BACKGROUND_FETCH_TASK_SESSIONS,
);
console.log("Successfully unregistered background fetch sessions task");
return true;
} catch (error) {
// Log error but don't throw - unregistering is not critical
console.warn("Failed to unregister background fetch sessions task:", error);
writeErrorLog("Error unregistering background fetch sessions task", error);
return false;
}
}
export async function registerBackgroundFetchAsyncSessions(): Promise<boolean> {
if (!BackgroundTaskModule) {
console.log(
"BackgroundTask module not available (TV platform or not supported)",
);
return false;
}
try {
// Check if task is already registered
const isRegistered = await TaskManager.isTaskRegisteredAsync(
BACKGROUND_FETCH_TASK_SESSIONS,
);
if (isRegistered) {
console.log("Background fetch sessions task already registered");
return true;
}
await BackgroundTaskModule!.unregisterTaskAsync(
BACKGROUND_FETCH_TASK_SESSIONS,
);
const minimumInterval = Platform.OS === "android" ? 600 : 900;
await BackgroundTaskModule!.registerTaskAsync(
BACKGROUND_FETCH_TASK_SESSIONS,
{
minimumInterval,
},
);
console.log("Successfully registered background fetch sessions task");
return true;
} catch (error) {
// Log error but don't throw - background fetch is not critical
console.warn("Failed to register background fetch sessions task:", error);
writeErrorLog("Error registering background fetch sessions task", error);
return false;
}
}