Update the downloader module

This commit is contained in:
Zoe Roux 2024-01-27 18:12:32 +01:00
parent 3ae167bd16
commit ae518cafe5
4 changed files with 17 additions and 19 deletions

View File

@ -18,7 +18,7 @@
"@formatjs/intl-displaynames": "^6.6.6",
"@formatjs/intl-locale": "^3.4.5",
"@gorhom/portal": "^1.0.14",
"@kesha-antonov/react-native-background-downloader": "^2.10.0",
"@kesha-antonov/react-native-background-downloader": "^3.0.1",
"@kyoo/ui": "workspace:^",
"@material-symbols/svg-400": "^0.14.6",
"@react-native-community/netinfo": "11.1.0",

View File

@ -33,7 +33,7 @@
"yoshiki": "*"
},
"optionalDependencies": {
"@kesha-antonov/react-native-background-downloader": "^2.10.0",
"@kesha-antonov/react-native-background-downloader": "^3.0.1",
"expo-file-system": "^16.0.5",
"expo-router": "^3.4.6"
},

View File

@ -88,9 +88,9 @@ const setupDownloadTask = (
if (!stateAtom) stateAtom = atom({} as State);
store.set(stateAtom, {
status: task.state,
progress: task.percent * 100,
size: task.totalBytes,
availableSize: task.bytesWritten,
progress: (task.bytesDownloaded / task.bytesTotal) * 100,
size: task.bytesTotal,
availableSize: task.bytesDownloaded,
pause: () => {
task.pause();
store.set(stateAtom!, (x) => ({ ...x, state: "PAUSED" }));
@ -126,22 +126,20 @@ const setupDownloadTask = (
task
.begin(({ expectedBytes }) => update((x) => ({ ...x, size: expectedBytes })))
.progress((percent, availableSize, size) => {
.progress(({ bytesDownloaded, bytesTotal }) => {
update((x) => ({
...x,
progress: Math.round(percent * 100),
size,
availableSize,
progress: Math.round((bytesDownloaded / bytesTotal) * 100),
size: bytesTotal,
availableSize: bytesDownloaded,
status: "DOWNLOADING",
}));
})
.done(() => {
update((x) => ({ ...x, progress: 100, status: "DONE", play: playFn(state, queryClient) }));
// apparently this is needed for ios /shrug i'm totaly gona forget this
// if i ever implement ios so keeping this here
if (Platform.OS === "ios") RNBackgroundDownloader.completeHandler(task.id);
RNBackgroundDownloader.completeHandler(task.id);
})
.error((error) => {
.error(({ error }) => {
update((x) => ({ ...x, status: "FAILED", error }));
console.error(`Error downloading ${state.data.slug}`, error);
ToastAndroid.show(`Error downloading ${state.data.slug}`, ToastAndroid.LONG);

View File

@ -2509,12 +2509,12 @@ __metadata:
languageName: node
linkType: hard
"@kesha-antonov/react-native-background-downloader@npm:^2.10.0":
version: 2.10.0
resolution: "@kesha-antonov/react-native-background-downloader@npm:2.10.0"
"@kesha-antonov/react-native-background-downloader@npm:^3.0.1":
version: 3.0.1
resolution: "@kesha-antonov/react-native-background-downloader@npm:3.0.1"
peerDependencies:
react-native: ">=0.57.0"
checksum: f56e4bf5f28b07d8b9e776ce3bdc6ed715ef3d9a95d3ec67b4852dc2992c51283550b5406106454557654a1c2503e920ec62d895aa6240aae97ba4f029df8a32
checksum: f369689009b74add987e667746bd80409646ad2ebb51f9a4831242b365e898975d89759b7effd4169156d74ff4cc89d84318f1ab5a854dcd72bcba91081ba3a0
languageName: node
linkType: hard
@ -2603,7 +2603,7 @@ __metadata:
resolution: "@kyoo/ui@workspace:packages/ui"
dependencies:
"@gorhom/portal": ^1.0.14
"@kesha-antonov/react-native-background-downloader": ^2.10.0
"@kesha-antonov/react-native-background-downloader": ^3.0.1
"@kyoo/models": "workspace:^"
"@kyoo/primitives": "workspace:^"
"@shopify/flash-list": ^1.6.3
@ -10409,7 +10409,7 @@ __metadata:
"@formatjs/intl-displaynames": ^6.6.6
"@formatjs/intl-locale": ^3.4.5
"@gorhom/portal": ^1.0.14
"@kesha-antonov/react-native-background-downloader": ^2.10.0
"@kesha-antonov/react-native-background-downloader": ^3.0.1
"@kyoo/ui": "workspace:^"
"@material-symbols/svg-400": ^0.14.6
"@react-native-community/netinfo": 11.1.0