LCOV - code coverage report
Current view: top level - src/platform/updates/components - ReleaseNotificationToast.vue Coverage Total Hit
Test: ComfyUI E2E Coverage Lines: 38.6 % 57 22
Test Date: 2026-11-17 04:17:53

            Line data    Source code
       1              : <template>
       2         2099 :   <div v-if="shouldShow" class="release-toast-popup">
       3              :     <NotificationPopup
       4              :       icon="icon-[lucide--rocket]"
       5              :       :title="$t('releaseToast.newVersionAvailable')"
       6              :       :subtitle="latestRelease?.version"
       7              :       :position
       8              :     >
       9              :       <SanitizedHtml
      10              :         class="pl-14 text-sm leading-[1.21] font-normal text-muted-foreground"
      11              :         :html="formattedContent"
      12              :       />
      13              : 
      14              :       <template #footer-start>
      15              :         <a
      16              :           class="flex items-center gap-2 py-1 text-sm font-normal text-muted-foreground hover:text-foreground"
      17              :           :href="changelogUrl"
      18              :           target="_blank"
      19              :           rel="noopener noreferrer"
      20              :           @click="handleLearnMore"
      21              :         >
      22              :           <i class="icon-[lucide--external-link]"></i>
      23              :           {{ $t('releaseToast.whatsNew') }}
      24              :         </a>
      25              :       </template>
      26              : 
      27              :       <template #footer-end>
      28              :         <Button
      29              :           variant="link"
      30              :           size="unset"
      31              :           class="h-6 px-0 font-normal"
      32              :           @click="handleSkip"
      33              :         >
      34              :           {{ $t('releaseToast.skip') }}
      35              :         </Button>
      36              :         <Button
      37              :           variant="secondary"
      38              :           size="lg"
      39              :           class="font-normal"
      40              :           @click="handleUpdate"
      41              :         >
      42              :           {{ $t('releaseToast.update') }}
      43              :         </Button>
      44              :       </template>
      45              :     </NotificationPopup>
      46              :   </div>
      47              : </template>
      48              : 
      49              : <script setup lang="ts">
      50              : import { default as DOMPurify } from 'dompurify'
      51              : import { computed, onMounted, ref, watch } from 'vue'
      52              : import { useI18n } from 'vue-i18n'
      53              : 
      54              : import NotificationPopup from '@comfyorg/design-system/common/NotificationPopup'
      55              : import SanitizedHtml from '@comfyorg/design-system/common/SanitizedHtml'
      56              : import Button from '@comfyorg/design-system/button/Button'
      57              : import { useErrorHandling } from '@/composables/useErrorHandling'
      58              : import { useExternalLink } from '@/composables/useExternalLink'
      59              : import { useCommandStore } from '@/platform/keybindings/commandStore'
      60              : import { isDesktop } from '@/platform/distribution/types'
      61              : import { formatVersionAnchor } from '@/utils/formatUtil'
      62              : import { renderMarkdownToHtml } from '@/utils/markdownRendererUtil'
      63              : 
      64              : import type { ReleaseNote } from '@/platform/updates/common/releaseService'
      65              : import { useReleaseStore } from '@/platform/updates/common/releaseStore'
      66              : 
      67              : const { position = 'bottom-left', isVisible = true } = defineProps<{
      68              :   position?: 'bottom-left' | 'bottom-right'
      69              :   isVisible?: boolean
      70              : }>()
      71              : 
      72         2093 : const { buildDocsUrl } = useExternalLink()
      73         2093 : const { toastErrorHandler } = useErrorHandling()
      74         2093 : const releaseStore = useReleaseStore()
      75         2093 : const { t } = useI18n()
      76              : 
      77              : // Local state for dismissed status
      78         2093 : const isDismissed = ref(false)
      79              : 
      80              : // Get latest release from store
      81         2093 : const latestRelease = computed<ReleaseNote | null>(() => {
      82            0 :   return releaseStore.recentRelease
      83              : })
      84              : 
      85              : // Show toast when new version available and not dismissed
      86         2093 : const shouldShow = computed(
      87              :   () => releaseStore.shouldShowToast && !isDismissed.value && isVisible
      88              : )
      89              : 
      90              : // Generate changelog URL with version anchor (language-aware)
      91         2093 : const changelogUrl = computed(() => {
      92            0 :   const changelogBaseUrl = buildDocsUrl('/changelog', { includeLocale: true })
      93            0 :   if (latestRelease.value?.version) {
      94              :     const versionAnchor = formatVersionAnchor(latestRelease.value.version)
      95            0 :     return `${changelogBaseUrl}#${versionAnchor}`
      96              :   }
      97            0 :   return changelogBaseUrl
      98              : })
      99              : 
     100         2093 : const formattedContent = computed(() => {
     101            0 :   if (!latestRelease.value?.content) {
     102            0 :     return DOMPurify.sanitize(`<p>${t('releaseToast.description')}</p>`)
     103              :   }
     104              : 
     105            0 :   try {
     106              :     const markdown = latestRelease.value.content
     107              :     // Remove the h1 title line and images for toast mode
     108              :     const contentWithoutTitle = markdown.replace(/^# .+$/m, '')
     109            0 :     const contentWithoutImages = contentWithoutTitle.replace(
     110              :       /!\[.*?\]\(.*?\)/g,
     111              :       ''
     112              :     )
     113              : 
     114              :     // Check if there's meaningful content left after cleanup
     115            0 :     const trimmedContent = contentWithoutImages.trim()
     116            0 :     if (!trimmedContent || trimmedContent.replace(/\s+/g, '') === '') {
     117            0 :       return DOMPurify.sanitize(`<p>${t('releaseToast.description')}</p>`)
     118              :     }
     119              : 
     120              :     // renderMarkdownToHtml already sanitizes with DOMPurify, so this is safe
     121            0 :     return renderMarkdownToHtml(contentWithoutImages)
     122              :   } catch (error) {
     123            0 :     console.error('Error parsing markdown:', error)
     124              :     // Fallback to plain text with line breaks - sanitize the HTML we create
     125            0 :     const fallbackContent = latestRelease.value.content.replace(/\n/g, '<br>')
     126            0 :     return fallbackContent.trim()
     127              :       ? DOMPurify.sanitize(fallbackContent)
     128              :       : DOMPurify.sanitize(`<p>${t('releaseToast.description')}</p>`)
     129              :   }
     130              : })
     131              : 
     132              : // Auto-hide timer
     133         2093 : let hideTimer: ReturnType<typeof setTimeout> | null = null
     134              : 
     135         2093 : const startAutoHide = () => {
     136            0 :   if (hideTimer) clearTimeout(hideTimer)
     137            0 :   hideTimer = setTimeout(() => {
     138            0 :     dismissToast()
     139              :   }, 8000) // 8 second auto-hide
     140              : }
     141              : 
     142         2093 : const clearAutoHide = () => {
     143            0 :   if (hideTimer) {
     144            0 :     clearTimeout(hideTimer)
     145            0 :     hideTimer = null
     146              :   }
     147              : }
     148              : 
     149         2093 : const dismissToast = () => {
     150            0 :   isDismissed.value = true
     151            0 :   clearAutoHide()
     152              : }
     153              : 
     154         2093 : const handleSkip = () => {
     155            0 :   if (latestRelease.value) {
     156            0 :     void releaseStore.handleSkipRelease(latestRelease.value.version)
     157              :   }
     158            0 :   dismissToast()
     159              : }
     160              : 
     161         2093 : const handleLearnMore = () => {
     162            0 :   if (latestRelease.value) {
     163            0 :     void releaseStore.handleShowChangelog(latestRelease.value.version)
     164              :   }
     165              :   // Do not dismiss; anchor will navigate in new tab but keep toast? spec maybe wants dismiss? We'll dismiss.
     166            0 :   dismissToast()
     167              : }
     168              : 
     169         2093 : const handleUpdate = async () => {
     170              :   if (isDesktop) {
     171              :     try {
     172              :       await useCommandStore().execute('Comfy-Desktop.CheckForUpdates')
     173              :       dismissToast()
     174              :     } catch (error) {
     175              :       toastErrorHandler(error)
     176              :     }
     177              :     return
     178              :   }
     179              : 
     180            0 :   window.open(
     181              :     buildDocsUrl('/installation/update_comfyui', { includeLocale: true }),
     182              :     '_blank'
     183              :   )
     184            0 :   dismissToast()
     185              : }
     186              : 
     187              : // Start auto-hide when toast becomes visible
     188         2093 : watch(shouldShow, (isVisible) => {
     189            0 :   if (isVisible) {
     190            0 :     startAutoHide()
     191              :   } else {
     192            0 :     clearAutoHide()
     193              :   }
     194              : })
     195              : 
     196              : // Initialize on mount
     197         2093 : onMounted(async () => {
     198              :   // Fetch releases if not already loaded
     199         2093 :   if (!releaseStore.releases.length) {
     200         2093 :     await releaseStore.fetchReleases()
     201              :   }
     202              : })
     203              : 
     204              : // Expose methods for testing
     205         2093 : defineExpose({
     206              :   handleSkip,
     207              :   handleLearnMore,
     208              :   handleUpdate
     209              : })
     210              : </script>
        

Generated by: LCOV version 2.0-1