11<template >
22 <div class =" flex gap-2 items-center" >
3+ <DownloadManager />
34 <div v-if =" downloadState.total > 0 || hasActiveLoadingBars" class =" relative" >
45 <IconButton
56 v-tooltip =" downloadToggleLabel "
1718 </div >
1819 <AppUpdateButton />
1920 <div
20- class =" flex border-solid border-surface-5 text-sm items-center gap-2 py-1.5 px-3 rounded-xl border"
21+ class =" flex border-solid border-surface-5 text-sm font-medium items-center gap-2 py-1.5 px-3 rounded-xl border"
2122 >
2223 <template v-if =" selectedProcess " >
2324 <OnlineIndicatorIcon />
@@ -130,10 +131,10 @@ import {
130131 TerminalSquareIcon ,
131132 UnplugIcon ,
132133} from ' @modrinth/assets'
133- import { IconButton } from ' @modrinth/ui'
134134import {
135135 defineMessages ,
136136 FloatingMenu ,
137+ IconButton ,
137138 injectNotificationManager ,
138139 injectPopupNotificationManager ,
139140 type PopupNotificationProgressItem ,
@@ -145,10 +146,9 @@ import { computed, onBeforeUnmount, onMounted, ref } from 'vue'
145146import { useRouter } from ' vue-router'
146147
147148import AppUpdateButton from ' @/components/ui/app-update-button/index.vue'
148- import { useInstallJobNotifications } from ' @/composables/browse/install-job-notifications '
149+ import DownloadManager from ' @/components/ui/download-manager/index.vue '
149150import { useAppEvent } from ' @/composables/use-app-event'
150151import { trackEvent } from ' @/helpers/analytics'
151- import { toError } from ' @/helpers/errors'
152152import { get_many as getInstances } from ' @/helpers/instance'
153153import { get_all as getRunningProcesses , kill as killProcess } from ' @/helpers/process'
154154import type { LoadingBar } from ' @/helpers/state'
@@ -323,7 +323,6 @@ function goToTerminal(instanceId?: string) {
323323const currentLoadingBars = ref <LoadingBar []>([])
324324const currentLoadingBarIconUrls = ref <Record <string , string | null >>({})
325325const notificationId = ref <string | number | null >(null )
326- const terminalNotificationIds = new Map <string , string | number >()
327326const dismissed = ref (false )
328327
329328function getLoadingBarKey(loadingBar : LoadingBar ): string {
@@ -371,79 +370,28 @@ function removeNotification(): void {
371370 notificationId .value = null
372371}
373372
374- function syncTerminalNotifications(): void {
375- const terminalNotifications = installJobNotifications .terminalNotifications .value
376- const currentJobIds = new Set (terminalNotifications .map ((notification ) => notification .id ))
377-
378- for (const terminal of terminalNotifications ) {
379- const popupId = terminalNotificationIds .get (terminal .id )
380- let notification = popupId
381- ? popupNotificationManager
382- .getNotifications ()
383- .find (
384- (candidate ): candidate is PopupNotificationStandard =>
385- candidate .id === popupId && candidate .contentType === ' standard' ,
386- )
387- : undefined
388-
389- if (! notification ) {
390- notification = popupNotificationManager .addPopupNotification ({
391- contentType: ' standard' ,
392- title: terminal .title ,
393- text: terminal .text ,
394- type: terminal .type ,
395- buttons: terminal .buttons ,
396- onDismiss: terminal .onDismiss ,
397- autoCloseMs: null ,
398- })
399- terminalNotificationIds .set (terminal .id , notification .id )
400- continue
401- }
402-
403- notification .title = terminal .title
404- notification .text = terminal .text
405- notification .type = terminal .type
406- notification .buttons = terminal .buttons
407- notification .onDismiss = terminal .onDismiss
408- }
409-
410- for (const [jobId, popupId] of terminalNotificationIds ) {
411- if (! currentJobIds .has (jobId )) {
412- popupNotificationManager .removeNotification (popupId )
413- terminalNotificationIds .delete (jobId )
414- }
415- }
416- }
417-
418373function buildDownloadItems(): PopupNotificationProgressItem [] {
419- return [
420- ... installJobNotifications .progressItems .value ,
421- ... currentLoadingBars .value .map <PopupNotificationProgressItem >((bar ) => ({
422- id: getLoadingBarKey (bar ),
423- title: bar .title ?? ' ' ,
424- text: getLoadingText (bar ),
425- iconUrl: currentLoadingBarIconUrls .value [getLoadingBarKey (bar )] ?? null ,
426- progress: getLoadingProgress (bar ),
427- waiting: ! bar .total || bar .total <= 0 ,
428- progressType: bar .bar_type ?.type === ' pack_import' ? ' bytes' : ' percentage' ,
429- progressCurrent: bar .current ,
430- progressTotal: bar .total ,
431- })),
432- ]
374+ return currentLoadingBars .value .map ((bar ) => ({
375+ id: getLoadingBarKey (bar ),
376+ title: bar .title ?? ' ' ,
377+ text: getLoadingText (bar ),
378+ iconUrl: currentLoadingBarIconUrls .value [getLoadingBarKey (bar )] ?? null ,
379+ progress: getLoadingProgress (bar ),
380+ waiting: ! bar .total || bar .total <= 0 ,
381+ progressType: bar .bar_type ?.type === ' pack_import' ? ' bytes' : ' percentage' ,
382+ progressCurrent: bar .current ,
383+ progressTotal: bar .total ,
384+ }))
433385}
434386
435- const hasActiveLoadingBars = computed (
436- () => currentLoadingBars .value .length > 0 || installJobNotifications .active .value ,
437- )
387+ const hasActiveLoadingBars = computed (() => currentLoadingBars .value .length > 0 )
438388
439389function updateNotification(resummon = false ): void {
440- syncTerminalNotifications ()
441-
442390 if (resummon ) {
443391 dismissed .value = false
444392 }
445393
446- if (currentLoadingBars .value .length === 0 && ! installJobNotifications . active . value ) {
394+ if (currentLoadingBars .value .length === 0 ) {
447395 removeNotification ()
448396 dismissed .value = false
449397 return
@@ -462,19 +410,15 @@ function updateNotification(resummon = false): void {
462410 const progressItems = buildDownloadItems ()
463411
464412 if (notif ) {
465- notif .title = installJobNotifications .active .value
466- ? installJobNotifications .title .value
467- : formatMessage (messages .downloads )
413+ notif .title = formatMessage (messages .downloads )
468414 notif .text = undefined
469415 notif .progressItems = progressItems
470416 notif .progress = undefined
471417 notif .waiting = undefined
472418 } else {
473419 const notification = popupNotificationManager .addPopupNotification ({
474420 contentType: ' standard' ,
475- title: installJobNotifications .active .value
476- ? installJobNotifications .title .value
477- : formatMessage (messages .downloads ),
421+ title: formatMessage (messages .downloads ),
478422 type: ' download' ,
479423 autoCloseMs: null ,
480424 progressItems ,
@@ -554,12 +498,6 @@ async function refreshLoadingBars() {
554498 updateNotification ()
555499}
556500
557- const installJobNotifications = await useInstallJobNotifications ({
558- router ,
559- handleError : (error ) => handleError (toError (error )),
560- onChange: updateNotification ,
561- })
562-
563501await refreshLoadingBars ()
564502
565503useAppEvent (' loading' , async () => {
@@ -576,11 +514,8 @@ function selectProcess(process: RunningProcess) {
576514
577515onBeforeUnmount (() => {
578516 removeNotification ()
579- terminalNotificationIds .forEach ((id ) => popupNotificationManager .removeNotification (id ))
580- terminalNotificationIds .clear ()
581517 dismissed .value = false
582518 window .removeEventListener (' offline' , handleOffline )
583519 window .removeEventListener (' online' , handleOnline )
584- installJobNotifications .dispose ()
585520})
586521 </script >
0 commit comments