Line data Source code
1 : <template>
2 2156 : <Menu
3 : :items="translatedItems"
4 : class="comfy-command-menu"
5 : @activate="onMenuItemActivate"
6 : >
7 : <template #trigger="{ open }">
8 : <Button
9 : variant="textonly"
10 : size="unset"
11 : :tooltip="t('sideToolbar.labels.menu')"
12 : tooltip-side="right"
13 : data-testid="comfy-menu-button"
14 : type="button"
15 : :aria-label="t('sideToolbar.labels.menu')"
16 : :class="
17 : cn(
18 : 'flex h-(--sidebar-item-height) w-(--sidebar-width) shrink-0 flex-col rounded-none p-2',
19 : open && 'bg-muted hover:bg-muted'
20 : )
21 : "
22 : @click="onLogoMenuClick"
23 : >
24 : <div class="grid place-items-center-safe gap-0.5">
25 : <i
26 : class="col-span-full row-span-full icon-[lucide--chevron-down] size-3 translate-x-4 text-muted-foreground"
27 : />
28 : <ComfyLogo
29 : alt="ComfyUI Logo"
30 : class="comfyui-logo col-span-full row-span-full size-4.5"
31 : mode="fill"
32 : />
33 : </div>
34 : </Button>
35 : </template>
36 : </Menu>
37 : </template>
38 :
39 : <script setup lang="ts">
40 : import { computed } from 'vue'
41 : import { useI18n } from 'vue-i18n'
42 :
43 : import { cn } from '@comfyorg/tailwind-utils'
44 : import { snakeCase } from 'es-toolkit'
45 :
46 : import ComfyLogo from '@comfyorg/design-system/icon/ComfyLogo'
47 : import Button from '@comfyorg/design-system/button/Button'
48 : import Menu from '@comfyorg/design-system/menu/Menu'
49 : import type { MenuItem } from '@comfyorg/design-system/lib/menu/types'
50 : import { useWorkflowTemplateSelectorDialog } from '@/platform/workflow/templates/composables/useWorkflowTemplateSelectorDialog'
51 : import { useSettingStore } from '@/platform/settings/settingStore'
52 : import type { SettingPanelType } from '@comfyorg/settings-core/types'
53 : import { useTelemetry } from '@comfyorg/telemetry'
54 : import { useThemeService } from '@/platform/theme/themeService'
55 : import { useSettingsDialog } from '@/platform/settings/composables/useSettingsDialog'
56 : import { useCommandStore } from '@/platform/keybindings/commandStore'
57 : import { useMenuItemStore } from '@/stores/menuItemStore'
58 : import type { AppMenuItem } from '@/stores/menuItemStore'
59 : import { useThemeStore } from '@/platform/theme/themeStore'
60 : import { normalizeI18nKey } from '@/utils/formatUtil'
61 : import { useManagerDialog } from '@/platform/customNodes/manager/composables/dialogs/useManagerDialog'
62 : import { ManagerTab } from '@/platform/customNodes/manager/types/comfyManagerTypes'
63 :
64 2093 : const { t } = useI18n()
65 2093 : const menuItemStore = useMenuItemStore()
66 2093 : const commandStore = useCommandStore()
67 2093 : const themeStore = useThemeStore()
68 2093 : const themeService = useThemeService()
69 2093 : const settingsDialog = useSettingsDialog()
70 2093 : const settingStore = useSettingStore()
71 :
72 2093 : const nodes2Enabled = computed(
73 : () => settingStore.get('Comfy.VueNodes.Enabled') ?? false
74 : )
75 :
76 2093 : const telemetry = useTelemetry()
77 :
78 161 : function onLogoMenuClick() {
79 161 : telemetry?.trackUiButtonClicked({
80 : button_id: 'sidebar_comfy_menu_opened',
81 : element_group: 'sidebar'
82 : })
83 : }
84 :
85 2093 : const EXTRA_ITEM_BUTTON_IDS: Partial<Record<string, string>> = {
86 : 'browse-templates': 'comfy_menu_browse_templates_clicked',
87 : 'manage-extensions': 'comfy_menu_manage_extensions_clicked'
88 : }
89 :
90 112 : function commandButtonId(commandId: string) {
91 112 : if (commandStore.getCommand(commandId)?.source !== 'System')
92 2 : return 'comfy_menu_extension_command_clicked'
93 110 : return `comfy_menu_${snakeCase(commandId)}_clicked`
94 : }
95 :
96 157 : function menuItemButtonId(item: AppMenuItem) {
97 157 : if ('commandId' in item) return commandButtonId(item.commandId)
98 157 : if (item.key?.startsWith('theme-')) return 'comfy_menu_theme_clicked'
99 157 : return item.key ? EXTRA_ITEM_BUTTON_IDS[item.key] : undefined
100 : }
101 :
102 157 : function onMenuItemActivate(item: AppMenuItem) {
103 157 : const buttonId = menuItemButtonId(item)
104 157 : if (!buttonId) return
105 157 : telemetry?.trackUiButtonClicked({
106 : button_id: buttonId,
107 : element_group: 'comfy_menu'
108 : })
109 : }
110 :
111 2093 : const translateMenuItem = (item: AppMenuItem): AppMenuItem => {
112 92712 : const label = typeof item.label === 'function' ? item.label() : item.label
113 92712 : const translatedLabel = label
114 : ? t(`menuLabels.${normalizeI18nKey(label)}`, label)
115 : : undefined
116 :
117 92712 : return item.items
118 : ? {
119 : ...item,
120 : label: translatedLabel,
121 : items: item.items.map(translateMenuItem)
122 : }
123 : : { ...item, label: translatedLabel }
124 : }
125 :
126 2093 : const showSettings = (defaultPanel?: SettingPanelType) => {
127 0 : settingsDialog.show(defaultPanel)
128 : }
129 :
130 2093 : const showManageExtensions = async () => {
131 0 : await useManagerDialog().openManager({
132 : initialTab: ManagerTab.All,
133 : showToastOnLegacyError: false
134 : })
135 : }
136 :
137 2093 : const themeMenuItems = computed(() => {
138 2093 : return themeStore.presets.map<MenuItem>((palette) => ({
139 : key: `theme-${palette.id}`,
140 : label: palette.name,
141 : checked: () => themeStore.activePresetId === palette.id,
142 : command: async () => {
143 2 : await themeService.setActiveTheme(palette.id)
144 : }
145 : }))
146 : })
147 :
148 2093 : const extraMenuItems = computed<MenuItem[]>(() => [
149 : { separator: true },
150 : {
151 : key: 'theme',
152 : label: t('menu.theme'),
153 : items: themeMenuItems.value
154 : },
155 : {
156 : key: 'nodes-2.0-toggle',
157 : label: 'Nodes 2.0',
158 : checked: nodes2Enabled.value,
159 : presentation: 'switch',
160 : class: 'select-none',
161 : command: () => onNodes2ToggleChange(!nodes2Enabled.value)
162 : },
163 : { separator: true },
164 : {
165 : key: 'browse-templates',
166 : label: t('menuLabels.Browse Templates'),
167 : icon: 'icon-[comfy--template]',
168 : command: () => useWorkflowTemplateSelectorDialog().show('menu')
169 : },
170 : {
171 : key: 'settings',
172 : label: t('g.settings'),
173 : icon: 'icon-[lucide--settings]',
174 : command: () => {
175 0 : telemetry?.trackUiButtonClicked({
176 : button_id: 'sidebar_settings_menu_opened',
177 : element_group: 'sidebar'
178 : })
179 0 : showSettings()
180 : }
181 : },
182 : {
183 : key: 'manage-extensions',
184 : label: t('menu.manageExtensions'),
185 : icon: 'icon-[comfy--extensions-blocks]',
186 : command: showManageExtensions
187 : }
188 : ])
189 :
190 2093 : const menuSeparator: MenuItem = { separator: true }
191 :
192 2093 : const translatedItems = computed<AppMenuItem[]>(() => {
193 2156 : const items = menuItemStore.menuItems.map(translateMenuItem)
194 2156 : let helpIndex = items.findIndex((item) => item.key === 'Help')
195 2156 : let helpItem: MenuItem | undefined
196 :
197 2156 : if (helpIndex !== -1) {
198 2156 : items[helpIndex].icon = 'mdi mdi-help-circle-outline'
199 2156 : const isLastItem = helpIndex !== items.length - 1
200 2156 : helpItem = items.splice(
201 : helpIndex,
202 : 1,
203 : ...(isLastItem ? [menuSeparator] : [])
204 : )[0]
205 : }
206 2156 : helpIndex = items.length
207 :
208 2156 : items.splice(
209 : helpIndex,
210 : 0,
211 : ...extraMenuItems.value,
212 : ...(helpItem ? [menuSeparator, helpItem] : [])
213 : )
214 :
215 2156 : return items
216 : })
217 :
218 2093 : const onNodes2ToggleChange = async (value: boolean) => {
219 43 : await settingStore.set('Comfy.VueNodes.Enabled', value)
220 43 : telemetry?.trackUiButtonClicked({
221 : button_id: `menu_nodes_2.0_toggle_${value ? 'enabled' : 'disabled'}`,
222 : element_group: 'sidebar'
223 : })
224 : }
225 : </script>
|