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