From 005b42fbb7b71042b7966bc66ec937eb755dcefc Mon Sep 17 00:00:00 2001 From: Mariana Martinho Date: Sat, 14 Nov 2026 22:50:24 +0100 Subject: [PATCH 01/32] fix(home): keep a starting build's name and status readable, and drop the folder from Home tiles While a build starts or installs, its Home card put View logs and Cancel beside the text, which squeezed the name and status to nothing at every width. The actions now sit on their own row under the name, and the device picture steps aside when the builds grid is narrow, so the card keeps its size and the text has room. The tile subtitle no longer shows the install folder, which was always cut off; it shows the ComfyUI version (or the source when there is none). --- locales/en.json | 1 - locales/zh.json | 1 - .../src/composables/useBuildProgress.ts | 14 +- .../src/panel/HomeBuildsLayout.test.ts | 128 ++++++++++++++++++ src/renderer/src/panel/HomeView.test.ts | 4 +- src/renderer/src/panel/home/HomeBuildCard.vue | 70 +++++----- src/renderer/src/panel/home/homeBuild.ts | 3 +- 7 files changed, 167 insertions(+), 54 deletions(-) create mode 100644 src/renderer/src/panel/HomeBuildsLayout.test.ts diff --git a/locales/en.json b/locales/en.json index 4d27f7c14..8e339a11d 100644 --- a/locales/en.json +++ b/locales/en.json @@ -889,7 +889,6 @@ "useMyBuilds": "Use my builds" }, "installProgress": { - "detail": "{phase} · {percent}%", "starting": "Starting…", "cancelling": "Cancelling…", "percent": "{percent}%", diff --git a/locales/zh.json b/locales/zh.json index 5d20826c3..fa8553095 100644 --- a/locales/zh.json +++ b/locales/zh.json @@ -889,7 +889,6 @@ "useMyBuilds": "使用我的版本" }, "installProgress": { - "detail": "{phase} · {percent}%", "starting": "正在开始…", "cancelling": "正在取消…", "percent": "{percent}%", diff --git a/src/renderer/src/composables/useBuildProgress.ts b/src/renderer/src/composables/useBuildProgress.ts index 4c5fea17f..1c7528689 100644 --- a/src/renderer/src/composables/useBuildProgress.ts +++ b/src/renderer/src/composables/useBuildProgress.ts @@ -9,7 +9,6 @@ export type BuildProgressKind = 'install' | 'launch' export interface BuildProgress { kind: BuildProgressKind percent: number | null - phase: string cancelling: boolean } @@ -34,7 +33,6 @@ export function buildProgressOf( return { kind: 'launch', percent: op.flatPercent >= 0 ? Math.round(op.flatPercent) : null, - phase: op.steps?.find((step) => step.phase === op.activePhase)?.label ?? op.flatStatus, cancelling: op.cancelRequested } } @@ -42,7 +40,6 @@ export function buildProgressOf( return { kind: 'install', percent: Math.round(percent), - phase: op.steps?.find((step) => step.phase === op.activePhase)?.label ?? '', cancelling: op.cancelRequested } } @@ -62,7 +59,6 @@ export function useInstallingBuilds(): (installationId: string) => boolean { export function useBuildProgress(build: () => Installation): { progress: ComputedRef - detail: ComputedRef viewLogs: () => void cancel: () => Promise } { @@ -72,14 +68,6 @@ export function useBuildProgress(build: () => Installation): { const view = useViewBuildLogs() const progress = computed(() => buildProgressOf(progressStore, build().id)) - const detail = computed(() => { - const current = progress.value - if (!current) return '' - if (current.cancelling) return t('installProgress.cancelling') - if (!current.phase) return t('installProgress.starting') - if (current.percent === null) return current.phase - return t('installProgress.detail', { phase: current.phase, percent: current.percent }) - }) function viewLogs(): void { view(build().id) @@ -100,5 +88,5 @@ export function useBuildProgress(build: () => Installation): { if (confirmed) progressStore.cancelOperation(current.id) } - return { progress, detail, viewLogs, cancel } + return { progress, viewLogs, cancel } } diff --git a/src/renderer/src/panel/HomeBuildsLayout.test.ts b/src/renderer/src/panel/HomeBuildsLayout.test.ts new file mode 100644 index 000000000..4be36ba62 --- /dev/null +++ b/src/renderer/src/panel/HomeBuildsLayout.test.ts @@ -0,0 +1,128 @@ +import { beforeAll, beforeEach, describe, expect, it, vi } from 'vitest' +import { page as browserPage } from 'vitest/browser' +import { flushPromises, mount } from '@vue/test-utils' +import { createPinia, setActivePinia } from 'pinia' + +import '../assets/main.css' +import HomeView from './HomeView.vue' +import { useProgressStore, type Operation } from '../stores/progressStore' +import type { Installation } from '../types/ipc' + +const MIN_WINDOW_BUILDS_WIDTH = 452 +const NORMAL_WINDOW_BUILDS_WIDTH = 932 + +const STARTING: Installation = { + id: 'starting', + name: 'My ComfyUI Build', + sourceLabel: 'Standalone', + sourceCategory: 'local', + version: 'v0.3.68', + installPath: '/Users/someone/Documents/ComfyUI/Builds/My ComfyUI Build', + lastLaunchedAt: 300 +} +const READY: Installation = { + id: 'ready', + name: 'Flux Sandbox', + sourceLabel: 'Standalone', + sourceCategory: 'local', + version: 'v0.42.4', + installPath: '/Users/someone/Documents/ComfyUI/Builds/Flux Sandbox', + lastLaunchedAt: 200 +} +const CLOUD: Installation = { + id: 'cloud', + name: 'Comfy Cloud', + sourceId: 'cloud', + sourceLabel: 'Cloud', + sourceCategory: 'cloud', + lastLaunchedAt: 100 +} + +let host: HTMLElement + +beforeAll(() => browserPage.viewport(1440, 900)) + +beforeEach(() => { + host = document.createElement('div') + host.style.cssText = 'position: fixed; left: 0; top: 0; width: 1200px; height: 900px' + document.body.append(host) + ;(window as unknown as { api: unknown }).api = { + listHomeWorkflows: vi.fn().mockResolvedValue([]), + openCatalogWorkflow: vi.fn().mockResolvedValue(true), + getAppsEnabled: vi.fn().mockResolvedValue(false), + getInstallations: vi.fn().mockResolvedValue([STARTING, READY, CLOUD]), + onInstallationsChanged: vi.fn(() => () => {}), + onInstallationsVersionsUpdated: vi.fn(() => () => {}), + getSetting: vi.fn().mockResolvedValue(undefined), + setSetting: vi.fn().mockResolvedValue(undefined), + onSettingsChanged: vi.fn(() => () => {}), + comfybuilder: { + getAuthStatus: vi.fn().mockResolvedValue({ signedIn: false }), + onAuthChanged: vi.fn(() => () => {}) + } + } + setActivePinia(createPinia()) +}) + +async function homeWithStartingBuild() { + const wrapper = mount(HomeView, { attachTo: host }) + await flushPromises() + useProgressStore().operations.set(STARTING.id, { + opKind: 'launch', + finished: false, + flatPercent: 5, + cancelRequested: false + } as Operation) + await flushPromises() + return wrapper +} + +async function layBuildsOut(width: number): Promise { + const section = host.querySelector('[data-testid="home-builds"]')! + section.style.width = `${width}px` + await new Promise((resolve) => requestAnimationFrame(() => requestAnimationFrame(resolve))) + return section +} + +function fullyShown(element: Element): boolean { + return element.scrollWidth <= element.clientWidth && element.clientWidth > 0 +} + +describe('Home build cards', () => { + it.each([ + ['at the minimum window width', MIN_WINDOW_BUILDS_WIDTH], + ['at a normal window width', NORMAL_WINDOW_BUILDS_WIDTH] + ])( + 'show the whole name and status of a starting build %s, in a card shaped like the others', + async (_name, width) => { + const wrapper = await homeWithStartingBuild() + const section = await layBuildsOut(width) + const card = section.querySelector('[data-testid="home-build-starting"]')! + const status = card.querySelector('[data-testid="home-build-status"] .truncate')! + const name = card.querySelector('[data-testid="home-build-name"]')! + const cardBox = card.getBoundingClientRect() + + expect(status.textContent?.trim()).toBe('Starting ComfyUI') + expect(fullyShown(status)).toBe(true) + expect(name.textContent?.trim()).toBe(STARTING.name) + expect(fullyShown(name)).toBe(true) + for (const action of ['home-build-view-logs', 'home-build-cancel']) { + const box = card.querySelector(`[data-testid="${action}"]`)!.getBoundingClientRect() + expect(box.width).toBeGreaterThan(0) + expect(box.left).toBeGreaterThanOrEqual(cardBox.left) + expect(box.right).toBeLessThanOrEqual(cardBox.right) + expect(box.bottom).toBeLessThanOrEqual(cardBox.bottom) + } + const shown = [...section.querySelectorAll('li')].filter( + (item) => getComputedStyle(item).display !== 'none' + ) + expect(shown.length).toBeGreaterThan(1) + for (const item of shown) { + const box = item.firstElementChild!.getBoundingClientRect() + expect(box.height).toBe(cardBox.height) + expect(box.width).toBeCloseTo(cardBox.width, 0) + } + wrapper.unmount() + } + ) +}) diff --git a/src/renderer/src/panel/HomeView.test.ts b/src/renderer/src/panel/HomeView.test.ts index 9dc075db4..f12fec338 100644 --- a/src/renderer/src/panel/HomeView.test.ts +++ b/src/renderer/src/panel/HomeView.test.ts @@ -460,12 +460,12 @@ describe('Home builds', () => { expect(kept).toEqual(['My Local 1', 'Video Lab']) }) - it('shows a stopped local build as ready, with its ComfyUI version and folder', async () => { + it('shows a stopped local build as ready, with its ComfyUI version and no folder', async () => { getInstallations.mockResolvedValue([OLDEST]) const wrapper = await openHome() expect(wrapper.get('[data-testid="home-build"]').text()).toBe( - 'ReadyFlux SandboxComfyUI v0.42.4 · /Users/pablo/ComfyUI-Installs/Flux' + 'ReadyFlux SandboxComfyUI v0.42.4' ) }) diff --git a/src/renderer/src/panel/home/HomeBuildCard.vue b/src/renderer/src/panel/home/HomeBuildCard.vue index b7fdaba8d..e6f65e5d6 100644 --- a/src/renderer/src/panel/home/HomeBuildCard.vue +++ b/src/renderer/src/panel/home/HomeBuildCard.vue @@ -36,6 +36,7 @@ const broken = computed(() => { const toneStyle = computed(() => HOME_BUILD_TONES[tone]) const statusLabel = computed(() => { + if (install.progress.value?.cancelling) return t('installProgress.cancelling') if (installing.value) return t(starting.value ? 'home.buildStartingComfyUI' : 'home.buildInstalling') if (broken.value) return broken.value @@ -54,10 +55,9 @@ const statusLabel = computed(() => { return status satisfies never } }) -const detail = computed(() => { - if (installing.value) return install.detail.value - return isComfyCloud(build) ? t('home.cloudHardware') : homeBuildDetail(build) -}) +const detail = computed(() => + isComfyCloud(build) ? t('home.cloudHardware') : homeBuildDetail(build) +) const isLive = computed(() => !installing.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' @@ -79,12 +79,15 @@ const CARD_CLASS = aria-hidden="true" /> - + {{ statusLabel }} - - {{ build.name }} - - {{ detail }} + {{ build.name }} + + + + - - - - Date: Sun, 15 Nov 2026 09:57:01 +0100 Subject: [PATCH 02/32] feat(home): stack build tiles when narrow, one build menu for Home and the sidebar Home's build tiles go to one per row when two no longer fit their name and status, and keep three in a row on wide windows. A starting or installing tile looks like every other tile: status with percent, name, ComfyUI version and the progress bar. Clicking it opens the logs. Every Home tile shows a More button on hover, and a right-click on a tile or on a build in the sidebar opens the same menu: what the build can do now (Launch; View logs and Cancel; View logs, Restart and Stop), Open in new window, the existing build menu items, then Uninstall, which asks inside the menu. A right-click on Home in the sidebar offers Open in new window. --- src/preload/api.ts | 1 + .../src/composables/useInstallContextMenu.ts | 25 +- src/renderer/src/panel/AppSidebar.vue | 50 +++- .../src/panel/HomeBuildsLayout.test.ts | 104 +++++--- src/renderer/src/panel/HomeView.vue | 7 +- src/renderer/src/panel/PanelApp.test.ts | 2 +- src/renderer/src/panel/PanelApp.vue | 10 + src/renderer/src/panel/home/BuildMenu.test.ts | 241 ++++++++++++++++++ src/renderer/src/panel/home/BuildMenu.vue | 117 +++++++++ src/renderer/src/panel/home/HomeBuildCard.vue | 179 +++++++------ src/renderer/src/panel/home/useBuildMenu.ts | 161 ++++++++++++ src/types/ipc.ts | 1 + 12 files changed, 763 insertions(+), 135 deletions(-) create mode 100644 src/renderer/src/panel/home/BuildMenu.test.ts create mode 100644 src/renderer/src/panel/home/BuildMenu.vue create mode 100644 src/renderer/src/panel/home/useBuildMenu.ts diff --git a/src/preload/api.ts b/src/preload/api.ts index 8415ca9f2..ef396c3f0 100644 --- a/src/preload/api.ts +++ b/src/preload/api.ts @@ -88,6 +88,7 @@ export function buildElectronApi(): ElectronApi { terminalRestart: (installationId) => ipcRenderer.invoke('terminal-restart', installationId), openInstallInNewWindow: (installationId) => ipcRenderer.send('comfy-window:open-install-new-window', installationId), + openDashboardInNewWindow: () => ipcRenderer.send('comfy-window:new-chooser-window'), openInstallWindow: (installationId) => ipcRenderer.invoke('open-install-window', installationId), closeComfyWindow: (installationId, opts) => diff --git a/src/renderer/src/composables/useInstallContextMenu.ts b/src/renderer/src/composables/useInstallContextMenu.ts index be7b1c085..8b6e9215a 100644 --- a/src/renderer/src/composables/useInstallContextMenu.ts +++ b/src/renderer/src/composables/useInstallContextMenu.ts @@ -260,7 +260,11 @@ export function useInstallContextMenu( } } - async function triggerAction(id: string, inst: Installation): Promise { + async function triggerAction( + id: string, + inst: Installation, + actionOpts: { confirmed?: boolean } = {} + ): Promise { if (id === 'manage') { opts.onManage?.(inst) } else if (id === 'update') { @@ -315,14 +319,16 @@ export function useInstallContextMenu( } else if (id === 'delete') { if (opts.onShowProgress) { const deleteLabel = t('actions.delete') - const confirmed = await modal.confirm({ - title: t('actions.deleteConfirmTitle'), - message: `${inst.installPath ? inst.installPath + '\n\n' : ''}${t( - 'actions.deleteConfirmMessage' - )}\n\n${t('actions.deleteConfirmDetail')}`, - confirmLabel: deleteLabel, - confirmStyle: 'danger' - }) + const confirmed = + actionOpts.confirmed === true || + (await modal.confirm({ + title: t('actions.deleteConfirmTitle'), + message: `${inst.installPath ? inst.installPath + '\n\n' : ''}${t( + 'actions.deleteConfirmMessage' + )}\n\n${t('actions.deleteConfirmDetail')}`, + confirmLabel: deleteLabel, + confirmStyle: 'danger' + })) if (!confirmed) return opts.onShowProgress({ installationId: inst.id, @@ -385,6 +391,7 @@ export function useInstallContextMenu( return { ctxMenu, ctxMenuItems, + getMenuItems, openCardMenu, openKebabMenu, handleCtxMenuSelect, diff --git a/src/renderer/src/panel/AppSidebar.vue b/src/renderer/src/panel/AppSidebar.vue index ecc49da2c..0d7667347 100644 --- a/src/renderer/src/panel/AppSidebar.vue +++ b/src/renderer/src/panel/AppSidebar.vue @@ -1,5 +1,5 @@ diff --git a/src/renderer/src/panel/HomeBuildsLayout.test.ts b/src/renderer/src/panel/HomeBuildsLayout.test.ts index 4be36ba62..912f432d8 100644 --- a/src/renderer/src/panel/HomeBuildsLayout.test.ts +++ b/src/renderer/src/panel/HomeBuildsLayout.test.ts @@ -64,15 +64,24 @@ beforeEach(() => { setActivePinia(createPinia()) }) -async function homeWithStartingBuild() { +type BuildState = 'starting' | 'installing' | 'uninstalling' | 'ready' + +const OPERATIONS: Record, Partial> = { + starting: { opKind: 'launch', flatPercent: 5 }, + installing: { opKind: 'install', flatPercent: 40 }, + uninstalling: { opKind: 'destructive', flatPercent: 18 } +} + +async function homeWithBuildIn(state: BuildState) { const wrapper = mount(HomeView, { attachTo: host }) await flushPromises() - useProgressStore().operations.set(STARTING.id, { - opKind: 'launch', - finished: false, - flatPercent: 5, - cancelRequested: false - } as Operation) + if (state !== 'ready') { + useProgressStore().operations.set(STARTING.id, { + finished: false, + cancelRequested: false, + ...OPERATIONS[state] + } as Operation) + } await flushPromises() return wrapper } @@ -88,41 +97,74 @@ function fullyShown(element: Element): boolean { return element.scrollWidth <= element.clientWidth && element.clientWidth > 0 } -describe('Home build cards', () => { +function shownTiles(section: HTMLElement): HTMLElement[] { + return [...section.querySelectorAll('li')] + .filter((item) => getComputedStyle(item).display !== 'none') + .map((item) => item.firstElementChild as HTMLElement) +} + +function columnsOf(section: HTMLElement): number { + return getComputedStyle(section.querySelector('ul')!).gridTemplateColumns.split(' ').length +} + +describe('Home build tiles', () => { it.each([ - ['at the minimum window width', MIN_WINDOW_BUILDS_WIDTH], - ['at a normal window width', NORMAL_WINDOW_BUILDS_WIDTH] + ['the minimum window width', 1, MIN_WINDOW_BUILDS_WIDTH], + ['a normal window width', 3, NORMAL_WINDOW_BUILDS_WIDTH] ])( - 'show the whole name and status of a starting build %s, in a card shaped like the others', - async (_name, width) => { - const wrapper = await homeWithStartingBuild() + 'at %s, sit %i per row and show the whole name and status of a starting build', + async (_name, columns, width) => { + const wrapper = await homeWithBuildIn('starting') const section = await layBuildsOut(width) - const card = section.querySelector('[data-testid="home-build-starting"]')! + const card = section.querySelector('[data-testid="home-build-starting"]')! const status = card.querySelector('[data-testid="home-build-status"] .truncate')! const name = card.querySelector('[data-testid="home-build-name"]')! - const cardBox = card.getBoundingClientRect() - expect(status.textContent?.trim()).toBe('Starting ComfyUI') + expect(columnsOf(section)).toBe(columns) + expect(status.textContent?.trim()).toBe('Starting ComfyUI · 5%') expect(fullyShown(status)).toBe(true) expect(name.textContent?.trim()).toBe(STARTING.name) expect(fullyShown(name)).toBe(true) - for (const action of ['home-build-view-logs', 'home-build-cancel']) { - const box = card.querySelector(`[data-testid="${action}"]`)!.getBoundingClientRect() - expect(box.width).toBeGreaterThan(0) - expect(box.left).toBeGreaterThanOrEqual(cardBox.left) - expect(box.right).toBeLessThanOrEqual(cardBox.right) - expect(box.bottom).toBeLessThanOrEqual(cardBox.bottom) - } - const shown = [...section.querySelectorAll('li')].filter( - (item) => getComputedStyle(item).display !== 'none' - ) - expect(shown.length).toBeGreaterThan(1) - for (const item of shown) { - const box = item.firstElementChild!.getBoundingClientRect() - expect(box.height).toBe(cardBox.height) - expect(box.width).toBeCloseTo(cardBox.width, 0) + expect( + card.querySelector( + 'button:not([data-testid="home-build-more"]):not([data-testid="home-build-open"])' + ) + ).toBeNull() + + const tiles = shownTiles(section) + expect(tiles.length).toBeGreaterThan(1) + const rows = new Set(tiles.map((tile) => Math.round(tile.getBoundingClientRect().top))) + expect(rows.size).toBe(Math.ceil(tiles.length / columns)) + for (const tile of tiles) { + expect(tile.getBoundingClientRect().width).toBeCloseTo( + card.getBoundingClientRect().width, + 0 + ) } wrapper.unmount() } ) + + it.each( + (['starting', 'installing', 'uninstalling', 'ready'] as const).flatMap((state) => [ + [state, MIN_WINDOW_BUILDS_WIDTH] as const, + [state, NORMAL_WINDOW_BUILDS_WIDTH] as const + ]) + )('keep one height when a build is %s, at %ipx', async (state, width) => { + const wrapper = await homeWithBuildIn(state) + const section = await layBuildsOut(width) + const tiles = shownTiles(section) + const more = tiles[0]!.querySelector('[data-testid="home-build-more"]')! + + expect(tiles[0]!.getAttribute('data-build-id')).toBe(STARTING.id) + expect(tiles[0]!.getAttribute('data-testid')).toBe( + state === 'ready' ? 'home-build' : `home-build-${state}` + ) + for (const tile of tiles) expect(tile.getBoundingClientRect().height).toBe(100) + const tileBox = tiles[0]!.getBoundingClientRect() + const moreBox = more.getBoundingClientRect() + expect(moreBox.right).toBeLessThanOrEqual(tileBox.right) + expect(moreBox.top + moreBox.height / 2).toBeCloseTo(tileBox.top + tileBox.height / 2, 0) + wrapper.unmount() + }) }) diff --git a/src/renderer/src/panel/HomeView.vue b/src/renderer/src/panel/HomeView.vue index 911983df5..fc91cd518 100644 --- a/src/renderer/src/panel/HomeView.vue +++ b/src/renderer/src/panel/HomeView.vue @@ -256,9 +256,10 @@ onMounted(() => {
  • { expect(card.text()).toContain('Installing ComfyUI') expect(wrapper.find('[data-testid="home-open-build"]').exists()).toBe(false) - await wrapper.get('[data-testid="home-build-view-logs"]').trigger('click') + await card.trigger('click') await flushPromises() const dialog = () => document.body.querySelector('[data-testid="build-progress-dialog"]') expect(dialog()).not.toBeNull() diff --git a/src/renderer/src/panel/PanelApp.vue b/src/renderer/src/panel/PanelApp.vue index f4d57d20a..ddfdcc668 100644 --- a/src/renderer/src/panel/PanelApp.vue +++ b/src/renderer/src/panel/PanelApp.vue @@ -51,6 +51,7 @@ import { } from '../lib/progressTerminalPresets' import { useThumbnailPrefetch } from '../composables/useThumbnailPrefetch' import { provideBuildLogs } from '../composables/useBuildProgress' +import { provideBuildMenuHost } from './home/useBuildMenu' import { focusRunningBuild } from '../lib/focusRunningBuild' import type { AppCard, DashboardPage, Installation } from '../types/ipc' @@ -276,6 +277,15 @@ chooserHandoff = useChooserHandoff({ }) const { handleChooserPick, handleChooserShowNewInstall } = chooserHandoff +provideBuildMenuHost({ + launch: async (inst, launchOpts) => { + if (await focusRunningBuild(inst)) return + await handleChooserPick(inst, launchOpts) + }, + openDetails: openBuildFromSidebar, + showProgress: handleShowProgress +}) + async function handleStartupRestorePick(inst: Installation): Promise { try { const outcome = await chooserHandoff.performChooserLaunch(inst, undefined, { inPlace: true }) diff --git a/src/renderer/src/panel/home/BuildMenu.test.ts b/src/renderer/src/panel/home/BuildMenu.test.ts new file mode 100644 index 000000000..553502d54 --- /dev/null +++ b/src/renderer/src/panel/home/BuildMenu.test.ts @@ -0,0 +1,241 @@ +import { beforeEach, describe, expect, it, vi } from 'vitest' +import { defineComponent, h } from 'vue' +import { flushPromises, mount, type VueWrapper } from '@vue/test-utils' +import { createPinia, setActivePinia } from 'pinia' + +import AppSidebar from '../AppSidebar.vue' +import HomeBuildCard from './HomeBuildCard.vue' +import { provideBuildMenuHost, type BuildMenuHost } from './useBuildMenu' +import { provideBuildLogs } from '../../composables/useBuildProgress' +import { useInstallationStore } from '../../stores/installationStore' +import { useProgressStore, type Operation } from '../../stores/progressStore' +import { useSessionStore } from '../../stores/sessionStore' +import type { Installation } from '../../types/ipc' + +const BUILD: Installation = { + id: 'flux', + name: 'Flux Sandbox', + sourceId: 'standalone', + sourceLabel: 'Standalone', + sourceCategory: 'local', + status: 'installed', + version: 'v0.42.4', + installPath: '/Users/someone/ComfyUI/Flux Sandbox' +} + +type State = 'ready' | 'starting' | 'installing' | 'running' | 'uninstalling' + +const REST = ['|', 'manage', 'copy-install', 'reveal-in-folder', '|', 'share', 'restore-snapshot'] +const EXPECTED: Record = { + ready: ['launch', '|', 'open-new-window', ...REST, '|', 'delete'], + starting: ['view-logs', 'cancel', ...REST, '|', 'delete'], + installing: ['view-logs', 'cancel', ...REST, '|', 'delete'], + running: ['view-logs', 'restart', 'stop', '|', 'open-new-window', ...REST, '|', 'delete'], + uninstalling: ['cancel', ...REST, '|', 'delete'] +} +const OPERATIONS: Partial>> = { + starting: { opKind: 'launch', flatPercent: 5 }, + installing: { opKind: 'install', flatPercent: 40 }, + uninstalling: { opKind: 'destructive', flatPercent: 18 } +} + +let host: BuildMenuHost & { [K in keyof BuildMenuHost]: ReturnType } +const mounted: VueWrapper[] = [] +const viewLogs = vi.fn() + +beforeEach(() => { + for (const wrapper of mounted.splice(0)) wrapper.unmount() + document.body.innerHTML = '' + ;(window as unknown as { api: unknown }).api = { + platform: 'darwin', + navigatePanel: vi.fn(), + getAppsEnabled: vi.fn().mockResolvedValue(false), + getInstallations: vi.fn().mockResolvedValue([]), + onInstallationsChanged: vi.fn(() => () => {}), + onInstallationsVersionsUpdated: vi.fn(() => () => {}), + getSetting: vi.fn().mockResolvedValue(undefined), + setSetting: vi.fn().mockResolvedValue(undefined), + onSettingsChanged: vi.fn(() => () => {}), + openInstallInNewWindow: vi.fn(), + openDashboardInNewWindow: vi.fn(), + comfybuilder: { + getAuthStatus: vi.fn().mockResolvedValue({ signedIn: false }), + onAuthChanged: vi.fn(() => () => {}) + } + } + host = { launch: vi.fn(), openDetails: vi.fn(), showProgress: vi.fn() } + viewLogs.mockReset() + setActivePinia(createPinia()) + useInstallationStore().installations = [BUILD] +}) + +function withHost(render: () => ReturnType) { + return defineComponent({ + setup() { + provideBuildMenuHost(host) + provideBuildLogs(viewLogs) + return render + } + }) +} + +function putIn(state: State): void { + const operation = OPERATIONS[state] + if (operation) { + useProgressStore().operations.set(BUILD.id, { + finished: false, + cancelRequested: false, + ...operation + } as Operation) + } + if (state === 'running') { + useSessionStore().runningInstances.set(BUILD.id, { + installationId: BUILD.id + } as never) + } +} + +async function mountTile(state: State): Promise { + const wrapper = mount( + withHost(() => h(HomeBuildCard, { build: BUILD, status: 'ready', tone: 'ember' })), + { attachTo: document.body } + ) + mounted.push(wrapper) + putIn(state) + await flushPromises() + return wrapper +} + +async function mountSidebar(state: State): Promise { + const wrapper = mount( + withHost(() => h(AppSidebar, { activePage: 'home' })), + { attachTo: document.body } + ) + mounted.push(wrapper) + putIn(state) + await flushPromises() + return wrapper +} + +async function shownMenu(): Promise { + await flushPromises() + await vi.waitFor(() => { + expect(document.querySelector('[data-testid="build-menu"]')).not.toBeNull() + }) + const menu = document.querySelector('[data-testid="build-menu"]')! + return [...menu.querySelectorAll('[role="menuitem"], [role="separator"]')].map((row) => + row.getAttribute('role') === 'separator' + ? '|' + : row.getAttribute('data-testid')!.replace('build-menu-', '') + ) +} + +async function closeMenu(): Promise { + document + .querySelector('[data-testid="build-menu"]') + ?.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape', bubbles: true })) + await flushPromises() + await vi.waitFor(() => { + expect(document.querySelector('[data-testid="build-menu"]')).toBeNull() + }) +} + +async function rightClick(element: Element): Promise { + element.dispatchEvent( + new MouseEvent('contextmenu', { bubbles: true, cancelable: true, clientX: 40, clientY: 40 }) + ) + await flushPromises() +} + +describe('Build menu', () => { + it.each(Object.keys(EXPECTED) as State[])( + 'lists what a %s build can do now first, Uninstall last', + async (state) => { + const tile = await mountTile(state) + + await tile.get('[data-testid="home-build-more"]').trigger('click') + + expect(await shownMenu()).toEqual(EXPECTED[state]) + } + ) + + it.each(Object.keys(EXPECTED) as State[])( + 'opens the same items from the tile ⋯, a right-click on the tile and on the sidebar row for a %s build', + async (state) => { + const tile = await mountTile(state) + await tile.get('[data-testid="home-build-more"]').trigger('click') + const fromMore = await shownMenu() + await closeMenu() + + await rightClick(tile.get(`[data-build-id="${BUILD.id}"]`).element) + const fromTile = await shownMenu() + await closeMenu() + + const sidebar = await mountSidebar(state) + await rightClick(sidebar.get(`[data-testid="app-sidebar-build-${BUILD.id}"]`).element) + const fromSidebar = await shownMenu() + + expect(fromTile).toEqual(fromMore) + expect(fromSidebar).toEqual(fromMore) + } + ) + + it('asks inside the menu before it uninstalls, then uninstalls without another dialog', async () => { + const tile = await mountTile('ready') + await tile.get('[data-testid="home-build-more"]').trigger('click') + await shownMenu() + + document.querySelector('[data-testid="build-menu-delete"]')!.click() + await flushPromises() + + const question = document.querySelector('[data-testid="build-menu-uninstall-question"]') + expect(question?.textContent).toContain('Flux Sandbox') + expect(host.showProgress).not.toHaveBeenCalled() + + document.querySelector('[data-testid="build-menu-confirm-uninstall"]')!.click() + await flushPromises() + + expect(host.showProgress).toHaveBeenCalledExactlyOnceWith( + expect.objectContaining({ installationId: BUILD.id, actionId: 'delete' }) + ) + expect(document.querySelector('[role="dialog"]')).toBeNull() + }) + + it('opens the logs when a starting build is clicked, and launches a ready one from the menu', async () => { + const tile = await mountTile('starting') + + await tile.get('[data-testid="home-build-starting"]').trigger('click') + expect(viewLogs).toHaveBeenCalledExactlyOnceWith(BUILD.id) + expect(host.launch).not.toHaveBeenCalled() + + useProgressStore().operations.clear() + await flushPromises() + await tile.get('[data-testid="home-build-more"]').trigger('click') + await shownMenu() + document.querySelector('[data-testid="build-menu-launch"]')!.click() + await flushPromises() + + expect(host.launch).toHaveBeenCalledExactlyOnceWith(BUILD) + }) + + it('offers Open in new window on a right-click on Home in the sidebar, and nothing on the other pages', async () => { + const sidebar = await mountSidebar('ready') + + await rightClick(sidebar.get('[data-testid="app-sidebar-assets"]').element) + expect(document.querySelector('[data-reka-menu-content]')).toBeNull() + + await rightClick(sidebar.get('[data-testid="app-sidebar-home"]').element) + await vi.waitFor(() => { + expect(document.querySelector('[data-reka-menu-content]')).not.toBeNull() + }) + const rows = [...document.querySelectorAll('[data-reka-menu-content] [role="menuitem"]')] + expect(rows.map((row) => row.textContent?.trim())).toEqual(['Open in new window']) + + ;(rows[0] as HTMLElement).click() + await flushPromises() + expect( + (window as unknown as { api: { openDashboardInNewWindow: () => void } }).api + .openDashboardInNewWindow + ).toHaveBeenCalledOnce() + }) +}) diff --git a/src/renderer/src/panel/home/BuildMenu.vue b/src/renderer/src/panel/home/BuildMenu.vue new file mode 100644 index 000000000..df22ed853 --- /dev/null +++ b/src/renderer/src/panel/home/BuildMenu.vue @@ -0,0 +1,117 @@ + + + diff --git a/src/renderer/src/panel/home/HomeBuildCard.vue b/src/renderer/src/panel/home/HomeBuildCard.vue index 1f0648192..518cfee00 100644 --- a/src/renderer/src/panel/home/HomeBuildCard.vue +++ b/src/renderer/src/panel/home/HomeBuildCard.vue @@ -1,9 +1,10 @@ diff --git a/src/renderer/src/panel/home/useBuildMenu.ts b/src/renderer/src/panel/home/useBuildMenu.ts new file mode 100644 index 000000000..0ef8fc122 --- /dev/null +++ b/src/renderer/src/panel/home/useBuildMenu.ts @@ -0,0 +1,161 @@ +import { computed, inject, provide, type InjectionKey } from 'vue' +import { useI18n } from 'vue-i18n' +import { until } from '@vueuse/core' +import { buildProgressOf, useBuildProgress } from '../../composables/useBuildProgress' +import { useInstallContextMenu } from '../../composables/useInstallContextMenu' +import { useModal } from '../../composables/useModal' +import { useQuickUpdate } from '../../composables/useQuickUpdate' +import { openInstallManager } from '../../lib/openInstallManager' +import { useProgressStore } from '../../stores/progressStore' +import { useSessionStore } from '../../stores/sessionStore' +import type { Installation, ShowProgressOpts } from '../../types/ipc' + +export interface BuildMenuHost { + launch: (build: Installation, opts?: { isRestart?: boolean }) => void | Promise + openDetails: (build: Installation) => void | Promise + showProgress: (opts: ShowProgressOpts) => void | Promise +} + +export interface BuildMenuEntry { + id: string + label: string + separator?: boolean + danger?: boolean + disabled?: boolean + title?: string +} + +const BUILD_MENU_HOST: InjectionKey = Symbol('buildMenuHost') +const NO_HOST: BuildMenuHost = { + launch: () => {}, + openDetails: () => {}, + showProgress: () => {} +} +const STOP_WAIT_MS = 15_000 + +export function provideBuildMenuHost(host: BuildMenuHost): void { + provide(BUILD_MENU_HOST, host) +} + +function startsGroup(entries: BuildMenuEntry[], items: BuildMenuEntry[]): void { + const [head] = entries + if (!head) return + head.separator = items.length > 0 + items.push(...entries) +} + +export function useBuildMenu(build: () => Installation) { + const { t } = useI18n() + const host = inject(BUILD_MENU_HOST, NO_HOST) + const modal = useModal() + const sessionStore = useSessionStore() + const progressStore = useProgressStore() + const install = useBuildProgress(build) + const { runQuickUpdate } = useQuickUpdate({ + onShowProgress: (opts) => void host.showProgress(opts), + onUnavailable: (inst) => openInstallManager(inst, { initialTab: 'update' }) + }) + const installMenu = useInstallContextMenu({ + onManage: (inst, options) => + options ? openInstallManager(inst, options) : void host.openDetails(inst), + onShowProgress: (opts) => void host.showProgress(opts), + onUpdate: runQuickUpdate + }) + + function isLocal(inst: Installation): boolean { + return inst.sourceCategory !== 'cloud' + } + + const items = computed(() => { + const inst = build() + const progress = buildProgressOf(progressStore, inst.id) + const running = !progress && isLocal(inst) && sessionStore.isRunning(inst.id) + const items: BuildMenuEntry[] = [] + + const now: BuildMenuEntry[] = [] + if (progress) { + if (progress.kind !== 'uninstall') { + now.push({ id: 'view-logs', label: t('installProgress.viewLogs') }) + } + now.push({ id: 'cancel', label: t('common.cancel'), disabled: progress.cancelling }) + } else if (running) { + now.push( + { id: 'view-logs', label: t('installProgress.viewLogs') }, + { id: 'restart', label: t('actions.restart') }, + { id: 'stop', label: t('actions.stop') } + ) + } else if (!sessionStore.isStopping(inst.id) && !sessionStore.isLaunching(inst.id)) { + now.push({ id: 'launch', label: t('actions.launch') }) + } + startsGroup(now, items) + + if (!progress) { + startsGroup([{ id: 'open-new-window', label: t('instancePicker.openInNewWindow') }], items) + } + + const existing = installMenu + .getMenuItems(inst) + .map(({ id, label, disabled, title, style, separator }): BuildMenuEntry => ({ + id, + label, + disabled, + title, + separator, + danger: style === 'danger' + })) + startsGroup( + existing.filter((item) => item.id !== 'stop' && item.id !== 'delete'), + items + ) + startsGroup( + existing.filter((item) => item.id === 'delete'), + items + ) + return items + }) + + async function restart(inst: Installation): Promise { + const confirmed = await modal.confirm({ + title: t('actions.restartConfirmTitle'), + message: t('actions.restartConfirmMessage'), + confirmLabel: t('actions.restartConfirm'), + confirmStyle: 'danger' + }) + if (!confirmed) return + try { + await window.api.stopComfyUI(inst.id) + } catch (err) { + await modal.alert({ + title: t('actions.restart'), + message: (err as Error)?.message || String(err) + }) + return + } + await until(() => sessionStore.isRunning(inst.id)).toBe(false, { timeout: STOP_WAIT_MS }) + if (sessionStore.isRunning(inst.id)) return + await host.launch(inst, { isRestart: true }) + } + + async function run(id: string, opts: { confirmed?: boolean } = {}): Promise { + const inst = build() + switch (id) { + case 'launch': + return host.launch(inst) + case 'view-logs': + if (install.progress.value) install.viewLogs() + else openInstallManager(inst, { initialTab: 'console' }) + return + case 'cancel': + return install.cancel() + case 'restart': + return restart(inst) + case 'open-new-window': + window.api.openInstallInNewWindow(inst.id) + return + default: + return installMenu.triggerAction(id, inst, opts) + } + } + + return { items, run } +} diff --git a/src/types/ipc.ts b/src/types/ipc.ts index 9df2a2fdf..401ed2de6 100644 --- a/src/types/ipc.ts +++ b/src/types/ipc.ts @@ -1151,6 +1151,7 @@ export interface ElectronApi { terminalRestart(installationId: string): Promise openInstallWindow(installationId: string): Promise openInstallInNewWindow(installationId: string): void + openDashboardInNewWindow(): void closeComfyWindow(installationId: string, opts?: { skipConfirm?: boolean }): Promise closeHostWindow(): Promise returnToDashboard(): Promise From 33baffd33770bd2d518e0444539966f7f43a8f8a Mon Sep 17 00:00:00 2001 From: Mariana Martinho Date: Sun, 15 Nov 2026 10:13:49 +0100 Subject: [PATCH 03/32] feat(home): icons on every build menu row, no right-click menu on sidebar pages Each build menu row shows its icon left of the label, like the other Desktop menus: the existing items keep theirs, and Launch, View logs, Cancel, Restart, Stop and Open in new window get one. A right-click on Home, Apps or Assets in the sidebar opens nothing, so the page menu and its new-window bridge are gone. --- src/preload/api.ts | 1 - src/renderer/src/panel/AppSidebar.vue | 26 ------------------- src/renderer/src/panel/home/BuildMenu.test.ts | 22 ++++------------ src/renderer/src/panel/home/BuildMenu.vue | 10 +++++++ src/renderer/src/panel/home/useBuildMenu.ts | 24 ++++++++++------- src/types/ipc.ts | 1 - 6 files changed, 30 insertions(+), 54 deletions(-) diff --git a/src/preload/api.ts b/src/preload/api.ts index ef396c3f0..8415ca9f2 100644 --- a/src/preload/api.ts +++ b/src/preload/api.ts @@ -88,7 +88,6 @@ export function buildElectronApi(): ElectronApi { terminalRestart: (installationId) => ipcRenderer.invoke('terminal-restart', installationId), openInstallInNewWindow: (installationId) => ipcRenderer.send('comfy-window:open-install-new-window', installationId), - openDashboardInNewWindow: () => ipcRenderer.send('comfy-window:new-chooser-window'), openInstallWindow: (installationId) => ipcRenderer.invoke('open-install-window', installationId), closeComfyWindow: (installationId, opts) => diff --git a/src/renderer/src/panel/AppSidebar.vue b/src/renderer/src/panel/AppSidebar.vue index 0d7667347..cfd63ed80 100644 --- a/src/renderer/src/panel/AppSidebar.vue +++ b/src/renderer/src/panel/AppSidebar.vue @@ -16,7 +16,6 @@ import { import type { Component } from 'vue' import Button from '@comfyorg/design-system/button/Button' import ComfyCLogo from '../components/icons/ComfyCLogo.vue' -import ContextMenu from '../components/ContextMenu.vue' import BuildMenu, { type BuildMenuAnchor } from './home/BuildMenu.vue' import ComfyWordmark from '../components/icons/ComfyWordmark.vue' import SidebarAccount from './SidebarAccount.vue' @@ -149,22 +148,6 @@ function openBuildMenu(event: MouseEvent, build: Installation): void { buildMenuAt.value = { build, anchor: pointAt(event) } buildMenuOpen.value = true } - -const PAGES_THAT_OPEN_IN_A_NEW_WINDOW: ReadonlySet = new Set(['home']) -const pageMenu = ref({ open: false, x: 0, y: 0 }) -const pageMenuItems = computed(() => [ - { id: 'open-new-window', label: t('instancePicker.openInNewWindow') } -]) - -function openPageMenu(event: MouseEvent, page: DashboardPage): void { - if (!PAGES_THAT_OPEN_IN_A_NEW_WINDOW.has(page)) return - event.preventDefault() - pageMenu.value = { open: true, x: event.clientX, y: event.clientY } -} - -function selectPageMenu(id: string): void { - if (id === 'open-new-window') window.api.openDashboardInNewWindow() -} diff --git a/src/renderer/src/panel/home/BuildMenu.test.ts b/src/renderer/src/panel/home/BuildMenu.test.ts index 553502d54..df6437706 100644 --- a/src/renderer/src/panel/home/BuildMenu.test.ts +++ b/src/renderer/src/panel/home/BuildMenu.test.ts @@ -57,7 +57,6 @@ beforeEach(() => { setSetting: vi.fn().mockResolvedValue(undefined), onSettingsChanged: vi.fn(() => () => {}), openInstallInNewWindow: vi.fn(), - openDashboardInNewWindow: vi.fn(), comfybuilder: { getAuthStatus: vi.fn().mockResolvedValue({ signedIn: false }), onAuthChanged: vi.fn(() => () => {}) @@ -218,24 +217,13 @@ describe('Build menu', () => { expect(host.launch).toHaveBeenCalledExactlyOnceWith(BUILD) }) - it('offers Open in new window on a right-click on Home in the sidebar, and nothing on the other pages', async () => { + it('opens no menu on a right-click on a page in the sidebar', async () => { const sidebar = await mountSidebar('ready') - await rightClick(sidebar.get('[data-testid="app-sidebar-assets"]').element) - expect(document.querySelector('[data-reka-menu-content]')).toBeNull() - - await rightClick(sidebar.get('[data-testid="app-sidebar-home"]').element) - await vi.waitFor(() => { - expect(document.querySelector('[data-reka-menu-content]')).not.toBeNull() - }) - const rows = [...document.querySelectorAll('[data-reka-menu-content] [role="menuitem"]')] - expect(rows.map((row) => row.textContent?.trim())).toEqual(['Open in new window']) + for (const page of ['home', 'assets']) { + await rightClick(sidebar.get(`[data-testid="app-sidebar-${page}"]`).element) + } - ;(rows[0] as HTMLElement).click() - await flushPromises() - expect( - (window as unknown as { api: { openDashboardInNewWindow: () => void } }).api - .openDashboardInNewWindow - ).toHaveBeenCalledOnce() + expect(document.querySelector('[data-reka-menu-content]')).toBeNull() }) }) diff --git a/src/renderer/src/panel/home/BuildMenu.vue b/src/renderer/src/panel/home/BuildMenu.vue index df22ed853..5d0e87db2 100644 --- a/src/renderer/src/panel/home/BuildMenu.vue +++ b/src/renderer/src/panel/home/BuildMenu.vue @@ -1,6 +1,7 @@ @@ -191,6 +204,7 @@ function openContextMenu(event: MouseEvent): void { :build="build" :anchor="menuAt.anchor" :align="menuAt.align" + :return-focus="menuAt.returnFocus" /> diff --git a/src/renderer/src/panel/home/useBuildMenu.ts b/src/renderer/src/panel/home/useBuildMenu.ts index b8549520f..2fa1d2180 100644 --- a/src/renderer/src/panel/home/useBuildMenu.ts +++ b/src/renderer/src/panel/home/useBuildMenu.ts @@ -91,7 +91,8 @@ export function useBuildMenu(build: () => Installation) { } startsGroup(now, items) - if (!progress) { + const busy = !!progress || sessionStore.isLaunching(inst.id) || sessionStore.isStopping(inst.id) + if (!busy) { startsGroup( [{ id: 'open-new-window', label: t('instancePicker.openInNewWindow'), icon: AppWindow }], items From afa1c29c42436102b5e9793532e9b1c60ce973f2 Mon Sep 17 00:00:00 2001 From: Mariana Martinho Date: Sun, 15 Nov 2026 16:00:02 +0100 Subject: [PATCH 06/32] feat(home): set Auto start from the build menu, show it on the card Drop the Auto start checkbox under every Home build card and Builds page tile. The shared build menu (Home tile, right-click, sidebar row) gets a Start with Desktop / Don't start with Desktop line right after Open in new window, shown in every state. The Builds page tile menu gets the same line as its first group. A ready card or tile whose build starts with Desktop says Starts with Desktop with a power icon instead of Ready. The panel shares one copy of the auto start setting, so a change from any menu shows on every card at once. --- e2e/home.test.ts | 20 -- locales/en.json | 5 +- locales/zh.json | 5 +- .../src/composables/useAutoStartBuild.ts | 28 ++- .../src/composables/useInstallContextMenu.ts | 18 ++ .../src/panel/HomeBuildsLayout.test.ts | 31 ++- src/renderer/src/panel/HomeView.test.ts | 97 ++++---- src/renderer/src/panel/HomeView.vue | 1 - src/renderer/src/panel/PanelApp.vue | 2 + .../src/panel/autoStartNarrowLayout.test.ts | 82 ++++--- .../src/panel/home/BuildAutoStartCheckbox.vue | 23 -- src/renderer/src/panel/home/BuildMenu.test.ts | 106 ++++++++- src/renderer/src/panel/home/HomeBuildCard.vue | 207 +++++++++--------- src/renderer/src/panel/home/useBuildMenu.ts | 24 +- src/renderer/src/views/ChooserView.test.ts | 55 ++++- src/renderer/src/views/ChooserView.vue | 4 +- .../src/views/chooser/ChooserFamilyGrid.vue | 1 - .../src/views/chooser/ChooserInstallTile.vue | 171 +++++++-------- 18 files changed, 531 insertions(+), 349 deletions(-) delete mode 100644 src/renderer/src/panel/home/BuildAutoStartCheckbox.vue diff --git a/e2e/home.test.ts b/e2e/home.test.ts index 3a1336157..0a1136177 100644 --- a/e2e/home.test.ts +++ b/e2e/home.test.ts @@ -53,23 +53,3 @@ test('Home in the sidebar returns to Home @windows @macos @linux', async () => { await ctx.panel.waitForVisible(HOME_VIEW) expect(await ctx.panel.isVisible('.chooser-view')).toBe(false) }) - -test('Auto start on a Home card saves that build for the next start, and unticking sets None @windows @macos @linux', async () => { - const box = '[data-testid="home-build-auto-start"] [role="checkbox"]' - const saved = () => ctx.panel.evaluate("window.api.getSetting('autoLaunchOnStartup')") - const boxState = () => - ctx.panel.evaluate(`document.querySelector('${box}')?.getAttribute('aria-checked')`) - await ctx.panel.waitForVisible(box) - const buildId = await ctx.panel.evaluate( - `document.querySelector('[data-testid="home-build-auto-start"]').dataset.buildId` - ) - - expect(await ctx.panel.click(box)).toBe(true) - await expect.poll(saved).toBe(buildId) - await expect.poll(boxState).toBe('true') - expect(await ctx.panel.isVisible(HOME_VIEW)).toBe(true) - - expect(await ctx.panel.click(box)).toBe(true) - await expect.poll(saved).toBe('none') - await expect.poll(boxState).toBe('false') -}) diff --git a/locales/en.json b/locales/en.json index ad52c1f53..35998bcb8 100644 --- a/locales/en.json +++ b/locales/en.json @@ -115,8 +115,9 @@ "openComfyUIIn": "Open ComfyUI in {name}", "opensIn": "Opens in {name}", "allBuilds": "All builds", - "autoStart": "Auto start", - "autoStartHint": "Start this build when Comfy Desktop opens", + "startWithDesktop": "Start with Desktop", + "dontStartWithDesktop": "Don't start with Desktop", + "startsWithDesktop": "Starts with Desktop", "buildRunning": "Running", "buildStarting": "Starting", "buildReady": "Ready", diff --git a/locales/zh.json b/locales/zh.json index 9a4dfa1d1..855d4e9b0 100644 --- a/locales/zh.json +++ b/locales/zh.json @@ -115,8 +115,9 @@ "openComfyUIIn": "在 {name} 中打开 ComfyUI", "opensIn": "在 {name} 中打开", "allBuilds": "全部构建", - "autoStart": "自动启动", - "autoStartHint": "Comfy Desktop 打开时启动此构建", + "startWithDesktop": "随 Desktop 启动", + "dontStartWithDesktop": "不随 Desktop 启动", + "startsWithDesktop": "将随 Desktop 启动", "buildRunning": "运行中", "buildStarting": "启动中", "buildReady": "就绪", diff --git a/src/renderer/src/composables/useAutoStartBuild.ts b/src/renderer/src/composables/useAutoStartBuild.ts index e4e19a3b3..686e83a47 100644 --- a/src/renderer/src/composables/useAutoStartBuild.ts +++ b/src/renderer/src/composables/useAutoStartBuild.ts @@ -1,9 +1,33 @@ -import { onScopeDispose, ref } from 'vue' +import { + getCurrentInstance, + hasInjectionContext, + inject, + onScopeDispose, + provide, + ref, + type InjectionKey +} from 'vue' const AUTO_START_SETTING = 'autoLaunchOnStartup' const AUTO_START_NONE = 'none' -export function useAutoStartBuild() { +export type AutoStartBuild = ReturnType + +const AUTO_START_BUILD: InjectionKey = Symbol('autoStartBuild') + +export function provideAutoStartBuild(): AutoStartBuild { + const autoStart = createAutoStartBuild() + provide(AUTO_START_BUILD, autoStart) + return autoStart +} + +export function useAutoStartBuild(): AutoStartBuild { + const shared = hasInjectionContext() ? inject(AUTO_START_BUILD, null) : null + if (shared) return shared + return getCurrentInstance() ? provideAutoStartBuild() : createAutoStartBuild() +} + +function createAutoStartBuild() { const autoStartValue = ref(undefined) let confirmedValue: unknown = undefined let revision = 0 diff --git a/src/renderer/src/composables/useInstallContextMenu.ts b/src/renderer/src/composables/useInstallContextMenu.ts index 8b6e9215a..117897f56 100644 --- a/src/renderer/src/composables/useInstallContextMenu.ts +++ b/src/renderer/src/composables/useInstallContextMenu.ts @@ -8,6 +8,8 @@ import { Download, FolderOpen, History, + Power, + PowerOff, Settings2, Trash2 } from '@lucide/vue' @@ -16,6 +18,7 @@ import { useSessionStore } from '../stores/sessionStore' import { useProgressStore } from '../stores/progressStore' import { useModal } from './useModal' import { useStopAction } from './useStopAction' +import type { AutoStartBuild } from './useAutoStartBuild' import { revealInFolderLabel } from './usePlatform' import { progressOpKindForActionId, destroysInstanceForActionId } from '../lib/progressOpKind' import { shareLatestSnapshot } from '../lib/snapshots' @@ -33,6 +36,7 @@ export type InstallMenuActionId = | 'share' | 'promote-to-workspace' | 'copy-install' + | 'auto-start' | 'delete' export interface ManageOpenOptions { @@ -46,6 +50,7 @@ export function useInstallContextMenu( onShowProgress?: (showOpts: ShowProgressOpts) => void onUpdate?: (inst: Installation) => Promise canPromoteToWorkspace?: (inst: Installation) => boolean + autoStart?: AutoStartBuild } = {} ) { const { t } = useI18n() @@ -217,6 +222,17 @@ export function useInstallContextMenu( items.push(...cluster) } + if (opts.autoStart) { + const startsOnOpen = opts.autoStart.startsOnOpen(inst.id) + const [head] = items + if (head) head.separator = true + items.unshift({ + id: 'auto-start', + label: startsOnOpen ? t('home.dontStartWithDesktop') : t('home.startWithDesktop'), + icon: startsOnOpen ? PowerOff : Power + }) + } + return items } @@ -314,6 +330,8 @@ export function useInstallContextMenu( setPromotingToWorkspace(inst.id, false) } if (failureMessage) await modal.alert({ title, message: failureMessage }) + } else if (id === 'auto-start') { + await opts.autoStart?.setStartsOnOpen(inst.id, !opts.autoStart.startsOnOpen(inst.id)) } else if (id === 'copy-install') { opts.onManage?.(inst, { autoAction: 'copy' }) } else if (id === 'delete') { diff --git a/src/renderer/src/panel/HomeBuildsLayout.test.ts b/src/renderer/src/panel/HomeBuildsLayout.test.ts index 57e2a7284..04617eeaf 100644 --- a/src/renderer/src/panel/HomeBuildsLayout.test.ts +++ b/src/renderer/src/panel/HomeBuildsLayout.test.ts @@ -64,23 +64,29 @@ beforeEach(() => { setActivePinia(createPinia()) }) -type BuildState = 'starting' | 'installing' | 'uninstalling' | 'ready' +type BuildState = 'starting' | 'installing' | 'uninstalling' | 'ready' | 'starting with Desktop' -const OPERATIONS: Record, Partial> = { +const OPERATIONS: Partial>> = { starting: { opKind: 'launch', flatPercent: 5 }, installing: { opKind: 'install', flatPercent: 40 }, uninstalling: { opKind: 'destructive', flatPercent: 18 } } async function homeWithBuildIn(state: BuildState) { + if (state === 'starting with Desktop') { + vi.mocked(window.api.getSetting).mockImplementation(async (key: string) => + key === 'autoLaunchOnStartup' ? STARTING.id : undefined + ) + } const wrapper = mount(HomeView, { attachTo: host }) await flushPromises() - if (state !== 'ready') { + const operation = OPERATIONS[state] + if (operation) { useProgressStore().operations.set(STARTING.id, { finished: false, cancelRequested: false, _globalFloor: 0, - ...OPERATIONS[state] + ...operation } as Operation) } await flushPromises() @@ -147,10 +153,12 @@ describe('Home build tiles', () => { ) it.each( - (['starting', 'installing', 'uninstalling', 'ready'] as const).flatMap((state) => [ - [state, MIN_WINDOW_BUILDS_WIDTH] as const, - [state, NORMAL_WINDOW_BUILDS_WIDTH] as const - ]) + (['starting', 'installing', 'uninstalling', 'ready', 'starting with Desktop'] as const).flatMap( + (state) => [ + [state, MIN_WINDOW_BUILDS_WIDTH] as const, + [state, NORMAL_WINDOW_BUILDS_WIDTH] as const + ] + ) )('keep one height when a build is %s, at %ipx', async (state, width) => { const wrapper = await homeWithBuildIn(state) const section = await layBuildsOut(width) @@ -159,8 +167,13 @@ describe('Home build tiles', () => { expect(tiles[0]!.getAttribute('data-build-id')).toBe(STARTING.id) expect(tiles[0]!.getAttribute('data-testid')).toBe( - state === 'ready' ? 'home-build' : `home-build-${state}` + OPERATIONS[state] ? `home-build-${state}` : 'home-build' ) + if (state === 'starting with Desktop') { + const status = tiles[0]!.querySelector('[data-testid="home-build-status"] .truncate')! + expect(status.textContent?.trim()).toBe('Starts with Desktop') + expect(fullyShown(status)).toBe(true) + } for (const tile of tiles) expect(tile.getBoundingClientRect().height).toBe(100) const tileBox = tiles[0]!.getBoundingClientRect() const moreBox = more.getBoundingClientRect() diff --git a/src/renderer/src/panel/HomeView.test.ts b/src/renderer/src/panel/HomeView.test.ts index 013c799c6..afd1ad2a7 100644 --- a/src/renderer/src/panel/HomeView.test.ts +++ b/src/renderer/src/panel/HomeView.test.ts @@ -6,7 +6,6 @@ import HomeView from './HomeView.vue' import { useDashboardScopeStore } from '../stores/dashboardScopeStore' import { useProgressStore } from '../stores/progressStore' import { useSessionStore } from '../stores/sessionStore' -import { setChecked } from '../views/testHelpers' import type { CatalogWorkflow, Installation } from '../types/ipc' const listHomeWorkflows = vi.fn<() => Promise>() @@ -697,84 +696,100 @@ describe('Home build auto start', () => { }) }) - function autoStartBox(wrapper: VueWrapper, id: string) { - return wrapper.get( - `[data-testid="home-build-auto-start"][data-build-id="${id}"] [role="checkbox"]` - ) + function cardOf(wrapper: VueWrapper, id: string) { + return wrapper.get(`[data-build-id="${id}"][data-testid^="home-build"]`) + } + + function statusOf(wrapper: VueWrapper, id: string): string { + return cardOf(wrapper, id).get('[data-testid="home-build-status"]').text() } - function ticked(wrapper: VueWrapper): string[] { + function startingWithDesktop(wrapper: VueWrapper): string[] { return wrapper - .findAll('[data-testid="home-build-auto-start"]') - .filter((box) => box.get('[role="checkbox"]').attributes('aria-checked') === 'true') - .map((box) => box.attributes('data-build-id')!) + .findAll('[data-testid="home-build-starts-with-desktop"]') + .map((icon) => icon.element.closest('[data-build-id]')!.getAttribute('data-build-id')!) } - it('ticks the card of the build that starts when Desktop opens', async () => { + it('says Starts with Desktop on the ready card of the build that starts when Desktop opens', async () => { saved = OLDEST.id - getInstallations.mockResolvedValue([OLDEST, CLOUD, NEWEST]) + getInstallations.mockResolvedValue([OLDEST, RUNNING]) const wrapper = await openHome() - expect(wrapper.findAll('[data-testid="home-build-auto-start"]')).toHaveLength(3) - expect(ticked(wrapper)).toEqual([OLDEST.id]) + expect(wrapper.find('[role="checkbox"]').exists()).toBe(false) + expect(statusOf(wrapper, OLDEST.id)).toBe('Starts with Desktop') + expect(statusOf(wrapper, RUNNING.id)).toBe('Ready') + expect(startingWithDesktop(wrapper)).toEqual([OLDEST.id]) + expect( + cardOf(wrapper, OLDEST.id).get('[data-testid="home-build-open"]').attributes('aria-label') + ).toBe(`${OLDEST.name}, Starts with Desktop`) }) - it('moves the tick to Comfy Cloud when its box is ticked, without opening it', async () => { + it('moves Starts with Desktop to the card whose menu says Start with Desktop', async () => { saved = OLDEST.id - getInstallations.mockResolvedValue([OLDEST, CLOUD]) + getInstallations.mockResolvedValue([OLDEST, RUNNING]) const wrapper = await openHome() - await setChecked(autoStartBox(wrapper, CLOUD.id), true) + await cardOf(wrapper, RUNNING.id).get('[data-testid="home-build-more"]').trigger('click') + await flushPromises() + const line = await vi.waitFor(() => { + const found = document.querySelector('[data-testid="build-menu-auto-start"]') + expect(found).not.toBeNull() + return found! + }) + expect(line.textContent?.trim()).toBe('Start with Desktop') + line.click() await flushPromises() - expect(setSetting).toHaveBeenCalledWith('autoLaunchOnStartup', CLOUD.id) - expect(ticked(wrapper)).toEqual([CLOUD.id]) - expect(wrapper.emitted('pick')).toBeUndefined() + expect(setSetting).toHaveBeenCalledWith('autoLaunchOnStartup', RUNNING.id) + expect(startingWithDesktop(wrapper)).toEqual([RUNNING.id]) + expect(statusOf(wrapper, OLDEST.id)).toBe('Ready') expect(wrapper.emitted('open-build')).toBeUndefined() }) - it('sets None when the ticked card is unticked', async () => { - saved = NEWEST.id - getInstallations.mockResolvedValue([OLDEST, NEWEST]) + it('keeps Always on for Comfy Cloud when it is the one that starts with Desktop', async () => { + saved = CLOUD.id + getInstallations.mockResolvedValue([OLDEST, CLOUD]) const wrapper = await openHome() - await setChecked(autoStartBox(wrapper, NEWEST.id), false) - await flushPromises() - - expect(setSetting).toHaveBeenCalledWith('autoLaunchOnStartup', 'none') - expect(ticked(wrapper)).toEqual([]) + expect(statusOf(wrapper, CLOUD.id)).toBe('Always on') + expect(statusOf(wrapper, OLDEST.id)).toBe('Ready') + expect(startingWithDesktop(wrapper)).toEqual([]) }) - it('ticks no card when Settings says Last used build', async () => { + it('says Ready on every card when Settings says Last used build', async () => { saved = 'last' - getInstallations.mockResolvedValue([OLDEST, NEWEST]) + getInstallations.mockResolvedValue([OLDEST, RUNNING]) const wrapper = await openHome() - expect(ticked(wrapper)).toEqual([]) + expect(statusOf(wrapper, OLDEST.id)).toBe('Ready') + expect(statusOf(wrapper, RUNNING.id)).toBe('Ready') + expect(startingWithDesktop(wrapper)).toEqual([]) }) it('follows a build picked in Settings without a restart', async () => { saved = OLDEST.id - getInstallations.mockResolvedValue([OLDEST, NEWEST]) + getInstallations.mockResolvedValue([OLDEST, RUNNING]) const wrapper = await openHome() - saved = NEWEST.id + saved = RUNNING.id for (const listener of settingsListeners) listener({ key: 'autoLaunchOnStartup' }) await flushPromises() - expect(ticked(wrapper)).toEqual([NEWEST.id]) + expect(startingWithDesktop(wrapper)).toEqual([RUNNING.id]) + expect(statusOf(wrapper, OLDEST.id)).toBe('Ready') }) - it('leaves the box off a card while its build installs', async () => { + it('shows the install status, not Starts with Desktop, while that build installs', async () => { Object.assign(window.api, { onInstallProgress: vi.fn(() => () => {}), onComfyOutput: vi.fn(() => () => {}) }) - getInstallations.mockResolvedValue([OLDEST, NEWEST]) + saved = OLDEST.id + getInstallations.mockResolvedValue([OLDEST, RUNNING]) const wrapper = await openHome() useProgressStore().startOperation({ - installationId: NEWEST.id, + installationId: OLDEST.id, title: 'Installing', opKind: 'install', apiCall: () => new Promise(() => {}) @@ -782,12 +797,10 @@ describe('Home build auto start', () => { await flushPromises() expect( - wrapper.find(`[data-testid="home-build-installing"][data-build-id="${NEWEST.id}"]`).exists() + wrapper.find(`[data-testid="home-build-installing"][data-build-id="${OLDEST.id}"]`).exists() ).toBe(true) - expect( - wrapper - .findAll('[data-testid="home-build-auto-start"]') - .map((box) => box.attributes('data-build-id')) - ).toEqual([OLDEST.id]) + expect(statusOf(wrapper, OLDEST.id)).not.toContain('Starts with Desktop') + expect(startingWithDesktop(wrapper)).toEqual([]) + expect(setSetting).not.toHaveBeenCalledWith('autoLaunchOnStartup', expect.anything()) }) }) diff --git a/src/renderer/src/panel/HomeView.vue b/src/renderer/src/panel/HomeView.vue index 3bff2d23a..67d05b436 100644 --- a/src/renderer/src/panel/HomeView.vue +++ b/src/renderer/src/panel/HomeView.vue @@ -276,7 +276,6 @@ onMounted(() => { :tone="buildTones[index]!" :auto-start="autoStart.startsOnOpen(build.id)" @open="openBuild(build)" - @auto-start="autoStart.setStartsOnOpen(build.id, $event)" />
diff --git a/src/renderer/src/panel/PanelApp.vue b/src/renderer/src/panel/PanelApp.vue index ddfdcc668..40b5d48a5 100644 --- a/src/renderer/src/panel/PanelApp.vue +++ b/src/renderer/src/panel/PanelApp.vue @@ -52,6 +52,7 @@ import { import { useThumbnailPrefetch } from '../composables/useThumbnailPrefetch' import { provideBuildLogs } from '../composables/useBuildProgress' import { provideBuildMenuHost } from './home/useBuildMenu' +import { provideAutoStartBuild } from '../composables/useAutoStartBuild' import { focusRunningBuild } from '../lib/focusRunningBuild' import type { AppCard, DashboardPage, Installation } from '../types/ipc' @@ -277,6 +278,7 @@ chooserHandoff = useChooserHandoff({ }) const { handleChooserPick, handleChooserShowNewInstall } = chooserHandoff +provideAutoStartBuild() provideBuildMenuHost({ launch: async (inst, launchOpts) => { if (await focusRunningBuild(inst)) return diff --git a/src/renderer/src/panel/autoStartNarrowLayout.test.ts b/src/renderer/src/panel/autoStartNarrowLayout.test.ts index e1d927aaf..29ab0871e 100644 --- a/src/renderer/src/panel/autoStartNarrowLayout.test.ts +++ b/src/renderer/src/panel/autoStartNarrowLayout.test.ts @@ -16,6 +16,9 @@ const PAGE_SIDE_PADDING = 2 * 40 const HOME_WIDTH_IN_SMALLEST_WINDOW = SMALLEST_WINDOW_WIDTH - FRAME_AND_EXPANDED_SIDEBAR_WIDTH const BUILDS_GRID_WIDTH_IN_LARGE_WINDOW = LARGE_WINDOW_WIDTH - FRAME_AND_EXPANDED_SIDEBAR_WIDTH - PAGE_SIDE_PADDING +const WIDE_WINDOW_WIDTH = 1280 +const BUILDS_GRID_WIDTH_IN_WIDE_WINDOW = + WIDE_WINDOW_WIDTH - FRAME_AND_EXPANDED_SIDEBAR_WIDTH - PAGE_SIDE_PADDING const HOME_CARD_SIDE_PADDING_AND_BORDER = 18 + 1 const BUILDS_TILE_RIGHT_PADDING = 12 const READABLE_NAME_WIDTH = 40 @@ -49,7 +52,9 @@ beforeEach(() => { onInstallationsVersionsUpdated: vi.fn(() => () => {}), onInstallProgress: vi.fn(() => () => {}), onComfyOutput: vi.fn(() => () => {}), - getSetting: vi.fn().mockResolvedValue('none'), + getSetting: vi.fn(async (key: string) => + key === 'autoLaunchOnStartup' ? STUDIO.id : undefined + ), setSetting: vi.fn().mockResolvedValue(undefined), onSettingsChanged: vi.fn(() => () => {}), comfybuilder: { @@ -64,62 +69,85 @@ beforeEach(() => { afterEach(() => page.remove()) -describe('Auto start on Home build cards in the smallest window with the sidebar open', () => { - it('leaves each build name the width the card has after its picture, with the box on a row under the card', async () => { +function fullyShown(element: Element): boolean { + return element.scrollWidth <= element.clientWidth && element.clientWidth > 0 +} + +describe('Starts with Desktop on Home build cards in the smallest window with the sidebar open', () => { + it('shows the whole status and leaves each name the width the card has after its picture', async () => { page.style.cssText = `position: absolute; left: 0; top: 0; width: ${HOME_WIDTH_IN_SMALLEST_WINDOW}px` const wrapper = mount(HomeView, { attachTo: page }) await flushPromises() + const studioStatus = onlyIn( + wrapper, + `div[data-testid="home-build"][data-build-id="${STUDIO.id}"] [data-testid="home-build-status"] .truncate` + ) + expect(studioStatus.textContent?.trim()).toBe('Starts with Desktop') + expect(fullyShown(studioStatus), 'status is not cut off').toBe(true) + expect(wrapper.find('[role="checkbox"]').exists()).toBe(false) + for (const { id } of [STUDIO, PORTRAITS]) { const card = onlyIn(wrapper, `div[data-testid="home-build"][data-build-id="${id}"]`) const name = card.querySelector('.font-semibold')! - const box = onlyIn(wrapper, `[data-testid="home-build-auto-start"][data-build-id="${id}"]`) const cardBox = boxOf(card) const nameBox = boxOf(name) - const checkboxBox = boxOf(box) + expect(cardBox.height, `${id} card height`).toBe(100) expect(nameBox.width, `${id} name width`).toBeGreaterThanOrEqual(READABLE_NAME_WIDTH) expect( Math.abs(cardBox.right - HOME_CARD_SIDE_PADDING_AND_BORDER - nameBox.right), `${id} name stops at the card's padding` ).toBeLessThanOrEqual(1) - expect(card.contains(box), `${id} box sits outside the card button`).toBe(false) - expect(checkboxBox.top, `${id} box is under the card`).toBeGreaterThanOrEqual(cardBox.bottom) - expect(checkboxBox.width, `${id} box is shown`).toBeGreaterThan(0) - expect(checkboxBox.left).toBeGreaterThanOrEqual(cardBox.left) - expect(checkboxBox.right).toBeLessThanOrEqual(cardBox.right) } }) }) -describe('Auto start on Builds page tiles in a 1024 px window with the sidebar open', () => { - it('keeps the name readable and every button inside the tile, with the box on a row under Start', async () => { - page.style.cssText = `position: absolute; left: 0; top: 0; width: ${BUILDS_GRID_WIDTH_IN_LARGE_WINDOW}px` - const wrapper = mount(ChooserFamilyGrid, { - attachTo: page, - props: { installations: [STUDIO, PORTRAITS], isStoppedActionGated: () => false } - }) - await flushPromises() +async function mountBuildsGrid(width: number): Promise { + page.style.cssText = `position: absolute; left: 0; top: 0; width: ${width}px` + const wrapper = mount(ChooserFamilyGrid, { + attachTo: page, + props: { installations: [STUDIO, PORTRAITS], isStoppedActionGated: () => false } + }) + await flushPromises() + return wrapper +} + +function buildsTileStatus(wrapper: VueWrapper): Element { + const tile = onlyIn(wrapper, `[data-testid="${TID.dashboardTile(STUDIO.id)}"]`) + return tile.querySelector('.chooser-tile-body .truncate')! +} + +describe('Starts with Desktop on Builds page tiles', () => { + it('in a 1024 px window with the sidebar open, keeps the status on one line, the name readable and every button inside the tile', async () => { + const wrapper = await mountBuildsGrid(BUILDS_GRID_WIDTH_IN_LARGE_WINDOW) + const status = buildsTileStatus(wrapper) + expect(status.textContent?.trim()).toBe('Starts with Desktop') + expect(boxOf(status).height, 'status stays on one line').toBe(16) + expect(wrapper.find('[role="checkbox"]').exists()).toBe(false) + + const heights = new Set() for (const { id } of [STUDIO, PORTRAITS]) { const tile = onlyIn(wrapper, `[data-testid="${TID.dashboardTile(id)}"]`) const name = tile.querySelector('.chooser-tile-name')! - const start = tile.querySelector('.chooser-tile-launch')! const kebab = tile.querySelector('.chooser-tile-kebab')! - const box = onlyIn(wrapper, `[data-testid="chooser-tile-auto-start-${id}"]`) const tileBox = boxOf(tile) - const checkboxBox = boxOf(box) + heights.add(tileBox.height) expect(boxOf(name).width, `${id} name width`).toBeGreaterThanOrEqual(READABLE_NAME_WIDTH) expect(boxOf(kebab).right, `${id} menu button is not cut off`).toBeLessThanOrEqual( tileBox.right - BUILDS_TILE_RIGHT_PADDING + 0.5 ) - expect(checkboxBox.top, `${id} box is under Start`).toBeGreaterThanOrEqual( - boxOf(start).bottom - ) - expect(checkboxBox.width, `${id} box is shown`).toBeGreaterThan(0) - expect(checkboxBox.right).toBeLessThanOrEqual(tileBox.right) - expect(checkboxBox.bottom).toBeLessThanOrEqual(tileBox.bottom) } + expect([...heights]).toEqual([100]) + }) + + it('in a 1280 px window with the sidebar open, shows the whole status', async () => { + const wrapper = await mountBuildsGrid(BUILDS_GRID_WIDTH_IN_WIDE_WINDOW) + + const status = buildsTileStatus(wrapper) + expect(status.textContent?.trim()).toBe('Starts with Desktop') + expect(fullyShown(status), 'status is not cut off').toBe(true) }) }) diff --git a/src/renderer/src/panel/home/BuildAutoStartCheckbox.vue b/src/renderer/src/panel/home/BuildAutoStartCheckbox.vue deleted file mode 100644 index ebd588d25..000000000 --- a/src/renderer/src/panel/home/BuildAutoStartCheckbox.vue +++ /dev/null @@ -1,23 +0,0 @@ - - - diff --git a/src/renderer/src/panel/home/BuildMenu.test.ts b/src/renderer/src/panel/home/BuildMenu.test.ts index ff961cffa..8bc3fd41c 100644 --- a/src/renderer/src/panel/home/BuildMenu.test.ts +++ b/src/renderer/src/panel/home/BuildMenu.test.ts @@ -27,11 +27,21 @@ type State = 'ready' | 'starting' | 'installing' | 'running' | 'uninstalling' const REST = ['|', 'manage', 'copy-install', 'reveal-in-folder', '|', 'share', 'restore-snapshot'] const EXPECTED: Record = { - ready: ['launch', '|', 'open-new-window', ...REST, '|', 'delete'], - starting: ['view-logs', 'cancel', ...REST, '|', 'delete'], - installing: ['view-logs', 'cancel', ...REST, '|', 'delete'], - running: ['view-logs', 'restart', 'stop', '|', 'open-new-window', ...REST, '|', 'delete'], - uninstalling: ['cancel', ...REST, '|', 'delete'] + ready: ['launch', '|', 'open-new-window', 'auto-start', ...REST, '|', 'delete'], + starting: ['view-logs', 'cancel', '|', 'auto-start', ...REST, '|', 'delete'], + installing: ['view-logs', 'cancel', '|', 'auto-start', ...REST, '|', 'delete'], + running: [ + 'view-logs', + 'restart', + 'stop', + '|', + 'open-new-window', + 'auto-start', + ...REST, + '|', + 'delete' + ], + uninstalling: ['cancel', '|', 'auto-start', ...REST, '|', 'delete'] } const OPERATIONS: Partial>> = { starting: { opKind: 'launch', flatPercent: 5 }, @@ -42,8 +52,11 @@ const OPERATIONS: Partial>> = { let host: BuildMenuHost & { [K in keyof BuildMenuHost]: ReturnType } const mounted: VueWrapper[] = [] const viewLogs = vi.fn() +const OTHER_BUILD_ID = 'other' +let saved: unknown beforeEach(() => { + saved = 'none' for (const wrapper of mounted.splice(0)) wrapper.unmount() document.body.innerHTML = '' ;(window as unknown as { api: unknown }).api = { @@ -53,8 +66,10 @@ beforeEach(() => { getInstallations: vi.fn().mockResolvedValue([]), onInstallationsChanged: vi.fn(() => () => {}), onInstallationsVersionsUpdated: vi.fn(() => () => {}), - getSetting: vi.fn().mockResolvedValue(undefined), - setSetting: vi.fn().mockResolvedValue(undefined), + getSetting: vi.fn(async (key: string) => (key === 'autoLaunchOnStartup' ? saved : undefined)), + setSetting: vi.fn(async (key: string, value: unknown) => { + if (key === 'autoLaunchOnStartup') saved = value + }), onSettingsChanged: vi.fn(() => () => {}), openInstallInNewWindow: vi.fn(), comfybuilder: { @@ -268,4 +283,81 @@ describe('Build menu', () => { expect(document.querySelector('[data-reka-menu-content]')).toBeNull() }) + + it.each([ + ['tile ⋯', 'more'], + ['sidebar row', 'sidebar'] + ] as const)( + 'from the %s, offers Start with Desktop and saves this build when picked', + async (_name, from) => { + saved = OTHER_BUILD_ID + await openMenuFrom(from) + + const line = autoStartLine() + expect(line.textContent?.trim()).toBe('Start with Desktop') + expect(line.querySelector('.lucide-power')).not.toBeNull() + line.click() + await flushPromises() + + expect(autoStartWrites()).toEqual([BUILD.id]) + expect(saved).toBe(BUILD.id) + } + ) + + it("offers Don't start with Desktop on the build that starts with Desktop and sets None when picked", async () => { + saved = BUILD.id + const tile = await openMenuFrom('more') + + const line = autoStartLine() + expect(line.textContent?.trim()).toBe("Don't start with Desktop") + expect(line.querySelector('.lucide-power-off')).not.toBeNull() + line.click() + await flushPromises() + + expect(autoStartWrites()).toEqual(['none']) + await vi.waitFor(() => expect(document.querySelector('[data-testid="build-menu"]')).toBeNull()) + await tile.get('[data-testid="home-build-more"]').trigger('click') + await shownMenu() + expect(autoStartLine().textContent?.trim()).toBe('Start with Desktop') + }) + + it('keeps the Start with Desktop line, in its own group, while the build installs', async () => { + const tile = await mountTile('installing') + await tile.get('[data-testid="home-build-more"]').trigger('click') + const shown = await shownMenu() + + expect(shown.slice(shown.indexOf('auto-start') - 1, shown.indexOf('auto-start') + 2)).toEqual([ + '|', + 'auto-start', + '|' + ]) + autoStartLine().click() + await flushPromises() + + expect(autoStartWrites()).toEqual([BUILD.id]) + }) }) + +async function openMenuFrom(from: 'more' | 'sidebar'): Promise { + if (from === 'more') { + const tile = await mountTile('ready') + await tile.get('[data-testid="home-build-more"]').trigger('click') + await shownMenu() + return tile + } + const sidebar = await mountSidebar('ready') + await rightClick(sidebar.get(`[data-testid="app-sidebar-build-${BUILD.id}"]`).element) + await shownMenu() + return sidebar +} + +function autoStartWrites(): unknown[] { + return vi + .mocked(window.api.setSetting) + .mock.calls.filter(([key]) => key === 'autoLaunchOnStartup') + .map(([, value]) => value) +} + +function autoStartLine(): HTMLElement { + return document.querySelector('[data-testid="build-menu-auto-start"]')! +} diff --git a/src/renderer/src/panel/home/HomeBuildCard.vue b/src/renderer/src/panel/home/HomeBuildCard.vue index 8f86f8949..953112c02 100644 --- a/src/renderer/src/panel/home/HomeBuildCard.vue +++ b/src/renderer/src/panel/home/HomeBuildCard.vue @@ -1,12 +1,11 @@ diff --git a/src/renderer/src/panel/home/useBuildMenu.ts b/src/renderer/src/panel/home/useBuildMenu.ts index 2fa1d2180..e9a9b6134 100644 --- a/src/renderer/src/panel/home/useBuildMenu.ts +++ b/src/renderer/src/panel/home/useBuildMenu.ts @@ -2,6 +2,7 @@ import { computed, inject, provide, type Component, type InjectionKey } from 'vu import { AppWindow, CircleStop, Play, RotateCw, ScrollText, X } from '@lucide/vue' import { useI18n } from 'vue-i18n' import { until } from '@vueuse/core' +import { useAutoStartBuild } from '../../composables/useAutoStartBuild' import { buildProgressOf, useBuildProgress } from '../../composables/useBuildProgress' import { useInstallContextMenu } from '../../composables/useInstallContextMenu' import { useModal } from '../../composables/useModal' @@ -61,7 +62,8 @@ export function useBuildMenu(build: () => Installation) { onManage: (inst, options) => options ? openInstallManager(inst, options) : void host.openDetails(inst), onShowProgress: (opts) => void host.showProgress(opts), - onUpdate: runQuickUpdate + onUpdate: runQuickUpdate, + autoStart: useAutoStartBuild() }) function isLocal(inst: Installation): boolean { @@ -91,14 +93,6 @@ export function useBuildMenu(build: () => Installation) { } startsGroup(now, items) - const busy = !!progress || sessionStore.isLaunching(inst.id) || sessionStore.isStopping(inst.id) - if (!busy) { - startsGroup( - [{ id: 'open-new-window', label: t('instancePicker.openInNewWindow'), icon: AppWindow }], - items - ) - } - const existing = installMenu .getMenuItems(inst) .map(({ id, label, icon, disabled, title, style, separator }): BuildMenuEntry => ({ @@ -110,8 +104,18 @@ export function useBuildMenu(build: () => Installation) { separator, danger: style === 'danger' })) + + const busy = !!progress || sessionStore.isLaunching(inst.id) || sessionStore.isStopping(inst.id) + const windowGroup: BuildMenuEntry[] = busy + ? [] + : [{ id: 'open-new-window', label: t('instancePicker.openInNewWindow'), icon: AppWindow }] + windowGroup.push(...existing.filter((item) => item.id === 'auto-start')) + startsGroup(windowGroup, items) + startsGroup( - existing.filter((item) => item.id !== 'stop' && item.id !== 'delete'), + existing.filter( + (item) => item.id !== 'stop' && item.id !== 'delete' && item.id !== 'auto-start' + ), items ) startsGroup( diff --git a/src/renderer/src/views/ChooserView.test.ts b/src/renderer/src/views/ChooserView.test.ts index 419ad966b..c43f082ce 100644 --- a/src/renderer/src/views/ChooserView.test.ts +++ b/src/renderer/src/views/ChooserView.test.ts @@ -11,7 +11,6 @@ import { useAuthStore } from '../stores/authStore' import { useDashboardScopeStore } from '../stores/dashboardScopeStore' import { PERSONAL_WORKSPACE_ID } from '../../../shared/workspaces' import { TID } from '../../../shared/testIds' -import { setChecked } from './testHelpers' import type { DevPlatformBuild, Installation } from '../types/ipc' vi.mock('../components/ContextMenu.vue', () => ({ @@ -259,33 +258,65 @@ describe('ChooserView', () => { expect(wrapper.emitted('open-details')).toBeUndefined() }) - it('ticks auto start on a tile, moving it from the other build without opening either', async () => { + it('sets Start with Desktop from a tile menu, moving it from the other build', async () => { + let saved: unknown = 'a' const api = installMockApi([ makeInstall({ id: 'a', name: 'Alpha' }), makeInstall({ id: 'b', name: 'Beta' }) ]) api.getSetting.mockImplementation(async (key: string) => - key === 'autoLaunchOnStartup' ? 'a' : undefined + key === 'autoLaunchOnStartup' ? saved : undefined ) + api.setSetting.mockImplementation(async (key: string, value: unknown) => { + if (key === 'autoLaunchOnStartup') saved = value + }) const wrapper = mountChooser() await flushPromises() - const autoStartBox = (id: string) => - wrapper.get(`[data-testid="chooser-tile-auto-start-${id}"] [role="checkbox"]`) - expect(autoStartBox('a').attributes('aria-checked')).toBe('true') + const tile = (id: string) => wrapper.get(`[data-testid="${TID.dashboardTile(id)}"]`) + const autoStartWrites = () => + api.setSetting.mock.calls.filter(([key]) => key === 'autoLaunchOnStartup').map(([, v]) => v) + const startsWithDesktop = (id: string) => + tile(id).find(`[data-testid="chooser-tile-starts-with-desktop-${id}"]`).exists() + async function menuFor(id: string) { + await tile(id).trigger('contextmenu') + const menu = wrapper + .findAllComponents({ name: 'ContextMenu' }) + .find((candidate) => candidate.props('open') === true)! + return menu + } - await setChecked(autoStartBox('b'), true) + expect(wrapper.find('[role="checkbox"]').exists()).toBe(false) + expect(startsWithDesktop('a')).toBe(true) + expect(tile('a').text()).toContain('Starts with Desktop') + expect(startsWithDesktop('b')).toBe(false) + expect(tile('b').text()).toContain('Ready') + + const menuA = await menuFor('a') + const itemsA = menuA.props('items') as { id: string; label: string; separator?: boolean }[] + expect(itemsA[0]).toMatchObject({ id: 'auto-start', label: "Don't start with Desktop" }) + expect(itemsA[1]).toMatchObject({ id: 'manage', separator: true }) + + const menuB = await menuFor('b') + const itemsB = menuB.props('items') as { id: string; label: string }[] + expect(itemsB[0]).toMatchObject({ id: 'auto-start', label: 'Start with Desktop' }) + menuB.vm.$emit('select', 'auto-start') await flushPromises() - expect(api.setSetting).toHaveBeenCalledWith('autoLaunchOnStartup', 'b') - expect(autoStartBox('a').attributes('aria-checked')).toBe('false') + expect(autoStartWrites()).toEqual(['b']) + expect(startsWithDesktop('a')).toBe(false) + expect(startsWithDesktop('b')).toBe(true) expect(wrapper.emitted('open-details')).toBeUndefined() expect(wrapper.emitted('pick')).toBeUndefined() - await setChecked(autoStartBox('b'), false) + const menuAgain = await menuFor('b') + expect((menuAgain.props('items') as { label: string }[])[0]!.label).toBe( + "Don't start with Desktop" + ) + menuAgain.vm.$emit('select', 'auto-start') await flushPromises() - expect(api.setSetting).toHaveBeenLastCalledWith('autoLaunchOnStartup', 'none') - expect(wrapper.emitted('open-details')).toBeUndefined() + expect(autoStartWrites()).toEqual(['b', 'none']) + expect(startsWithDesktop('b')).toBe(false) }) it('shows Update beside Start and keeps Start as the action', async () => { diff --git a/src/renderer/src/views/ChooserView.vue b/src/renderer/src/views/ChooserView.vue index 26867ae62..8ef2aabf4 100644 --- a/src/renderer/src/views/ChooserView.vue +++ b/src/renderer/src/views/ChooserView.vue @@ -8,6 +8,7 @@ import { useInstallationStore } from '../stores/installationStore' import { useAuthStore } from '../stores/authStore' import { useDashboardScopeStore } from '../stores/dashboardScopeStore' import { useInstallContextMenu } from '../composables/useInstallContextMenu' +import { useAutoStartBuild } from '../composables/useAutoStartBuild' import { useInstallList } from '../composables/useInstallList' import { useInstallingBuilds } from '../composables/useBuildProgress' import { useQuickUpdate } from '../composables/useQuickUpdate' @@ -203,7 +204,8 @@ const { options ? openInstallManager(inst, options) : emit('open-details', inst), onShowProgress: (showOpts) => emit('show-progress', showOpts), onUpdate: runQuickUpdate, - canPromoteToWorkspace + canPromoteToWorkspace, + autoStart: useAutoStartBuild() }) async function pickInstall(inst: Installation): Promise { diff --git a/src/renderer/src/views/chooser/ChooserFamilyGrid.vue b/src/renderer/src/views/chooser/ChooserFamilyGrid.vue index 382d2f72a..c504307a9 100644 --- a/src/renderer/src/views/chooser/ChooserFamilyGrid.vue +++ b/src/renderer/src/views/chooser/ChooserFamilyGrid.vue @@ -88,7 +88,6 @@ function unlockTileSize(el: Element): void { @trigger-action="(action, inst) => emit('trigger-action', action, inst)" @view-error="emit('view-error', $event)" @view-danger="emit('view-danger', $event)" - @auto-start="(inst, on) => autoStart.setStartsOnOpen(inst.id, on)" /> diff --git a/src/renderer/src/views/chooser/ChooserInstallTile.vue b/src/renderer/src/views/chooser/ChooserInstallTile.vue index 02a467762..88d5eb73b 100644 --- a/src/renderer/src/views/chooser/ChooserInstallTile.vue +++ b/src/renderer/src/views/chooser/ChooserInstallTile.vue @@ -11,6 +11,7 @@ import { LoaderCircle, OctagonAlert, Play, + Power, Server, Check } from '@lucide/vue' @@ -27,7 +28,6 @@ import { import Tooltip from '../../components/ui/Tooltip.vue' import BuildDeviceArt from '../../panel/home/BuildDeviceArt.vue' import BuildProgressBar from '../../panel/home/BuildProgressBar.vue' -import BuildAutoStartCheckbox from '../../panel/home/BuildAutoStartCheckbox.vue' import TruncatedText from '../../components/TruncatedText.vue' import { TID } from '../../../../shared/testIds' import { isBuildInstall } from '../../devplatform/buildState' @@ -60,7 +60,6 @@ const emit = defineEmits<{ 'view-error': [installation: Installation] 'view-danger': [installation: Installation] 'why-cloud': [] - 'auto-start': [installation: Installation, on: boolean] }>() const { t } = useI18n() @@ -174,9 +173,11 @@ const showWhyCloudTrigger = computed( const hasUpdate = computed(() => inst.value.statusTag?.style === 'update') const hasMigratePrompt = computed(() => inst.value.statusTag?.style === 'migrate') -const restingLabel = computed(() => - isCloudBuild(inst.value) ? t('home.buildAlwaysOn') : t('home.buildReady') -) +const startsWithDesktop = computed(() => props.autoStart && !isCloudBuild(inst.value)) +const restingLabel = computed(() => { + if (isCloudBuild(inst.value)) return t('home.buildAlwaysOn') + return startsWithDesktop.value ? t('home.startsWithDesktop') : t('home.buildReady') +}) const isFromBuild = computed(() => isBuildInstall(inst.value)) @@ -372,6 +373,13 @@ function triggerInstallAction(action: 'update' | 'migrate'): void { class="size-1.5 shrink-0 rounded-full bg-[#59d38c] shadow-[0_0_0_3px_rgb(89_211_140/0.36)]" aria-hidden="true" /> +
@@ -415,98 +423,87 @@ function triggerInstallAction(action: 'update' | 'migrate'): void { /> - - - - - +