feat: disallow downloads on mobile data if disabled

This commit is contained in:
Adrian Castro
2024-04-04 20:12:46 +02:00
parent 05a09cc6cd
commit bf6bd7af2f
3 changed files with 61 additions and 544 deletions

View File

@@ -49,6 +49,7 @@
"expo-linking": "~6.2.2",
"expo-media-library": "~15.9.1",
"expo-navigation-bar": "^2.8.1",
"expo-network": "~5.8.0",
"expo-router": "~3.4.8",
"expo-screen-orientation": "~6.4.1",
"expo-splash-screen": "~0.26.4",

View File

@@ -4,6 +4,8 @@ import type { ReactNode } from "react";
import React, { createContext, useContext, useEffect, useState } from "react";
import * as FileSystem from "expo-file-system";
import * as MediaLibrary from "expo-media-library";
import * as Network from "expo-network";
import { NetworkStateType } from "expo-network";
import {
checkForExistingDownloads,
completeHandler,
@@ -16,7 +18,10 @@ import { useToastController } from "@tamagui/toast";
import type { ScrapeMedia } from "@movie-web/provider-utils";
import { extractSegmentsFromHLS } from "@movie-web/provider-utils";
import { useDownloadHistoryStore } from "~/stores/settings";
import {
useDownloadHistoryStore,
useNetworkSettingsStore,
} from "~/stores/settings";
export interface DownloadItem {
id: string;
@@ -138,6 +143,19 @@ export const DownloadManagerProvider: React.FC<{ children: ReactNode }> = ({
media: ScrapeMedia,
headers?: Record<string, string>,
): Promise<Asset | void> => {
const { allowMobileData } = useNetworkSettingsStore.getState();
const { type: networkType } = await Network.getNetworkStateAsync();
if (networkType === NetworkStateType.CELLULAR && !allowMobileData) {
toastController.show("Mobile data downloads are disabled", {
burntOptions: { preset: "error" },
native: true,
duration: 500,
});
return;
}
const { status } = await MediaLibrary.requestPermissionsAsync();
if (status !== MediaLibrary.PermissionStatus.GRANTED) {
toastController.show("Permission denied", {

584
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff