Skip to content

Feat/version default searchbox #4135

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/components/graph/GraphCanvas.vue
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,13 @@ onMounted(async () => {
CORE_SETTINGS.forEach((setting) => {
settingStore.addSetting(setting)
})
if (!settingStore.exists('Comfy.InstalledVersion')) {
const currentVersion =
Object.keys(settingStore.settingValues).length > 0
? ''
: __COMFYUI_FRONTEND_VERSION__
await settingStore.set('Comfy.InstalledVersion', currentVersion)
}
// @ts-expect-error fixme ts strict error
await comfyApp.setup(canvasRef.value)
canvasStore.canvas = comfyApp.canvas
Expand Down
12 changes: 11 additions & 1 deletion src/constants/coreSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ export const CORE_SETTINGS: SettingParams[] = [
name: 'Action on link release (No modifier)',
type: 'combo',
options: Object.values(LinkReleaseTriggerAction),
defaultValue: LinkReleaseTriggerAction.CONTEXT_MENU
defaultValue: LinkReleaseTriggerAction.CONTEXT_MENU,
defaultsByInstallVersion: {
'1.21.3': LinkReleaseTriggerAction.SEARCH_BOX
}
},
{
id: 'Comfy.LinkRelease.ActionShift',
Expand Down Expand Up @@ -747,6 +750,13 @@ export const CORE_SETTINGS: SettingParams[] = [
defaultValue: false,
versionAdded: '1.8.7'
},
{
id: 'Comfy.InstalledVersion',
name: 'Installed version',
type: 'hidden',
defaultValue: null,
versionAdded: '1.22.1'
},
{
id: 'LiteGraph.ContextMenu.Scaling',
name: 'Scale node combo widget menus (lists) when zoomed in',
Expand Down
2 changes: 2 additions & 0 deletions src/schemas/apiSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ const zSettings = z.object({
'Comfy.Toast.DisableReconnectingToast': z.boolean(),
'Comfy.Workflow.Persist': z.boolean(),
'Comfy.TutorialCompleted': z.boolean(),
'Comfy.InstalledVersion': z.string().nullable(),
'Comfy.Node.AllowImageSizeDraw': z.boolean(),
'Comfy-Desktop.AutoUpdate': z.boolean(),
'Comfy-Desktop.SendStatistics': z.boolean(),
Expand All @@ -471,6 +472,7 @@ const zSettings = z.object({
'VHS.AdvancedPreviews': z.string(),
/** Settings used for testing */
'test.setting': z.any(),
'test.versionedSetting': z.any(),
'main.sub.setting.name': z.any(),
'single.setting': z.any(),
'LiteGraph.Node.DefaultPadding': z.boolean(),
Expand Down
24 changes: 24 additions & 0 deletions src/stores/settingStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/formatUtil'

export const getSettingInfo = (setting: SettingParams) => {
const parts = setting.category || setting.id.split('.')
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/types/settingTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ export interface Setting {
export interface SettingParams extends FormItem {
id: keyof Settings
defaultValue: any | (() => any)
// Optional versioned defaults based on installation version
defaultsByInstallVersion?: Record<string, any | (() => any)>
onChange?: (newValue: any, oldValue?: any) => void
// By default category is id.split('.'). However, changing id to assign
// new category has poor backward compatibility. Use this field to overwrite
Expand Down
20 changes: 20 additions & 0 deletions tests-ui/tests/store/settingStore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,26 @@ describe('useSettingStore', () => {
expect(store.get('test.setting')).toBe('default')
})

it('should use versioned default based on installation version', () => {
// Set up an installed version
store.settingValues['Comfy.InstalledVersion'] = '1.25.0'

const setting: SettingParams = {
id: 'test.versionedSetting',
name: 'test.versionedSetting',
type: 'text',
defaultValue: 'original',
defaultsByInstallVersion: {
'1.20.0': 'version_1_20',
'1.24.0': 'version_1_24'
}
}
store.addSetting(setting)

// Should use the highest version <= installed version
expect(store.get('test.versionedSetting')).toBe('version_1_24')
})

it('should set value and trigger onChange', async () => {
const onChangeMock = vi.fn()
const dispatchChangeMock = vi.mocked(app.ui.settings.dispatchChange)
Expand Down