Line data Source code
1 : import { storeToRefs } from 'pinia'
2 : import { computed, onMounted } from 'vue'
3 :
4 : import { useSettingStore } from '@/platform/settings/settingStore'
5 : import { useTelemetry } from '@comfyorg/telemetry'
6 : import { useReleaseStore } from '@/platform/updates/common/releaseStore'
7 : import { useHelpCenterStore } from '@/stores/helpCenterStore'
8 : import { useConflictAcknowledgment } from '@/platform/customNodes/manager/composables/useConflictAcknowledgment'
9 : import { useConflictDetection } from '@/platform/customNodes/manager/composables/useConflictDetection'
10 : import { useNodeConflictDialog } from '@/platform/customNodes/manager/composables/dialogs/useNodeConflictDialog'
11 :
12 4186 : export function useHelpCenter() {
13 4186 : const settingStore = useSettingStore()
14 4186 : const releaseStore = useReleaseStore()
15 4186 : const helpCenterStore = useHelpCenterStore()
16 4186 : const { isVisible: isHelpCenterVisible } = storeToRefs(helpCenterStore)
17 4186 : const { shouldShowRedDot: showReleaseRedDot } = storeToRefs(releaseStore)
18 :
19 4186 : const conflictDetection = useConflictDetection()
20 4186 : const { show: showNodeConflictDialog } = useNodeConflictDialog()
21 :
22 : // Use conflict acknowledgment state from composable - call only once
23 4186 : const { shouldShowRedDot: shouldShowConflictRedDot, markConflictsAsSeen } =
24 : useConflictAcknowledgment()
25 :
26 : // Use either release red dot or conflict red dot
27 4186 : const shouldShowRedDot = computed((): boolean => {
28 : const releaseRedDot = showReleaseRedDot.value
29 2014 : return releaseRedDot || shouldShowConflictRedDot.value
30 : })
31 :
32 4186 : const sidebarLocation = computed(() =>
33 : settingStore.get('Comfy.Sidebar.Location')
34 : )
35 :
36 : /**
37 : * Toggle Help Center and track UI button click.
38 : */
39 4186 : const toggleHelpCenter = () => {
40 21 : useTelemetry()?.trackUiButtonClicked({
41 : button_id: 'sidebar_help_center_toggled',
42 : element_group: 'sidebar'
43 : })
44 21 : helpCenterStore.toggle()
45 : }
46 :
47 4186 : const closeHelpCenter = () => {
48 10 : helpCenterStore.hide()
49 : }
50 :
51 : /**
52 : * Handle What's New popup dismissal
53 : * Check if conflict modal should be shown after ComfyUI update
54 : */
55 4186 : const handleWhatsNewDismissed = async () => {
56 0 : try {
57 : // Check if conflict modal should be shown after update
58 : const shouldShow =
59 : await conflictDetection.shouldShowConflictModalAfterUpdate()
60 0 : if (shouldShow) {
61 0 : showConflictModal()
62 : }
63 : } catch (error) {
64 0 : console.error('[HelpCenter] Error checking conflict modal:', error)
65 : }
66 : }
67 :
68 : /**
69 : * Show the node conflict dialog with current conflict data
70 : */
71 4186 : const showConflictModal = () => {
72 0 : showNodeConflictDialog({
73 : showAfterWhatsNew: true,
74 : dialogComponentProps: {
75 : onClose: () => {
76 0 : markConflictsAsSeen()
77 : }
78 : }
79 : })
80 : }
81 :
82 : // Initialize release store on mount
83 4186 : onMounted(async () => {
84 : // Initialize release store to fetch releases for toast and popup
85 4186 : await releaseStore.initialize()
86 : })
87 :
88 4186 : return {
89 : isHelpCenterVisible,
90 : shouldShowRedDot,
91 : sidebarLocation,
92 : toggleHelpCenter,
93 : closeHelpCenter,
94 : handleWhatsNewDismissed
95 : }
96 : }
|