|
| 1 | +<template> |
| 2 | + <div |
| 3 | + v-if="showVueNodesBannerRef" |
| 4 | + class="pointer-events-auto w-full h-10 bg-gradient-to-r from-blue-600 to-blue-700 flex items-center justify-between px-4" |
| 5 | + > |
| 6 | + <div class="w-5 h-5"></div> |
| 7 | + <div class="flex items-center"> |
| 8 | + <i class="icon-[lucide--sparkles]"></i> |
| 9 | + <h5 class="pl-2">{{ $t('vueNodesBanner.message') }}</h5> |
| 10 | + <Button |
| 11 | + class="cursor-pointer bg-transparent rounded h-7 px-3 border border-white text-white ml-4 text-xs" |
| 12 | + @click="handleTryItOut" |
| 13 | + > |
| 14 | + {{ $t('vueNodesBanner.tryItOut') }} |
| 15 | + </Button> |
| 16 | + </div> |
| 17 | + <Button |
| 18 | + class="cursor-pointer bg-transparent border-0 outline-0 grid place-items-center" |
| 19 | + unstyled |
| 20 | + @click="handleDismiss" |
| 21 | + > |
| 22 | + <i class="w-5 h-5 icon-[lucide--x]"></i> |
| 23 | + </Button> |
| 24 | + </div> |
| 25 | +</template> |
| 26 | + |
| 27 | +<script setup lang="ts"> |
| 28 | +import Button from 'primevue/button' |
| 29 | +import { onMounted, ref } from 'vue' |
| 30 | +
|
| 31 | +import { useSettingStore } from '@/platform/settings/settingStore' |
| 32 | +
|
| 33 | +const STORAGE_KEY = 'vueNodesBannerDismissed' |
| 34 | +
|
| 35 | +const settingStore = useSettingStore() |
| 36 | +const showVueNodesBannerRef = ref(false) |
| 37 | +
|
| 38 | +const checkLocalStorage = (): boolean => { |
| 39 | + try { |
| 40 | + const value = localStorage.getItem(STORAGE_KEY) |
| 41 | + // Return true if the banner was NOT dismissed (value is null or 'false') |
| 42 | + return value !== 'true' |
| 43 | + } catch (error) { |
| 44 | + // If localStorage is not available (e.g., private browsing), show the banner |
| 45 | + console.warn('localStorage not available:', error) |
| 46 | + return true |
| 47 | + } |
| 48 | +} |
| 49 | +
|
| 50 | +const handleDismiss = (): void => { |
| 51 | + showVueNodesBannerRef.value = false |
| 52 | + try { |
| 53 | + localStorage.setItem(STORAGE_KEY, 'true') |
| 54 | + } catch (error) { |
| 55 | + // Silently fail if localStorage is not available |
| 56 | + console.warn('Failed to save banner dismissal:', error) |
| 57 | + } |
| 58 | +} |
| 59 | +
|
| 60 | +const handleTryItOut = async (): Promise<void> => { |
| 61 | + try { |
| 62 | + await settingStore.set('Comfy.VueNodes.Enabled', true) |
| 63 | + } catch (error) { |
| 64 | + console.error('Failed to enable Vue nodes:', error) |
| 65 | + } finally { |
| 66 | + handleDismiss() |
| 67 | + } |
| 68 | +} |
| 69 | +
|
| 70 | +onMounted(() => { |
| 71 | + showVueNodesBannerRef.value = checkLocalStorage() |
| 72 | +}) |
| 73 | +</script> |
0 commit comments