From bf3fd889732cd239af00c6b4389f766e4b57a6d8 Mon Sep 17 00:00:00 2001 From: Vinh Trinh Date: Sun, 15 Nov 2026 05:09:36 -0500 Subject: [PATCH 1/3] feat(home): auto start checkbox on each build card and Builds page tile Each idle build card on Home and each tile on the Builds page gets an "Auto start" checkbox. It reads and writes the existing autoLaunchOnStartup setting, the same one Settings > General "Auto-launch on startup" writes, so only one build can be ticked. Ticking a build saves its id, unticking sets None, and "Last used build" ticks no card. The cards re-read the setting on settings-changed, so they follow a change made in Settings without a restart. On Home the checkbox sits beside the card's button, not inside it, so ticking it never opens the build. It shows only on idle cards. Ref DESK-302 --- e2e/home.test.ts | 20 +++ locales/en.json | 2 + locales/zh.json | 2 + .../src/composables/useAutoStartBuild.test.ts | 155 ++++++++++++++++++ .../src/composables/useAutoStartBuild.ts | 41 +++++ src/renderer/src/panel/HomeView.test.ts | 116 +++++++++++++ src/renderer/src/panel/HomeView.vue | 4 + .../src/panel/home/BuildAutoStartCheckbox.vue | 23 +++ src/renderer/src/panel/home/HomeBuildCard.vue | 102 ++++++------ src/renderer/src/views/ChooserView.test.ts | 30 ++++ .../src/views/chooser/ChooserFamilyGrid.vue | 4 + .../src/views/chooser/ChooserInstallTile.vue | 12 ++ 12 files changed, 465 insertions(+), 46 deletions(-) create mode 100644 src/renderer/src/composables/useAutoStartBuild.test.ts create mode 100644 src/renderer/src/composables/useAutoStartBuild.ts create mode 100644 src/renderer/src/panel/home/BuildAutoStartCheckbox.vue diff --git a/e2e/home.test.ts b/e2e/home.test.ts index 0a1136177..3a1336157 100644 --- a/e2e/home.test.ts +++ b/e2e/home.test.ts @@ -53,3 +53,23 @@ 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 ab1f086e2..ad52c1f53 100644 --- a/locales/en.json +++ b/locales/en.json @@ -115,6 +115,8 @@ "openComfyUIIn": "Open ComfyUI in {name}", "opensIn": "Opens in {name}", "allBuilds": "All builds", + "autoStart": "Auto start", + "autoStartHint": "Start this build when Comfy Desktop opens", "buildRunning": "Running", "buildStarting": "Starting", "buildReady": "Ready", diff --git a/locales/zh.json b/locales/zh.json index ba3af5898..9a4dfa1d1 100644 --- a/locales/zh.json +++ b/locales/zh.json @@ -115,6 +115,8 @@ "openComfyUIIn": "在 {name} 中打开 ComfyUI", "opensIn": "在 {name} 中打开", "allBuilds": "全部构建", + "autoStart": "自动启动", + "autoStartHint": "Comfy Desktop 打开时启动此构建", "buildRunning": "运行中", "buildStarting": "启动中", "buildReady": "就绪", diff --git a/src/renderer/src/composables/useAutoStartBuild.test.ts b/src/renderer/src/composables/useAutoStartBuild.test.ts new file mode 100644 index 000000000..e896e9921 --- /dev/null +++ b/src/renderer/src/composables/useAutoStartBuild.test.ts @@ -0,0 +1,155 @@ +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' +import { effectScope, type EffectScope } from 'vue' +import { flushPromises } from '@vue/test-utils' + +import { useAutoStartBuild } from './useAutoStartBuild' + +let saved: unknown +let settingsChanged: (change: { key: string }) => void +const unsubscribe = vi.fn() +const getSetting = vi.fn(async (_key: string): Promise => saved) +const setSetting = vi.fn(async (_key: string, value: unknown): Promise => { + saved = value +}) +let scope: EffectScope + +beforeEach(() => { + vi.clearAllMocks() + saved = 'none' + ;(window as unknown as { api: unknown }).api = { + getSetting, + setSetting, + onSettingsChanged: vi.fn((callback: (change: { key: string }) => void) => { + settingsChanged = callback + return unsubscribe + }) + } +}) + +afterEach(() => { + scope?.stop() +}) + +async function start() { + scope = effectScope() + const autoStart = scope.run(() => useAutoStartBuild())! + await flushPromises() + return autoStart +} + +describe('useAutoStartBuild', () => { + it('reads the Auto-launch on startup setting and ticks only the build it names', async () => { + saved = 'build-a' + const autoStart = await start() + + expect(getSetting).toHaveBeenCalledWith('autoLaunchOnStartup') + expect(autoStart.startsOnOpen('build-a')).toBe(true) + expect(autoStart.startsOnOpen('build-b')).toBe(false) + }) + + it('ticks no build for None or Last used build', async () => { + const autoStart = await start() + expect(autoStart.startsOnOpen('build-a')).toBe(false) + + saved = 'last' + settingsChanged({ key: 'autoLaunchOnStartup' }) + await flushPromises() + + expect(autoStart.startsOnOpen('build-a')).toBe(false) + }) + + it('moves the tick to a newly ticked build and saves its id in the same setting', async () => { + saved = 'build-a' + const autoStart = await start() + + await autoStart.setStartsOnOpen('build-b', true) + + expect(setSetting).toHaveBeenCalledWith('autoLaunchOnStartup', 'build-b') + expect(autoStart.startsOnOpen('build-b')).toBe(true) + expect(autoStart.startsOnOpen('build-a')).toBe(false) + }) + + it('replaces Last used build with the build that is ticked', async () => { + saved = 'last' + const autoStart = await start() + + await autoStart.setStartsOnOpen('build-a', true) + + expect(setSetting).toHaveBeenCalledWith('autoLaunchOnStartup', 'build-a') + }) + + it('sets None when the ticked build is unticked', async () => { + saved = 'build-a' + const autoStart = await start() + + await autoStart.setStartsOnOpen('build-a', false) + + expect(setSetting).toHaveBeenCalledWith('autoLaunchOnStartup', 'none') + expect(autoStart.startsOnOpen('build-a')).toBe(false) + }) + + it('writes nothing when a build is already in the state asked for', async () => { + saved = 'build-a' + const autoStart = await start() + + await autoStart.setStartsOnOpen('build-a', true) + await autoStart.setStartsOnOpen('build-b', false) + + expect(setSetting).not.toHaveBeenCalled() + }) + + it('follows a change made in Settings without a restart, and ignores other settings', async () => { + saved = 'build-a' + const autoStart = await start() + getSetting.mockClear() + + saved = 'build-b' + settingsChanged({ key: 'hideCloudFromPicker' }) + await flushPromises() + expect(getSetting).not.toHaveBeenCalled() + expect(autoStart.startsOnOpen('build-a')).toBe(true) + + settingsChanged({ key: 'autoLaunchOnStartup' }) + await flushPromises() + expect(autoStart.startsOnOpen('build-b')).toBe(true) + expect(autoStart.startsOnOpen('build-a')).toBe(false) + }) + + it('keeps a tick made while the first read is still on its way', async () => { + let answer: (value: unknown) => void = () => {} + getSetting.mockImplementationOnce( + () => + new Promise((resolve) => { + answer = resolve + }) + ) + scope = effectScope() + const autoStart = scope.run(() => useAutoStartBuild())! + + await autoStart.setStartsOnOpen('build-b', true) + answer('build-a') + await flushPromises() + + expect(autoStart.startsOnOpen('build-b')).toBe(true) + expect(autoStart.startsOnOpen('build-a')).toBe(false) + }) + + it('shows the saved choice again when saving fails', async () => { + saved = 'build-a' + const autoStart = await start() + setSetting.mockRejectedValueOnce(new Error('settings.json is unreadable')) + + await autoStart.setStartsOnOpen('build-b', true) + + expect(autoStart.startsOnOpen('build-a')).toBe(true) + expect(autoStart.startsOnOpen('build-b')).toBe(false) + }) + + it('stops listening for setting changes when its page goes away', async () => { + await start() + + scope.stop() + + expect(unsubscribe).toHaveBeenCalledTimes(1) + }) +}) diff --git a/src/renderer/src/composables/useAutoStartBuild.ts b/src/renderer/src/composables/useAutoStartBuild.ts new file mode 100644 index 000000000..78fd76476 --- /dev/null +++ b/src/renderer/src/composables/useAutoStartBuild.ts @@ -0,0 +1,41 @@ +import { onScopeDispose, ref } from 'vue' + +const AUTO_START_SETTING = 'autoLaunchOnStartup' +const AUTO_START_NONE = 'none' + +export function useAutoStartBuild() { + const autoStartValue = ref(undefined) + let revision = 0 + + async function read(): Promise { + const seen = ++revision + try { + const value = await window.api.getSetting(AUTO_START_SETTING) + if (seen === revision) autoStartValue.value = value + } catch {} + } + + const unsubscribe = window.api.onSettingsChanged(({ key }) => { + if (key === AUTO_START_SETTING) void read() + }) + onScopeDispose(unsubscribe) + void read() + + function startsOnOpen(buildId: string): boolean { + return autoStartValue.value === buildId + } + + async function setStartsOnOpen(buildId: string, on: boolean): Promise { + if (on === startsOnOpen(buildId)) return + const next = on ? buildId : AUTO_START_NONE + revision++ + autoStartValue.value = next + try { + await window.api.setSetting(AUTO_START_SETTING, next) + } catch { + await read() + } + } + + return { startsOnOpen, setStartsOnOpen } +} diff --git a/src/renderer/src/panel/HomeView.test.ts b/src/renderer/src/panel/HomeView.test.ts index d564adbb6..fa4ce9f4a 100644 --- a/src/renderer/src/panel/HomeView.test.ts +++ b/src/renderer/src/panel/HomeView.test.ts @@ -4,7 +4,9 @@ import { createPinia, setActivePinia } from 'pinia' 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>() @@ -674,3 +676,117 @@ describe('Home builds', () => { expect(wrapper.find('[data-testid="home-open-comfyui"]').exists()).toBe(false) }) }) + +describe('Home build auto start', () => { + let saved: unknown + let settingsChanged: (change: { key: string }) => void + const setSetting = vi.fn(async (_key: string, value: unknown) => { + saved = value + }) + + beforeEach(() => { + saved = 'none' + Object.assign(window.api, { + getSetting: vi.fn(async (key: string) => (key === 'autoLaunchOnStartup' ? saved : undefined)), + setSetting, + onSettingsChanged: vi.fn((callback: (change: { key: string }) => void) => { + settingsChanged = callback + return () => {} + }) + }) + }) + + function autoStartBox(wrapper: VueWrapper, id: string) { + return wrapper.get( + `[data-testid="home-build-auto-start"][data-build-id="${id}"] [role="checkbox"]` + ) + } + + function ticked(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')!) + } + + it('ticks the card of the build that starts when Desktop opens', async () => { + saved = OLDEST.id + getInstallations.mockResolvedValue([OLDEST, CLOUD, NEWEST]) + const wrapper = await openHome() + + expect(wrapper.findAll('[data-testid="home-build-auto-start"]')).toHaveLength(3) + expect(ticked(wrapper)).toEqual([OLDEST.id]) + }) + + it('moves the tick to Comfy Cloud when its box is ticked, without opening it', async () => { + saved = OLDEST.id + getInstallations.mockResolvedValue([OLDEST, CLOUD]) + const wrapper = await openHome() + + await setChecked(autoStartBox(wrapper, CLOUD.id), true) + await flushPromises() + + expect(setSetting).toHaveBeenCalledWith('autoLaunchOnStartup', CLOUD.id) + expect(ticked(wrapper)).toEqual([CLOUD.id]) + expect(wrapper.emitted('pick')).toBeUndefined() + expect(wrapper.emitted('open-build')).toBeUndefined() + }) + + it('sets None when the ticked card is unticked', async () => { + saved = NEWEST.id + getInstallations.mockResolvedValue([OLDEST, NEWEST]) + const wrapper = await openHome() + + await setChecked(autoStartBox(wrapper, NEWEST.id), false) + await flushPromises() + + expect(setSetting).toHaveBeenCalledWith('autoLaunchOnStartup', 'none') + expect(ticked(wrapper)).toEqual([]) + }) + + it('ticks no card when Settings says Last used build', async () => { + saved = 'last' + getInstallations.mockResolvedValue([OLDEST, NEWEST]) + const wrapper = await openHome() + + expect(ticked(wrapper)).toEqual([]) + }) + + it('follows a build picked in Settings without a restart', async () => { + saved = OLDEST.id + getInstallations.mockResolvedValue([OLDEST, NEWEST]) + const wrapper = await openHome() + + saved = NEWEST.id + settingsChanged({ key: 'autoLaunchOnStartup' }) + await flushPromises() + + expect(ticked(wrapper)).toEqual([NEWEST.id]) + }) + + it('leaves the box off a card while its build installs', async () => { + Object.assign(window.api, { + onInstallProgress: vi.fn(() => () => {}), + onComfyOutput: vi.fn(() => () => {}) + }) + getInstallations.mockResolvedValue([OLDEST, NEWEST]) + const wrapper = await openHome() + + useProgressStore().startOperation({ + installationId: NEWEST.id, + title: 'Installing', + opKind: 'install', + apiCall: () => new Promise(() => {}) + }) + await flushPromises() + + expect( + wrapper.find(`[data-testid="home-build-installing"][data-build-id="${NEWEST.id}"]`).exists() + ).toBe(true) + expect( + wrapper + .findAll('[data-testid="home-build-auto-start"]') + .map((box) => box.attributes('data-build-id')) + ).toEqual([OLDEST.id]) + }) +}) diff --git a/src/renderer/src/panel/HomeView.vue b/src/renderer/src/panel/HomeView.vue index 911983df5..12870c9ab 100644 --- a/src/renderer/src/panel/HomeView.vue +++ b/src/renderer/src/panel/HomeView.vue @@ -10,6 +10,7 @@ import HomeCarousel from './home/HomeCarousel.vue' import { homeBuildStatus, homeBuildTones, isCloudBuild } from './home/homeBuild' import { useHomeApps } from './home/useHomeApps' import { useInstallList } from '../composables/useInstallList' +import { useAutoStartBuild } from '../composables/useAutoStartBuild' import { buildProgressOf, launchFailed, @@ -55,6 +56,7 @@ const workspaceBuilds = computed(() => const isInstalling = useInstallingBuilds() const progressStore = useProgressStore() const viewBuildLogs = useViewBuildLogs() +const autoStart = useAutoStartBuild() const builds = computed(() => [ ...workspaceBuilds.value.filter((build) => isInstalling(build.id)), @@ -271,7 +273,9 @@ onMounted(() => { :build="build" :status="buildStatus(build)" :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/home/BuildAutoStartCheckbox.vue b/src/renderer/src/panel/home/BuildAutoStartCheckbox.vue new file mode 100644 index 000000000..ebd588d25 --- /dev/null +++ b/src/renderer/src/panel/home/BuildAutoStartCheckbox.vue @@ -0,0 +1,23 @@ + + + diff --git a/src/renderer/src/panel/home/HomeBuildCard.vue b/src/renderer/src/panel/home/HomeBuildCard.vue index daa07f8f3..1cbdd27d9 100644 --- a/src/renderer/src/panel/home/HomeBuildCard.vue +++ b/src/renderer/src/panel/home/HomeBuildCard.vue @@ -5,6 +5,7 @@ import { Check, LoaderCircle, OctagonAlert } from '@lucide/vue' import Button from '@comfyorg/design-system/button/Button' import BuildDeviceArt from './BuildDeviceArt.vue' import BuildProgressBar from './BuildProgressBar.vue' +import BuildAutoStartCheckbox from './BuildAutoStartCheckbox.vue' import { HOME_BUILD_TONES, homeBuildDetail, @@ -21,9 +22,10 @@ const { build, status, tone } = defineProps<{ build: Installation status: HomeBuildStatus tone: HomeBuildTone + autoStart?: boolean }>() -const emit = defineEmits<{ open: [] }>() +const emit = defineEmits<{ open: []; 'auto-start': [on: boolean] }>() const { t } = useI18n() const install = useBuildProgress(() => build) @@ -139,52 +141,60 @@ const CARD_CLASS = data-testid="home-build-progress" /> - + + + diff --git a/src/renderer/src/views/ChooserView.test.ts b/src/renderer/src/views/ChooserView.test.ts index b007c0678..419ad966b 100644 --- a/src/renderer/src/views/ChooserView.test.ts +++ b/src/renderer/src/views/ChooserView.test.ts @@ -11,6 +11,7 @@ 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', () => ({ @@ -258,6 +259,35 @@ 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 () => { + const api = installMockApi([ + makeInstall({ id: 'a', name: 'Alpha' }), + makeInstall({ id: 'b', name: 'Beta' }) + ]) + api.getSetting.mockImplementation(async (key: string) => + key === 'autoLaunchOnStartup' ? 'a' : undefined + ) + 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') + + await setChecked(autoStartBox('b'), true) + await flushPromises() + + expect(api.setSetting).toHaveBeenCalledWith('autoLaunchOnStartup', 'b') + expect(autoStartBox('a').attributes('aria-checked')).toBe('false') + expect(wrapper.emitted('open-details')).toBeUndefined() + expect(wrapper.emitted('pick')).toBeUndefined() + + await setChecked(autoStartBox('b'), false) + await flushPromises() + + expect(api.setSetting).toHaveBeenLastCalledWith('autoLaunchOnStartup', 'none') + expect(wrapper.emitted('open-details')).toBeUndefined() + }) + it('shows Update beside Start and keeps Start as the action', async () => { installMockApi([ makeInstall({ diff --git a/src/renderer/src/views/chooser/ChooserFamilyGrid.vue b/src/renderer/src/views/chooser/ChooserFamilyGrid.vue index dd14f4fe8..382d2f72a 100644 --- a/src/renderer/src/views/chooser/ChooserFamilyGrid.vue +++ b/src/renderer/src/views/chooser/ChooserFamilyGrid.vue @@ -3,6 +3,7 @@ import { computed } from 'vue' import ChooserInstallTile from './ChooserInstallTile.vue' import { homeBuildTones } from '../../panel/home/homeBuild' import { useInstallationStore } from '../../stores/installationStore' +import { useAutoStartBuild } from '../../composables/useAutoStartBuild' import type { Installation } from '../../types/ipc' const props = withDefaults( @@ -33,6 +34,7 @@ const emit = defineEmits<{ const installationStore = useInstallationStore() const tones = computed(() => homeBuildTones(props.installations, installationStore.installations)) +const autoStart = useAutoStartBuild() function lockLeavingTileSize(el: Element): void { const node = el as HTMLElement @@ -77,6 +79,7 @@ function unlockTileSize(el: Element): void { :show-why-cloud="props.showWhyCloud && installation.sourceCategory === 'cloud'" :is-stopped-action-gated="props.isStoppedActionGated(installation)" :is-promoting-to-workspace="props.isPromotingToWorkspace(installation)" + :auto-start="autoStart.startsOnOpen(installation.id)" @why-cloud="emit('why-cloud')" @pick="emit('pick', $event)" @open-details="emit('open-details', $event)" @@ -85,6 +88,7 @@ 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 d9f34dbf0..a230aa792 100644 --- a/src/renderer/src/views/chooser/ChooserInstallTile.vue +++ b/src/renderer/src/views/chooser/ChooserInstallTile.vue @@ -27,6 +27,7 @@ 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' @@ -41,6 +42,7 @@ interface Props { showMenu?: boolean showFreeRunsPill?: boolean tone?: HomeBuildTone + autoStart?: boolean } const props = withDefaults(defineProps(), { @@ -58,6 +60,7 @@ const emit = defineEmits<{ 'view-error': [installation: Installation] 'view-danger': [installation: Installation] 'why-cloud': [] + 'auto-start': [installation: Installation, on: boolean] }>() const { t } = useI18n() @@ -461,6 +464,15 @@ function triggerInstallAction(action: 'update' | 'migrate'): void { {{ actionPill.label }} + -