Line data Source code
1 : import type { Component } from 'vue'
2 :
3 : import { reportError } from '@comfyorg/telemetry/reportError'
4 : import { useDialogStore } from '@/stores/dialogStore'
5 :
6 : import type {
7 : SettingDialogProps,
8 : SettingPanelType
9 : } from '@comfyorg/settings-core/types'
10 :
11 2356 : const DIALOG_KEY = 'global-settings'
12 :
13 2356 : let navigationRequestCount = 0
14 :
15 109 : function nextNavigationRequest(
16 : panel: SettingPanelType | undefined,
17 : settingId: string | undefined
18 : ): Partial<SettingDialogProps> | undefined {
19 109 : if (!panel && !settingId) return undefined
20 5 : navigationRequestCount += 1
21 109 : return {
22 : navigationRequestId: navigationRequestCount,
23 : ...(panel ? { defaultPanel: panel } : {}),
24 : ...(settingId ? { scrollToSettingId: settingId } : {})
25 : }
26 : }
27 :
28 : // The redesigned Settings dialog is 1280px wide (DES 3253-16079).
29 2356 : let settingDialogComponent: Component<SettingDialogProps> | undefined
30 :
31 : /**
32 : * The settings dialog subtree opens the settings dialog itself (billing
33 : * stores, top-up dialogs, confirmation content), so the composable cannot
34 : * import the component without an import cycle. The app shell registers it.
35 : */
36 2355 : export function registerSettingDialogComponent(
37 : component: Component<SettingDialogProps>
38 : ) {
39 2355 : settingDialogComponent = component
40 : }
41 :
42 19050 : export function useSettingsDialog() {
43 19050 : const dialogStore = useDialogStore()
44 :
45 14 : function hide() {
46 14 : dialogStore.closeDialog({ key: DIALOG_KEY })
47 : }
48 :
49 109 : function show(panel?: SettingPanelType, settingId?: string) {
50 109 : if (!settingDialogComponent) {
51 0 : reportError(new Error('Setting dialog component is not registered'), {
52 : errorType: 'failure_opening_settings_dialog',
53 : surface: 'platform'
54 : })
55 0 : return
56 : }
57 109 : const destination = nextNavigationRequest(panel, settingId)
58 109 : if (destination && dialogStore.isDialogOpen(DIALOG_KEY)) {
59 2 : dialogStore.updateDialog({
60 : key: DIALOG_KEY,
61 : contentProps: destination
62 : })
63 : }
64 109 : dialogStore.showDialog({
65 : key: DIALOG_KEY,
66 : component: settingDialogComponent,
67 : props: {
68 : onClose: hide,
69 : ...destination
70 : },
71 : dialogComponentProps: {
72 : headless: true,
73 : closable: true
74 : }
75 : })
76 : }
77 :
78 0 : function showAbout() {
79 0 : show('about')
80 : }
81 :
82 19050 : return { show, hide, showAbout }
83 : }
|