Line data Source code
1 : import { watch } from 'vue'
2 : import { useI18n } from 'vue-i18n'
3 :
4 : import { useToast } from '@/components/ui/toast/toastStore'
5 : import { useSettingsDialog } from '@/platform/settings/composables/useSettingsDialog'
6 : import { useSettingStore } from '@/platform/settings/settingStore'
7 : import { useExtensionStore } from '@/platform/extensions/stores/extensionStore'
8 : import type { ComfyExtension } from '@/types/comfy'
9 :
10 : import { useAgentExtensionActions } from './useAgentExtensionActions'
11 :
12 2355 : export function useAgentExtensionNotices() {
13 2355 : const { t } = useI18n()
14 2355 : const extensionStore = useExtensionStore()
15 2355 : const settingStore = useSettingStore()
16 2355 : const toast = useToast()
17 2355 : const settingsDialog = useSettingsDialog()
18 2355 : const { disableExtension } = useAgentExtensionActions()
19 2355 : const notified = new Set<string>()
20 :
21 7 : function showNotice(extension: ComfyExtension) {
22 7 : toast.info(t('g.agentExtensionAdded', { name: extension.name }), {
23 : description: extension.provenance?.summary,
24 : actions: [
25 : {
26 : label: t('g.manageExtensions'),
27 : onClick: () => settingsDialog.show('extension')
28 : },
29 : {
30 : label: t('g.disableExtension'),
31 : onClick: () => disableExtension(extension)
32 : }
33 : ]
34 : })
35 : }
36 :
37 2355 : watch(
38 : [
39 : () => settingStore.isReady,
40 : () => extensionStore.agentExtensions,
41 : () => extensionStore.areLateCustomNodesPending
42 : ],
43 : ([settingsReady, extensions, pending]) => {
44 23625 : if (!settingsReady || pending) return
45 : const seen =
46 : settingStore.settingValues['Comfy.Extension.SeenAgentExtensions'] ?? []
47 23625 : seen.forEach((name) => notified.add(name))
48 23625 : const unseen = extensions.filter(({ name }) => !notified.has(name))
49 23625 : if (!unseen.length) return
50 :
51 7 : unseen.forEach((extension) => {
52 7 : notified.add(extension.name)
53 7 : showNotice(extension)
54 : })
55 7 : void settingStore.set('Comfy.Extension.SeenAgentExtensions', [
56 : ...notified
57 : ])
58 : },
59 : { immediate: true }
60 : )
61 : }
|