Skip to content

Commit

Permalink
Fix node badge on unknown color palette (#1487)
Browse files Browse the repository at this point in the history
* Fix node badge on unknown color palette

* Update test expectations [skip ci]

---------

Co-authored-by: github-actions <[email protected]>
  • Loading branch information
huchenlei and github-actions authored Nov 9, 2024
1 parent f8ec87d commit 4617e0f
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 5 deletions.
2 changes: 1 addition & 1 deletion browser_tests/colorPalette.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ test.describe('Node Color Adjustments', () => {
await comfyPage.setSetting('Comfy.ColorPalette', 'light')
await comfyPage.setSetting('Comfy.Node.Opacity', 0.3)
const node = await comfyPage.getFirstNodeRef()
await node.clickContextMenuOption('Colors')
await node?.clickContextMenuOption('Colors')
})

test('should persist color adjustments when changing custom node colors', async ({
Expand Down
18 changes: 18 additions & 0 deletions browser_tests/nodeBadge.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,21 @@ test.describe('Node source badge', () => {
})
})
})

test.describe('Node badge color', () => {
test('Can show node badge with unknown color palette', async ({
comfyPage
}) => {
await comfyPage.setSetting(
'Comfy.NodeBadge.NodeIdBadgeMode',
NodeBadgeMode.ShowAll
)
await comfyPage.setSetting('Comfy.ColorPalette', 'unknown')
await comfyPage.nextFrame()
// Click empty space to trigger canvas re-render.
await comfyPage.clickEmptySpace()
await expect(comfyPage.canvas).toHaveScreenshot(
'node-badge-unknown-color-palette.png'
)
})
})
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 4 additions & 3 deletions src/components/graph/NodeBadge.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { LGraphBadge } from '@comfyorg/litegraph'
import _ from 'lodash'
import { NodeBadgeMode } from '@/types/nodeSource'
import { ComfyNodeDefImpl, useNodeDefStore } from '@/stores/nodeDefStore'
import type { Palette } from '@/types/colorPalette'
const settingStore = useSettingStore()
const nodeSourceBadgeMode = computed(
Expand All @@ -35,7 +36,7 @@ watch([nodeSourceBadgeMode, nodeIdBadgeMode, nodeLifeCycleBadgeMode], () => {
app.graph?.setDirtyCanvas(true, true)
})
const colorPalette = computed(() =>
const colorPalette = computed<Palette | undefined>(() =>
getColorPalette(settingStore.get('Comfy.ColorPalette'))
)
Expand Down Expand Up @@ -78,10 +79,10 @@ onMounted(() => {
}
),
fgColor:
colorPalette.value.colors.litegraph_base?.BADGE_FG_COLOR ||
colorPalette.value?.colors?.litegraph_base?.BADGE_FG_COLOR ||
defaultColorPalette.colors.litegraph_base.BADGE_FG_COLOR,
bgColor:
colorPalette.value.colors.litegraph_base?.BADGE_BG_COLOR ||
colorPalette.value?.colors?.litegraph_base?.BADGE_BG_COLOR ||
defaultColorPalette.colors.litegraph_base.BADGE_BG_COLOR
})
})
Expand Down
4 changes: 3 additions & 1 deletion src/extensions/core/colorPalette.ts
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,9 @@ const setCustomColorPalettes = (customColorPalettes: ColorPalettes) => {
}

export const defaultColorPalette = colorPalettes[defaultColorPaletteId]
export const getColorPalette = (colorPaletteId?) => {
export const getColorPalette = (
colorPaletteId?: string
): Palette | undefined => {
if (!colorPaletteId) {
colorPaletteId = app.ui.settings.getSettingValue(id, defaultColorPaletteId)
}
Expand Down

0 comments on commit 4617e0f

Please sign in to comment.