Files
ComfyUI_frontend/src/scripts/ui/settings.ts
Christian Byrne 27ab355f9c [refactor] Improve updates/notifications domain organization (#5590)
* [refactor] Move update-related functionality to platform/updates domain

Reorganizes release management, version compatibility, and notification functionality
following Domain-Driven Design principles, mirroring VSCode's architecture pattern.

- Move releaseService.ts to platform/updates/common/
- Move releaseStore.ts to platform/updates/common/
- Move versionCompatibilityStore.ts to platform/updates/common/
- Move useFrontendVersionMismatchWarning.ts to platform/updates/common/
- Move toastStore.ts to platform/updates/common/
- Move ReleaseNotificationToast.vue to platform/updates/components/
- Move WhatsNewPopup.vue to platform/updates/components/
- Update 25+ import paths across codebase and tests

This creates a cohesive "updates" domain containing all functionality related to
software updates, version checking, release notifications, and user communication
about application state changes.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* fix imports

---------

Co-authored-by: Claude <noreply@anthropic.com>
2025-09-15 04:34:37 -07:00

130 lines
2.9 KiB
TypeScript

import { t } from '@/i18n'
import { useSettingStore } from '@/platform/settings/settingStore'
import type { SettingParams } from '@/platform/settings/types'
import { useToastStore } from '@/platform/updates/common/toastStore'
import type { Settings } from '@/schemas/apiSchema'
import type { ComfyApp } from '@/scripts/app'
import { ComfyDialog } from './dialog'
export class ComfySettingsDialog extends ComfyDialog<HTMLDialogElement> {
app: ComfyApp
constructor(app: ComfyApp) {
super()
this.app = app
}
dispatchChange<T>(id: string, value: T, oldValue?: T) {
this.dispatchEvent(
new CustomEvent(id + '.change', {
detail: {
value,
oldValue
}
})
)
}
/**
* @deprecated Use `settingStore.settingValues` instead.
*/
get settingsValues() {
return useSettingStore().settingValues
}
/**
* @deprecated Use `settingStore.settingsById` instead.
*/
get settingsLookup() {
return useSettingStore().settingsById
}
/**
* @deprecated Use `settingStore.settingsById` instead.
*/
get settingsParamLookup() {
return useSettingStore().settingsById
}
/**
* @deprecated Use `settingStore.get` instead.
*/
getSettingValue<K extends keyof Settings>(
id: K,
defaultValue?: Settings[K]
): Settings[K] {
if (defaultValue !== undefined) {
console.warn(
`Parameter defaultValue is deprecated. The default value in settings definition will be used instead.`
)
}
return useSettingStore().get(id)
}
/**
* @deprecated Use `settingStore.getDefaultValue` instead.
*/
getSettingDefaultValue<K extends keyof Settings>(
id: K
): Settings[K] | undefined {
return useSettingStore().getDefaultValue(id)
}
/**
* @deprecated Use `settingStore.set` instead.
*/
async setSettingValueAsync<K extends keyof Settings>(
id: K,
value: Settings[K]
) {
await useSettingStore().set(id, value)
}
/**
* @deprecated Use `settingStore.set` instead.
*/
setSettingValue<K extends keyof Settings>(id: K, value: Settings[K]) {
useSettingStore()
.set(id, value)
.catch((err) => {
useToastStore().addAlert(
t('toastMessages.errorSaveSetting', { id, err })
)
})
}
/**
* @deprecated Deprecated for external callers/extensions. Use
* `ComfyExtension.settings` field instead.
*
* Example:
* ```ts
* app.registerExtension({
* name: 'My Extension',
* settings: [
* {
* id: 'My.Setting',
* name: 'My Setting',
* type: 'text',
* defaultValue: 'Hello, world!'
* }
* ]
* })
* ```
*/
addSetting(params: SettingParams) {
const settingStore = useSettingStore()
settingStore.addSetting(params)
return {
get value() {
return settingStore.get(params.id)
},
set value(v) {
settingStore.set(params.id, v)
}
}
}
}