Line data Source code
1 : <template>
2 0 : <div class="flex flex-col">
3 : <div :id="labelId">
4 : {{ getDownloadLabel(download.savePath ?? '') }}
5 : </div>
6 : <div v-if="['cancelled', 'error'].includes(download.status ?? '')">
7 : <Badge
8 : :remove-label="$t('g.remove')"
9 : variant="chip"
10 : severity="danger"
11 : class="mt-2 h-6 font-light"
12 : removable
13 : @remove="handleRemoveDownload"
14 : >
15 : {{ t('electronFileDownload.cancelled') }}
16 : </Badge>
17 : </div>
18 : <div
19 : v-if="
20 : ['in_progress', 'paused', 'completed'].includes(download.status ?? '')
21 : "
22 : class="mt-2 flex items-center gap-2"
23 : >
24 : <div
25 : role="progressbar"
26 : :aria-labelledby="labelId"
27 : :aria-valuenow="downloadProgressPercent"
28 : aria-valuemin="0"
29 : aria-valuemax="100"
30 : class="flex-1"
31 : >
32 : <div class="h-5 overflow-hidden rounded-full bg-secondary">
33 : <div
34 : class="h-full bg-primary transition-[width]"
35 : :style="{ width: `${downloadProgressPercent}%` }"
36 : />
37 : </div>
38 : <span v-if="(download.progress ?? 0) > 0.1" class="text-xs">
39 : {{ downloadProgressPercent }}%
40 : </span>
41 : </div>
42 :
43 : <Button
44 : v-if="download.status === 'in_progress'"
45 : :tooltip="t('electronFileDownload.pause')"
46 : class="size-[22px] rounded-full"
47 : variant="secondary"
48 : size="icon-sm"
49 : :aria-label="t('electronFileDownload.pause')"
50 : @click="triggerPauseDownload"
51 : >
52 : <i class="icon-[lucide--pause] size-3" />
53 : </Button>
54 :
55 : <Button
56 : v-if="download.status === 'paused'"
57 : :tooltip="t('electronFileDownload.resume')"
58 : class="size-[22px] rounded-full"
59 : variant="secondary"
60 : size="icon-sm"
61 : :aria-label="t('electronFileDownload.resume')"
62 : @click="triggerResumeDownload"
63 : >
64 : <i class="icon-[lucide--play] size-3" />
65 : </Button>
66 :
67 : <Button
68 : v-if="['in_progress', 'paused'].includes(download.status ?? '')"
69 : :tooltip="t('electronFileDownload.cancel')"
70 : class="size-[22px] rounded-full"
71 : variant="destructive"
72 : size="icon-sm"
73 : :aria-label="t('electronFileDownload.cancel')"
74 : @click="triggerCancelDownload"
75 : >
76 : <i class="icon-[lucide--x-circle] size-3" />
77 : </Button>
78 : </div>
79 : </div>
80 : </template>
81 :
82 : <script setup lang="ts">
83 : import { computed, useId } from 'vue'
84 : import { useI18n } from 'vue-i18n'
85 :
86 : import Badge from '@comfyorg/design-system/badge/Badge'
87 : import Button from '@comfyorg/design-system/button/Button'
88 : import { useElectronDownloadStore } from '@/stores/electronDownloadStore'
89 : import type { ElectronDownload } from '@/stores/electronDownloadStore'
90 :
91 0 : const { t } = useI18n()
92 0 : const labelId = useId()
93 :
94 0 : const electronDownloadStore = useElectronDownloadStore()
95 :
96 : const { download } = defineProps<{
97 : download: ElectronDownload
98 : }>()
99 :
100 0 : const downloadProgressPercent = computed(() =>
101 : Number(((download.progress ?? 0) * 100).toFixed(1))
102 : )
103 :
104 0 : const getDownloadLabel = (savePath: string) => {
105 0 : let parts = savePath.split('/')
106 0 : parts = parts.length === 1 ? parts[0].split('\\') : parts
107 0 : const name = parts.pop()
108 : const dir = parts.pop()
109 0 : return `${dir}/${name}`
110 : }
111 :
112 0 : const triggerCancelDownload = () => electronDownloadStore.cancel(download.url)
113 0 : const triggerPauseDownload = () => electronDownloadStore.pause(download.url)
114 0 : const triggerResumeDownload = () => electronDownloadStore.resume(download.url)
115 :
116 0 : const handleRemoveDownload = () => {
117 0 : electronDownloadStore.$patch((state) => {
118 0 : state.downloads = state.downloads.filter(({ url }) => url !== download.url)
119 : })
120 : }
121 : </script>
|