Line data Source code
1 : import { useToast } from '@/components/ui/toast/toastStore'
2 : import { t } from '@/i18n'
3 : import { useSettingsDialog } from '@/platform/settings/composables/useSettingsDialog'
4 : import { useDialogService } from '@/services/dialogService'
5 : import { useCommandStore } from '@/platform/keybindings/commandStore'
6 : import { useDialogStore } from '@/stores/dialogStore'
7 : import {
8 : ManagerUIState,
9 : getManagerUIState,
10 : showIncompatibleManagerToast
11 : } from '@/platform/customNodes/manager/composables/useManagerState'
12 : import type { ManagerTab } from '@/platform/customNodes/manager/types/comfyManagerTypes'
13 : import ManagerDialog from '@/platform/customNodes/manager/components/manager/ManagerDialog.vue'
14 :
15 2355 : const DIALOG_KEY = 'global-manager'
16 :
17 : interface OpenManagerOptions {
18 : initialTab?: ManagerTab
19 : initialPackId?: string
20 : legacyCommand?: string
21 : showToastOnLegacyError?: boolean
22 : isLegacyOnly?: boolean
23 : }
24 :
25 216 : export function useManagerDialog() {
26 216 : const dialogService = useDialogService()
27 216 : const dialogStore = useDialogStore()
28 :
29 0 : function hide() {
30 0 : dialogStore.closeDialog({ key: DIALOG_KEY })
31 : }
32 :
33 15 : function show(initialTab?: ManagerTab, initialPackId?: string) {
34 15 : dialogService.showLayoutDialog({
35 : key: DIALOG_KEY,
36 : component: ManagerDialog,
37 : props: {
38 : onClose: hide,
39 : initialTab,
40 : initialPackId
41 : }
42 : })
43 : }
44 :
45 15 : async function openManager(options?: OpenManagerOptions): Promise<void> {
46 15 : const managerUIState = getManagerUIState()
47 15 : const settingsDialog = useSettingsDialog()
48 :
49 15 : switch (managerUIState) {
50 : case ManagerUIState.DISABLED:
51 0 : settingsDialog.show('extension')
52 0 : break
53 :
54 : case ManagerUIState.INCOMPATIBLE:
55 0 : showIncompatibleManagerToast({ force: true })
56 0 : break
57 :
58 : case ManagerUIState.LEGACY_UI: {
59 0 : const command =
60 : options?.legacyCommand || 'Comfy.Manager.Menu.ToggleVisibility'
61 0 : try {
62 0 : await useCommandStore().execute(command)
63 : } catch {
64 0 : if (options?.showToastOnLegacyError !== false) {
65 0 : useToast().error(t('g.error'), {
66 : description: t('manager.legacyMenuNotAvailable')
67 : })
68 : } else {
69 0 : settingsDialog.show('extension')
70 : }
71 : }
72 0 : break
73 : }
74 :
75 : case ManagerUIState.NEW_UI:
76 15 : if (options?.isLegacyOnly) {
77 0 : useToast().error(t('g.error'), {
78 : description: t('manager.legacyMenuNotAvailable')
79 : })
80 : } else {
81 15 : show(options?.initialTab, options?.initialPackId)
82 : }
83 : break
84 : }
85 : }
86 :
87 216 : return {
88 : show,
89 : hide,
90 : openManager
91 : }
92 : }
|