Skip to content
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

Fix double trigger of loadColorPalette effect #2118

Merged
merged 3 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
13 changes: 11 additions & 2 deletions browser_tests/colorPalette.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,11 @@ const customColorPalettes = {
test.describe('Color Palette', () => {
test('Can show custom color palette', async ({ comfyPage }) => {
await comfyPage.setSetting('Comfy.CustomColorPalettes', customColorPalettes)
await comfyPage.setSetting('Comfy.ColorPalette', 'custom_obsidian_dark')
await comfyPage.nextFrame()
// Reload to apply the new setting. Setting Comfy.CustomColorPalettes directly
// doesn't update the store immediately.
await comfyPage.reload()

await comfyPage.setSetting('Comfy.ColorPalette', 'obsidian_dark')
await expect(comfyPage.canvas).toHaveScreenshot(
'custom-color-palette-obsidian-dark.png'
)
Expand All @@ -150,6 +153,12 @@ test.describe('Color Palette', () => {
}, customColorPalettes.obsidian_dark)
expect(await comfyPage.getToastErrorCount()).toBe(0)

await comfyPage.setSetting('Comfy.ColorPalette', 'obsidian_dark')
await comfyPage.nextFrame()
await expect(comfyPage.canvas).toHaveScreenshot(
'custom-color-palette-obsidian-dark.png'
)
// Legacy `custom_` prefix is still supported
await comfyPage.setSetting('Comfy.ColorPalette', 'custom_obsidian_dark')
await comfyPage.nextFrame()
await expect(comfyPage.canvas).toHaveScreenshot(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,20 @@ import { storeToRefs } from 'pinia'
import Button from 'primevue/button'
import Message from 'primevue/message'
import Select from 'primevue/select'
import { watch } from 'vue'

import { useColorPaletteService } from '@/services/colorPaletteService'
import { useSettingStore } from '@/stores/settingStore'
import { useColorPaletteStore } from '@/stores/workspace/colorPaletteStore'

const settingStore = useSettingStore()
const colorPaletteStore = useColorPaletteStore()
const colorPaletteService = useColorPaletteService()
const { palettes, activePaletteId } = storeToRefs(colorPaletteStore)

const importCustomPalette = async () => {
const palette = await colorPaletteService.importColorPalette()
if (palette) {
colorPaletteService.loadColorPalette(palette.id)
settingStore.set('Comfy.ColorPalette', palette.id)
}
}

watch(activePaletteId, () => {
colorPaletteService.loadColorPalette(activePaletteId.value)
})
</script>
19 changes: 14 additions & 5 deletions src/components/graph/GraphCanvas.vue
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,21 @@ watch(
)

const colorPaletteService = useColorPaletteService()
watchEffect(() => {
if (!canvasStore.canvas) return
const colorPaletteStore = useColorPaletteStore()
watch(
[() => canvasStore.canvas, () => settingStore.get('Comfy.ColorPalette')],
([canvas, currentPaletteId]) => {
if (!canvas) return

colorPaletteService.loadColorPalette(settingStore.get('Comfy.ColorPalette'))
})
colorPaletteService.loadColorPalette(currentPaletteId)
}
)
watch(
() => colorPaletteStore.activePaletteId,
(newValue) => {
settingStore.set('Comfy.ColorPalette', newValue)
}
)

const workflowStore = useWorkflowStore()
const persistCurrentWorkflow = () => {
Expand Down Expand Up @@ -343,7 +353,6 @@ onMounted(async () => {
comfyAppReady.value = true

// Load color palette
const colorPaletteStore = useColorPaletteStore()
colorPaletteStore.customPalettes = settingStore.get(
'Comfy.CustomColorPalettes'
)
Expand Down
6 changes: 5 additions & 1 deletion src/constants/coreSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,11 @@ export const CORE_SETTINGS: SettingParams[] = [
name: 'The active color palette id',
type: 'hidden',
defaultValue: 'dark',
versionModified: '1.6.7'
versionModified: '1.6.7',
migrateDeprecatedValue(value: string) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously custom color palettes' id was prefixed with custom_ when persisted to settings.

// Legacy custom palettes were prefixed with 'custom_'
return value.startsWith('custom_') ? value.replace('custom_', '') : value
}
},
{
id: 'Comfy.CustomColorPalettes',
Expand Down
3 changes: 1 addition & 2 deletions src/services/colorPaletteService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ export const useColorPaletteService = () => {
app.canvas.setDirty(true, true)

colorPaletteStore.activePaletteId = colorPaletteId
settingStore.set('Comfy.ColorPalette', colorPaletteId)
}

/**
Expand Down Expand Up @@ -180,7 +179,7 @@ export const useColorPaletteService = () => {
return {
addCustomColorPalette: wrapWithErrorHandling(addCustomColorPalette),
deleteCustomColorPalette: wrapWithErrorHandling(deleteCustomColorPalette),
loadColorPalette: wrapWithErrorHandling(loadColorPalette),
loadColorPalette: wrapWithErrorHandlingAsync(loadColorPalette),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix error handling of async func.

exportColorPalette: wrapWithErrorHandling(exportColorPalette),
importColorPalette: wrapWithErrorHandlingAsync(importColorPalette)
}
Expand Down
Loading