feat: Implement versioned default settings system

This commit is contained in:
Yiqun Xu
2025-06-11 04:07:33 -07:00
parent c02ac95815
commit f145a89c66
8 changed files with 110 additions and 5 deletions

View File

@@ -7,6 +7,7 @@ import { api } from '@/scripts/api'
import { app } from '@/scripts/app'
import type { SettingParams } from '@/types/settingTypes'
import type { TreeNode } from '@/types/treeExplorerTypes'
import { compareVersions } from '@/utils/versioning'
export const getSettingInfo = (setting: SettingParams) => {
const parts = setting.category || setting.id.split('.')
@@ -83,6 +84,29 @@ export const useSettingStore = defineStore('setting', () => {
*/
function getDefaultValue<K extends keyof Settings>(key: K): Settings[K] {
const param = settingsById.value[key]
// Check for versioned defaults based on installation version
if (param?.defaultsByInstallVersion) {
const installedVersion = get('Comfy.InstalledVersion')
if (installedVersion) {
// Find the highest version that is <= installedVersion
const sortedVersions = Object.keys(param.defaultsByInstallVersion).sort(
(a, b) => compareVersions(a, b)
)
for (const version of sortedVersions.reverse()) {
if (compareVersions(installedVersion, version) >= 0) {
const versionedDefault = param.defaultsByInstallVersion[version]
return typeof versionedDefault === 'function'
? versionedDefault()
: versionedDefault
}
}
}
}
// Fall back to original defaultValue
return typeof param?.defaultValue === 'function'
? param.defaultValue()
: param?.defaultValue