forked from akanyan/STARTLINER
feat: global progress bar
Also fix me having no foresight and executing things inside log::debug! macros
This commit is contained in:
@ -88,6 +88,60 @@ listen<string>('launch-error', (event) => {
|
||||
errorMessage.value = event.payload;
|
||||
errorHeader.value = 'Launch error';
|
||||
});
|
||||
|
||||
interface DownloadingStatus {
|
||||
ratio: number;
|
||||
pkg_key: string;
|
||||
}
|
||||
const downloading_status: Ref<DownloadingStatus[]> = ref([]);
|
||||
|
||||
const download_value = computed(() => {
|
||||
return (
|
||||
downloading_status.value.map((v) => v.ratio).reduce((a, v) => a * v) *
|
||||
100
|
||||
);
|
||||
});
|
||||
|
||||
const downloadProgressText = computed(() => {
|
||||
if (download_value.value < 7) {
|
||||
return '';
|
||||
}
|
||||
let pkgs = `${downloading_status.value.length} package${downloading_status.value.length === 1 ? '' : 's'}`;
|
||||
if (download_value.value < 14) {
|
||||
return pkgs;
|
||||
} else {
|
||||
return `${pkgs} (${Math.floor(download_value.value)}%)`;
|
||||
}
|
||||
});
|
||||
|
||||
listen<DownloadingStatus>('download-progress', (event) => {
|
||||
let status = downloading_status.value.find(
|
||||
(v) => v.pkg_key === event.payload.pkg_key
|
||||
);
|
||||
|
||||
if (status === undefined) {
|
||||
status = {
|
||||
ratio: 0,
|
||||
pkg_key: event.payload.pkg_key,
|
||||
};
|
||||
downloading_status.value.push(status);
|
||||
}
|
||||
status.ratio = event.payload.ratio;
|
||||
|
||||
const remove = () => {
|
||||
if (status !== undefined) {
|
||||
downloading_status.value = downloading_status.value.filter(
|
||||
(v) => v.pkg_key !== event.payload.pkg_key
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
if (status.ratio === 1.0) {
|
||||
remove();
|
||||
}
|
||||
|
||||
setTimeout(() => remove, 10_000);
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@ -102,6 +156,16 @@ listen<string>('launch-error', (event) => {
|
||||
: 'main-scale-xl'
|
||||
"
|
||||
>
|
||||
<div
|
||||
v-if="downloading_status.length > 0"
|
||||
class="download-progress-bg"
|
||||
></div>
|
||||
<ProgressBar
|
||||
v-if="downloading_status.length > 0"
|
||||
:value="download_value"
|
||||
class="download-progress"
|
||||
>{{ downloadProgressText }}</ProgressBar
|
||||
>
|
||||
<ConfirmDialog>
|
||||
<template #message="{ message }">
|
||||
<ScrollPanel
|
||||
@ -353,4 +417,23 @@ body {
|
||||
.p-progressbar-label {
|
||||
transition-duration: 0s !important;
|
||||
}
|
||||
|
||||
.download-progress {
|
||||
position: fixed !important;
|
||||
bottom: 0;
|
||||
left: 5vw;
|
||||
width: 90vw;
|
||||
z-index: 10000 !important;
|
||||
margin: 20px auto;
|
||||
}
|
||||
.download-progress-bg {
|
||||
position: fixed;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
width: 100vw;
|
||||
height: 60px;
|
||||
background-color: var(--p-surface-900);
|
||||
border-top: 1px solid var(--p-surface-600);
|
||||
z-index: 998;
|
||||
}
|
||||
</style>
|
||||
|
Reference in New Issue
Block a user