mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-03-10 07:30:08 +00:00
[Electron] ComfyUI server config (Launch args config) (#1644)
* Remove electron adapter server args * Add server args typing * Add server config constant file * Tooltip to name; name to id * Capitalize category * Server config store * Prevent default value * Add serverconfig test * Guard server config panel with electron flag * Filter nullish values from server args * Use slider for preview size
This commit is contained in:
73
src/stores/serverConfigStore.ts
Normal file
73
src/stores/serverConfigStore.ts
Normal file
@@ -0,0 +1,73 @@
|
||||
import { ServerConfig } from '@/constants/serverConfig'
|
||||
import { defineStore } from 'pinia'
|
||||
import { computed, ref } from 'vue'
|
||||
|
||||
export type ServerConfigWithValue<T> = ServerConfig<T> & {
|
||||
value: T
|
||||
}
|
||||
|
||||
export const useServerConfigStore = defineStore('serverConfig', () => {
|
||||
const serverConfigById = ref<Record<string, ServerConfigWithValue<any>>>({})
|
||||
const serverConfigs = computed(() => {
|
||||
return Object.values(serverConfigById.value)
|
||||
})
|
||||
const serverConfigsByCategory = computed<
|
||||
Record<string, ServerConfigWithValue<any>[]>
|
||||
>(() => {
|
||||
return serverConfigs.value.reduce(
|
||||
(acc, config) => {
|
||||
const category = config.category?.[0] ?? 'General'
|
||||
acc[category] = acc[category] || []
|
||||
acc[category].push(config)
|
||||
return acc
|
||||
},
|
||||
{} as Record<string, ServerConfigWithValue<any>[]>
|
||||
)
|
||||
})
|
||||
const serverConfigValues = computed<Record<string, any>>(() => {
|
||||
return Object.fromEntries(
|
||||
serverConfigs.value.map((config) => {
|
||||
return [
|
||||
config.id,
|
||||
config.value === config.defaultValue || !config.value
|
||||
? undefined
|
||||
: config.value
|
||||
]
|
||||
})
|
||||
)
|
||||
})
|
||||
const launchArgs = computed<Record<string, string>>(() => {
|
||||
return Object.assign(
|
||||
{},
|
||||
...serverConfigs.value.map((config) => {
|
||||
if (config.value === config.defaultValue || !config.value) {
|
||||
return {}
|
||||
}
|
||||
return config.getValue
|
||||
? config.getValue(config.value)
|
||||
: { [config.id]: config.value }
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
function loadServerConfig(
|
||||
configs: ServerConfig<any>[],
|
||||
values: Record<string, any>
|
||||
) {
|
||||
for (const config of configs) {
|
||||
serverConfigById.value[config.id] = {
|
||||
...config,
|
||||
value: values[config.id] ?? config.defaultValue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
serverConfigById,
|
||||
serverConfigs,
|
||||
serverConfigsByCategory,
|
||||
serverConfigValues,
|
||||
launchArgs,
|
||||
loadServerConfig
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user