Skip to content
Merged
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
96 changes: 96 additions & 0 deletions src/renderer/src/panel/HomeView.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,102 @@ describe('Home builds', () => {
})
})

describe('Home build card while a build starts', () => {
const CARD_PADDING_AND_BORDER = 38
let observers: { target?: Element; report: (width: number) => void }[]
const originalResizeObserver = globalThis.ResizeObserver

beforeEach(() => {
observers = []
globalThis.ResizeObserver = class {
private readonly entry: { target?: Element; report: (width: number) => void }
constructor(callback: ResizeObserverCallback) {
this.entry = {
report: (width) =>
callback(
[
{
target: this.entry.target!,
contentRect: {
width: width - CARD_PADDING_AND_BORDER,
height: 98
} as DOMRectReadOnly,
contentBoxSize: [{ inlineSize: width - CARD_PADDING_AND_BORDER, blockSize: 98 }],
borderBoxSize: [{ inlineSize: width, blockSize: 100 }],
devicePixelContentBoxSize: []
} as unknown as ResizeObserverEntry
],
this as unknown as ResizeObserver
)
}
observers.push(this.entry)
}
observe(target: Element) {
this.entry.target = target
}
unobserve() {}
disconnect() {}
} as unknown as typeof ResizeObserver
Object.assign(window.api, {
onInstallProgress: vi.fn(() => () => {}),
onComfyOutput: vi.fn(() => () => {}),
cancelOperation: vi.fn(),
stopComfyUI: vi.fn()
})
})

afterEach(() => {
globalThis.ResizeObserver = originalResizeObserver
})

async function startBuildBesideTwoOthers(cardWidth: number) {
getInstallations.mockResolvedValue([OLDEST, CLOUD, NEWEST])
const wrapper = await openHome()
useProgressStore().startOperation({
installationId: NEWEST.id,
title: 'Starting',
opKind: 'launch',
apiCall: () => new Promise(() => {})
})
await flushPromises()
const starting = wrapper.get('[data-testid="home-build-starting"]')
const card = starting.get('[data-testid="home-build-busy-card"]')
for (const observer of observers) {
if (observer.target === card.element) observer.report(cardWidth)
}
await flushPromises()
return { wrapper, starting }
}

it('moves View logs and Cancel under a card in a row of three, so its name and status keep the room', async () => {
const { starting } = await startBuildBesideTwoOthers(300)

const card = starting.get('[data-testid="home-build-busy-card"]')
expect(card.find('[data-testid="home-build-cancel"]').exists()).toBe(false)
expect(card.find('[data-testid="home-build-view-logs"]').exists()).toBe(false)
expect(card.text()).toContain('Starting ComfyUI')
expect(card.text()).toContain(NEWEST.name)

await starting.get('[data-testid="home-build-cancel"]').trigger('click')
expect(window.api.cancelOperation).toHaveBeenCalledWith(NEWEST.id)
})

it('keeps View logs and Cancel inside a 460px card, counting its padding and border', async () => {
const { starting } = await startBuildBesideTwoOthers(460)

const card = starting.get('[data-testid="home-build-busy-card"]')
expect(card.find('[data-testid="home-build-cancel"]').exists()).toBe(true)
})

it('keeps View logs and Cancel inside a card that has room for them', async () => {
const { starting } = await startBuildBesideTwoOthers(560)

const card = starting.get('[data-testid="home-build-busy-card"]')
expect(card.find('[data-testid="home-build-view-logs"]').exists()).toBe(true)
expect(card.find('[data-testid="home-build-cancel"]').exists()).toBe(true)
})
})

