This commit is contained in:
sarendsen
2025-01-06 13:25:49 +01:00
parent 6a4621c377
commit ab33693dd9
59 changed files with 474 additions and 303 deletions

View File

@@ -13,12 +13,15 @@ import {
BaseItemDto,
MediaSourceInfo,
} from "@jellyfin/sdk/lib/generated-client/models";
import {
checkForExistingDownloads,
completeHandler,
download,
setConfig,
} from "@kesha-antonov/react-native-background-downloader";
// import {
// checkForExistingDownloads,
// completeHandler,
// download,
// setConfig,
// } from "@kesha-antonov/react-native-background-downloader";
const BackGroundDownloader = !Platform.isTV
? require("@kesha-antonov/react-native-background-downloader")
: null;
import MMKV from "react-native-mmkv";
import {
focusManager,
@@ -42,13 +45,14 @@ import React, {
import { AppState, AppStateStatus, Platform } from "react-native";
import { toast } from "sonner-native";
import { apiAtom } from "./JellyfinProvider";
import * as Notifications from "expo-notifications";
// import * as Notifications from "expo-notifications";
const Notifications = !Platform.isTV ? require("expo-notifications") : null;
import { getItemImage } from "@/utils/getItemImage";
import useImageStorage from "@/hooks/useImageStorage";
import { storage } from "@/utils/mmkv";
import useDownloadHelper from "@/utils/download";
import { FileInfo } from "expo-file-system";
import * as Haptics from "expo-haptics";
import * as Haptics from "@/packages/expo-haptics";
import * as Application from "expo-application";
export type DownloadedItem = {
@@ -67,6 +71,7 @@ const DownloadContext = createContext<ReturnType<
> | null>(null);
function useDownloadProvider() {
if (Platform.isTV) return;
const queryClient = useQueryClient();
const [settings] = useSettings();
const router = useRouter();
@@ -170,7 +175,7 @@ function useDownloadProvider() {
useEffect(() => {
const checkIfShouldStartDownload = async () => {
if (processes.length === 0) return;
await checkForExistingDownloads();
await BackGroundDownloader.checkForExistingDownloads();
};
checkIfShouldStartDownload();
@@ -214,7 +219,7 @@ function useDownloadProvider() {
)
);
setConfig({
BackGroundDownloader.setConfig({
isLogsEnabled: true,
progressInterval: 500,
headers: {
@@ -234,7 +239,7 @@ function useDownloadProvider() {
const baseDirectory = FileSystem.documentDirectory;
download({
BackGroundDownloader.download({
id: process.id,
url: settings?.optimizedVersionsServerUrl + "download/" + process.id,
destination: `${baseDirectory}/${process.item.Id}.mp4`,
@@ -284,7 +289,7 @@ function useDownloadProvider() {
},
});
setTimeout(() => {
completeHandler(process.id);
BackGroundDownloader.completeHandler(process.id);
removeProcess(process.id);
}, 1000);
})