forked from Ninjalama/streamyfin_mirror
chore
This commit is contained in:
3
app.json
3
app.json
@@ -138,7 +138,8 @@
|
||||
{
|
||||
"useDefaultExpandedMediaControls": true
|
||||
}
|
||||
]
|
||||
],
|
||||
"expo-background-task"
|
||||
],
|
||||
"experiments": {
|
||||
"typedRoutes": true
|
||||
|
||||
@@ -36,10 +36,6 @@ const BackGroundDownloader = !Platform.isTV
|
||||
import { DarkTheme, ThemeProvider } from "@react-navigation/native";
|
||||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
||||
|
||||
const BackgroundFetch = !Platform.isTV
|
||||
? require("expo-background-fetch")
|
||||
: null;
|
||||
|
||||
import * as Device from "expo-device";
|
||||
import * as FileSystem from "expo-file-system";
|
||||
|
||||
@@ -49,7 +45,7 @@ import { router, Stack, useSegments } from "expo-router";
|
||||
import * as SplashScreen from "expo-splash-screen";
|
||||
import * as ScreenOrientation from "@/packages/expo-screen-orientation";
|
||||
|
||||
const TaskManager = !Platform.isTV ? require("expo-task-manager") : null;
|
||||
import * as TaskManager from "expo-task-manager";
|
||||
|
||||
import { getLocales } from "expo-localization";
|
||||
import { Provider as JotaiProvider } from "jotai";
|
||||
@@ -130,7 +126,9 @@ if (!Platform.isTV) {
|
||||
console.log("TaskManager ~ sessions trigger");
|
||||
|
||||
const api = store.get(apiAtom);
|
||||
if (api === null || api === undefined) return;
|
||||
if (api === null || api === undefined) {
|
||||
return { value: null };
|
||||
}
|
||||
|
||||
const response = await getSessionApi(api).getSessions({
|
||||
activeWithinSeconds: 360,
|
||||
@@ -139,7 +137,7 @@ if (!Platform.isTV) {
|
||||
const result = response.data.filter((s) => s.NowPlayingItem);
|
||||
Notifications.setBadgeCountAsync(result.length);
|
||||
|
||||
return BackgroundFetch.BackgroundFetchResult.NewData;
|
||||
return { value: "success" };
|
||||
});
|
||||
|
||||
TaskManager.defineTask(BACKGROUND_FETCH_TASK, async () => {
|
||||
@@ -149,20 +147,18 @@ if (!Platform.isTV) {
|
||||
|
||||
const settingsData = storage.getString("settings");
|
||||
|
||||
if (!settingsData) return BackgroundFetch.BackgroundFetchResult.NoData;
|
||||
if (!settingsData) return { value: null };
|
||||
|
||||
const settings: Partial<Settings> = JSON.parse(settingsData);
|
||||
const url = settings?.optimizedVersionsServerUrl;
|
||||
|
||||
if (!settings?.autoDownload || !url)
|
||||
return BackgroundFetch.BackgroundFetchResult.NoData;
|
||||
if (!settings?.autoDownload || !url) return { value: null };
|
||||
|
||||
const token = getTokenFromStorage();
|
||||
const deviceId = getOrSetDeviceId();
|
||||
const baseDirectory = FileSystem.documentDirectory;
|
||||
|
||||
if (!token || !deviceId || !baseDirectory)
|
||||
return BackgroundFetch.BackgroundFetchResult.NoData;
|
||||
if (!token || !deviceId || !baseDirectory) return { value: null };
|
||||
|
||||
const jobs = await getAllJobsByDeviceId({
|
||||
deviceId,
|
||||
@@ -195,7 +191,7 @@ if (!Platform.isTV) {
|
||||
})
|
||||
.done(() => {
|
||||
console.log("TaskManager ~ Download completed: ", job.id);
|
||||
saveDownloadedItemInfo(job.item);
|
||||
_saveDownloadedItemInfo(job.item);
|
||||
BackGroundDownloader.completeHandler(job.id);
|
||||
cancelJobById({
|
||||
authHeader: token,
|
||||
@@ -233,7 +229,7 @@ if (!Platform.isTV) {
|
||||
console.log(`Auto download started: ${new Date(now).toISOString()}`);
|
||||
|
||||
// Be sure to return the successful result type!
|
||||
return BackgroundFetch.BackgroundFetchResult.NewData;
|
||||
return { value: "success" };
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -20,8 +20,7 @@ import { Text } from "../common/Text";
|
||||
import { ListGroup } from "../list/ListGroup";
|
||||
import { ListItem } from "../list/ListItem";
|
||||
|
||||
const BackgroundFetch = require("expo-background-fetch");
|
||||
const TaskManager = require("expo-task-manager");
|
||||
import * as TaskManager from "expo-task-manager";
|
||||
|
||||
export const OtherSettings: React.FC = () => {
|
||||
const router = useRouter();
|
||||
@@ -33,7 +32,8 @@ export const OtherSettings: React.FC = () => {
|
||||
* Background task
|
||||
*******************/
|
||||
const checkStatusAsync = async () => {
|
||||
await BackgroundFetch.getStatusAsync();
|
||||
// expo-background-task doesn't have a direct status check
|
||||
// Just check if the task is registered
|
||||
return await TaskManager.isTaskRegisteredAsync(BACKGROUND_FETCH_TASK);
|
||||
};
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
"axios": "^1.7.9",
|
||||
"expo": "~53.0.17",
|
||||
"expo-asset": "~11.1.7",
|
||||
"expo-background-fetch": "~13.1.6",
|
||||
"expo-background-task": "~0.2.8",
|
||||
"expo-blur": "~14.1.5",
|
||||
"expo-brightness": "~13.1.4",
|
||||
"expo-build-properties": "~0.14.8",
|
||||
|
||||
@@ -1,46 +1,41 @@
|
||||
const BackgroundFetch = require("expo-background-fetch");
|
||||
import * as BackgroundTask from "expo-background-task";
|
||||
|
||||
export const BACKGROUND_FETCH_TASK = "background-fetch";
|
||||
export const BACKGROUND_FETCH_TASK_SESSIONS = "background-fetch-sessions";
|
||||
|
||||
export async function registerBackgroundFetchAsync() {
|
||||
try {
|
||||
BackgroundFetch.registerTaskAsync(BACKGROUND_FETCH_TASK, {
|
||||
minimumInterval: 60 * 1, // 1 minutes
|
||||
stopOnTerminate: false, // android only,
|
||||
startOnBoot: false, // android only
|
||||
await BackgroundTask.registerTaskAsync(BACKGROUND_FETCH_TASK, {
|
||||
minimumInterval: 60, // 1 minute (in seconds, not milliseconds)
|
||||
});
|
||||
} catch (error) {
|
||||
console.log("Error registering background fetch task", error);
|
||||
console.log("Error registering background task", error);
|
||||
}
|
||||
}
|
||||
|
||||
export async function unregisterBackgroundFetchAsync() {
|
||||
try {
|
||||
BackgroundFetch.unregisterTaskAsync(BACKGROUND_FETCH_TASK);
|
||||
await BackgroundTask.unregisterTaskAsync(BACKGROUND_FETCH_TASK);
|
||||
} catch (error) {
|
||||
console.log("Error unregistering background fetch task", error);
|
||||
console.log("Error unregistering background task", error);
|
||||
}
|
||||
}
|
||||
|
||||
export const BACKGROUND_FETCH_TASK_SESSIONS = "background-fetch-sessions";
|
||||
|
||||
export async function registerBackgroundFetchAsyncSessions() {
|
||||
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
|
||||
console.log("Registering background task sessions");
|
||||
await BackgroundTask.registerTaskAsync(BACKGROUND_FETCH_TASK_SESSIONS, {
|
||||
minimumInterval: 60, // 1 minute
|
||||
});
|
||||
} catch (error) {
|
||||
console.log("Error registering background fetch task", error);
|
||||
console.log("Error registering background task sessions", error);
|
||||
}
|
||||
}
|
||||
|
||||
export async function unregisterBackgroundFetchAsyncSessions() {
|
||||
try {
|
||||
BackgroundFetch.unregisterTaskAsync(BACKGROUND_FETCH_TASK_SESSIONS);
|
||||
await BackgroundTask.unregisterTaskAsync(BACKGROUND_FETCH_TASK_SESSIONS);
|
||||
} catch (error) {
|
||||
console.log("Error unregistering background fetch task", error);
|
||||
console.log("Error unregistering background task sessions", error);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user