From bcf72ee04d635bcd5a21dfeaaeda0767b4c6d93c Mon Sep 17 00:00:00 2001 From: tranxuanthang Date: Mon, 23 Dec 2024 00:59:28 +0700 Subject: [PATCH] Downloader improvement and fixes --- src/App.vue | 3 ++ src/components/library/DownloadViewer.vue | 14 ++++--- .../library/track-list/TrackItem.vue | 25 ++++++------ src/composables/downloader.js | 38 ++++++++++++------- src/style.css | 4 +- 5 files changed, 51 insertions(+), 33 deletions(-) diff --git a/src/App.vue b/src/App.vue index 1c8898a..25a78da 100644 --- a/src/App.vue +++ b/src/App.vue @@ -23,8 +23,10 @@ import { appWindow } from '@tauri-apps/api/window' import { invoke } from '@tauri-apps/api/tauri' import { ModalsContainer } from 'vue-final-modal' import { useGlobalState } from './composables/global-state' +import { useDownloader } from '@/composables/downloader.js' const { themeMode, setThemeMode } = useGlobalState() +const { downloadNext } = useDownloader() const loading = ref(true) const init = ref(false) @@ -41,6 +43,7 @@ onMounted(async () => { init.value = await invoke('get_init') loading.value = false darkModeHandle() + downloadNext() }) const darkModeHandle = async () => { diff --git a/src/components/library/DownloadViewer.vue b/src/components/library/DownloadViewer.vue index 93d2413..7c0091b 100644 --- a/src/components/library/DownloadViewer.vue +++ b/src/components/library/DownloadViewer.vue @@ -4,7 +4,7 @@ @close="checkAndClose" content-class="w-full h-[80vh] max-w-screen-md" body-class="flex flex-col h-full min-h-0 justify-between gap-6" - :title="downloadedCount === totalCount ? 'Downloaded' : 'Downloading'" + :title="isFinished ? 'Downloaded' : 'Downloading'" >
@@ -29,7 +29,7 @@ @@ -59,11 +59,15 @@ const progressWidth = computed(() => { return '100%' } + if (downloadProgress.value > 1.0) { + return '100%' + } + return `${downloadProgress.value * 100}%` }) -const finishable = computed(() => { - return downloadedCount.value === totalCount.value +const isFinished = computed(() => { + return downloadedCount.value >= totalCount.value }) const handleStop = () => { @@ -72,7 +76,7 @@ const handleStop = () => { } const checkAndClose = () => { - if (finishable.value) { + if (isFinished.value) { startOver() emit('close') } else { diff --git a/src/components/library/track-list/TrackItem.vue b/src/components/library/track-list/TrackItem.vue index f1a7f56..0c7589f 100644 --- a/src/components/library/track-list/TrackItem.vue +++ b/src/components/library/track-list/TrackItem.vue @@ -1,15 +1,16 @@