Line data Source code
1 : <template>
2 1 : <Button
3 : variant="secondary"
4 : size="icon"
5 : :tooltip
6 : tooltip-side="bottom"
7 : :aria-label="tooltip"
8 : :aria-busy="isChecking || undefined"
9 : data-testid="cloud-button"
10 : @pointerenter="prefetch"
11 : @keydown.enter="prefetch"
12 : @keydown.space="prefetch"
13 : @click="openModal"
14 : >
15 : <ProgressRing v-if="isChecking" :percent="25" class="size-4 animate-spin" />
16 : <i v-else class="icon-[lucide--cloud]" aria-hidden="true" />
17 : </Button>
18 : </template>
19 :
20 : <script setup lang="ts">
21 : import { storeToRefs } from 'pinia'
22 : import { computed, onBeforeUnmount, ref, watch } from 'vue'
23 : import { useI18n } from 'vue-i18n'
24 :
25 : import Button from '@comfyorg/design-system/button/Button'
26 : import { useToast } from '@/components/ui/toast/toastStore'
27 : import ProgressRing from '@/platform/openOnCloud/components/ProgressRing.vue'
28 : import {
29 : closeRunOnCloudDialog,
30 : openRunOnCloudDialog
31 : } from '@/platform/openOnCloud/openRunOnCloudDialog'
32 : import { useCloudWorkflowCheckStore } from '@/platform/openOnCloud/stores/cloudWorkflowCheckStore'
33 :
34 1 : const { t } = useI18n()
35 1 : const toast = useToast()
36 1 : const checkStore = useCloudWorkflowCheckStore()
37 1 : const { state: check } = storeToRefs(checkStore)
38 :
39 1 : const isChecking = computed(() => check.value.phase === 'checking')
40 1 : const opensWhenAnswered = ref(false)
41 1 : let isMounted = true
42 1 : onBeforeUnmount(() => {
43 0 : isMounted = false
44 : })
45 :
46 1 : const tooltip = computed(() =>
47 : isChecking.value
48 : ? t('openOnCloud.cloudButton.checking')
49 : : t('openOnCloud.cloudButton.tooltip')
50 : )
51 :
52 0 : function prefetch() {
53 0 : if (check.value.phase === 'idle') void checkStore.check()
54 : }
55 :
56 0 : function showModal() {
57 0 : const current = check.value
58 0 : if (current.phase === 'failed') {
59 0 : toast.error(
60 : current.nodeType
61 : ? t('openOnCloud.missingLocalModelLoader', {
62 : nodeType: current.nodeType
63 : })
64 : : t('openOnCloud.checkFailed')
65 : )
66 0 : return
67 : }
68 0 : void openRunOnCloudDialog(() => isMounted && check.value === current)
69 : }
70 :
71 0 : function openModal() {
72 0 : const { phase } = check.value
73 0 : if (phase === 'answered') {
74 0 : showModal()
75 0 : return
76 : }
77 0 : opensWhenAnswered.value = true
78 0 : if (phase === 'idle' || phase === 'failed') void checkStore.check()
79 : }
80 :
81 1 : watch(
82 : () => check.value.phase,
83 : (phase) => {
84 0 : if (phase === 'idle') {
85 0 : opensWhenAnswered.value = false
86 0 : closeRunOnCloudDialog()
87 0 : return
88 : }
89 0 : if (phase === 'checking') {
90 0 : if (closeRunOnCloudDialog()) opensWhenAnswered.value = true
91 0 : return
92 : }
93 0 : if (!opensWhenAnswered.value) return
94 0 : opensWhenAnswered.value = false
95 0 : showModal()
96 : }
97 : )
98 : </script>
|