describe('Home build auto start', () => {
let saved: unknown
let settingsListeners: Array<(change: { key: string }) => void>
Expand Down
37 changes: 37 additions & 0 deletions src/renderer/src/panel/home/HomeBuildBusyActions.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<script setup lang="ts">
import { useI18n } from 'vue-i18n'
import Button from '@comfyorg/design-system/button/Button'

defineProps<{ canViewLogs: boolean; cancelling?: boolean }>()

const emit = defineEmits<{ 'view-logs': []; cancel: [] }>()

const { t } = useI18n()
</script>

<template>
<span class="flex shrink-0 items-center gap-2">
<Button
v-if="canViewLogs"
type="button"
variant="muted-textonly"
size="unset"
class="h-8 rounded-lg px-3 text-[13px]/5 font-normal hover:bg-secondary hover:text-foreground"
data-testid="home-build-view-logs"
@click="emit('view-logs')"
>
{{ t('installProgress.viewLogs') }}
</Button>
<Button
type="button"
variant="secondary"
size="unset"
class="h-8 rounded-lg px-3 text-[13px]/5 font-normal"
:disabled="cancelling"
data-testid="home-build-cancel"
@click="emit('cancel')"
>
{{ t('common.cancel') }}
</Button>
</span>
</template>
138 changes: 71 additions & 67 deletions src/renderer/src/panel/home/HomeBuildCard.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<script setup lang="ts">
import { computed } from 'vue'
import { computed, useTemplateRef } from 'vue'
import { useI18n } from 'vue-i18n'
import { useElementSize } from '@vueuse/core'
import { Check, LoaderCircle, OctagonAlert } from '@lucide/vue'
import Button from '@comfyorg/design-system/button/Button'
import BuildDeviceArt from './BuildDeviceArt.vue'
import HomeBuildBusyActions from './HomeBuildBusyActions.vue'
import BuildProgressBar from './BuildProgressBar.vue'
import BuildAutoStartCheckbox from './BuildAutoStartCheckbox.vue'
import {
Expand Down Expand Up @@ -66,79 +67,82 @@ const detail = computed(() => {
if (busy.value) return install.detail.value
return isComfyCloud(build) ? t('home.cloudHardware') : homeBuildDetail(build)
})
const INLINE_ACTIONS_MIN_WIDTH = 448
const busyCard = useTemplateRef<HTMLElement>('busyCard')
const { width: busyCardWidth } = useElementSize(
busyCard,
{ width: 0, height: 0 },
{ box: 'border-box' }
)
const actionsBelowCard = computed(
() => busyCardWidth.value > 0 && busyCardWidth.value < INLINE_ACTIONS_MIN_WIDTH
)
const isLive = computed(() => !busy.value && (status === 'running' || status === 'always-on'))
const CARD_CLASS =
'group relative flex h-25 w-full items-center gap-[18px] overflow-hidden rounded-2xl border bg-[rgb(137_137_137/0.05)] px-[18px] text-left outline-none transition-colors'
</script>

<template>
<div
v-if="busy"
:class="CARD_CLASS"
:style="{ borderColor: `rgb(${toneStyle.border} / 0.1)` }"
:data-testid="busyTestId"
:data-build-id="build.id"
>
<span
class="pointer-events-none absolute inset-0"
:style="{
background: `radial-gradient(60% 130% at 8% 0%, rgb(${toneStyle.tint} / 0.3), rgb(${toneStyle.tint} / 0) 70%)`
}"
aria-hidden="true"
/>
<BuildDeviceArt
class="relative shrink-0"
:kind="buildDeviceKind(build)"
:glow="toneStyle.glow"
/>
<span class="relative flex min-w-0 flex-1 flex-col">
<span class="flex h-4 items-center gap-1.5 text-xs/4 text-muted-foreground">
<LoaderCircle
:size="12"
class="shrink-0 animate-spin [animation-duration:900ms] motion-reduce:animate-none"
aria-hidden="true"
/>
<span class="truncate">{{ statusLabel }}</span>
</span>
<span class="mt-1 truncate text-[15px]/[21px] font-semibold text-foreground">
{{ build.name }}
</span>
<div v-if="busy" class="flex flex-col gap-1" :data-testid="busyTestId" :data-build-id="build.id">
<div
ref="busyCard"
:class="CARD_CLASS"
:style="{ borderColor: `rgb(${toneStyle.border} / 0.1)` }"
data-testid="home-build-busy-card"
>
<span
class="mt-0.5 truncate text-xs/[17px] text-subtle-foreground"
data-testid="home-build-install-detail"
>
{{ detail }}
class="pointer-events-none absolute inset-0"
:style="{
background: `radial-gradient(60% 130% at 8% 0%, rgb(${toneStyle.tint} / 0.3), rgb(${toneStyle.tint} / 0) 70%)`
}"
aria-hidden="true"
/>
<BuildDeviceArt
class="relative shrink-0"
:kind="buildDeviceKind(build)"
:glow="toneStyle.glow"
/>
<span class="relative flex min-w-0 flex-1 flex-col">
<span class="flex h-4 items-center gap-1.5 text-xs/4 text-muted-foreground">
<LoaderCircle
:size="12"
class="shrink-0 animate-spin [animation-duration:900ms] motion-reduce:animate-none"
aria-hidden="true"
/>
<span class="truncate">{{ statusLabel }}</span>
</span>
<span class="mt-1 truncate text-[15px]/[21px] font-semibold text-foreground">
{{ build.name }}
</span>
<span
class="mt-0.5 truncate text-xs/[17px] text-subtle-foreground"
data-testid="home-build-install-detail"
>
{{ detail }}
</span>
</span>
</span>
<span class="relative flex shrink-0 items-center gap-2">
<Button
v-if="!uninstalling"
type="button"
variant="muted-textonly"
size="unset"
class="h-8 rounded-lg px-3 text-[13px]/5 font-normal hover:bg-secondary hover:text-foreground"
data-testid="home-build-view-logs"
@click="install.viewLogs"
>
{{ t('installProgress.viewLogs') }}
</Button>
<Button
type="button"
variant="secondary"
size="unset"
class="h-8 rounded-lg px-3 text-[13px]/5 font-normal"
:disabled="install.progress.value?.cancelling"
data-testid="home-build-cancel"
@click="install.cancel"
>
{{ t('common.cancel') }}
</Button>
</span>
<BuildProgressBar
v-if="install.progress.value?.percent != null"
:percent="install.progress.value.percent"
:label="statusLabel"
data-testid="home-build-progress"
<HomeBuildBusyActions
v-if="!actionsBelowCard"
class="relative"
:can-view-logs="!uninstalling"
:cancelling="install.progress.value?.cancelling"
@view-logs="install.viewLogs"
@cancel="install.cancel"
/>
<BuildProgressBar
v-if="install.progress.value?.percent != null"
:percent="install.progress.value.percent"
:label="statusLabel"
data-testid="home-build-progress"
/>
</div>
<HomeBuildBusyActions
v-if="actionsBelowCard"
class="self-end"
:can-view-logs="!uninstalling"
:cancelling="install.progress.value?.cancelling"
@view-logs="install.viewLogs"
@cancel="install.cancel"
/>
</div>
<div v-else class="flex flex-col gap-1">
Expand Down
Loading