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..d4127828b --- /dev/null +++ b/src/renderer/src/composables/useAutoStartBuild.test.ts @@ -0,0 +1,195 @@ +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('shows the saved choice again when saving and reading it back both fail, so a second tick saves again', async () => { + saved = 'build-a' + const autoStart = await start() + setSetting.mockRejectedValueOnce(new Error('settings.json is unreadable')) + getSetting.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) + + await autoStart.setStartsOnOpen('build-b', true) + + expect(setSetting).toHaveBeenCalledTimes(2) + expect(setSetting).toHaveBeenLastCalledWith('autoLaunchOnStartup', 'build-b') + expect(autoStart.startsOnOpen('build-b')).toBe(true) + }) + + it('keeps a newer tick when the read after a failed save also fails', async () => { + saved = 'build-a' + const autoStart = await start() + let failRead: (error: Error) => void = () => {} + setSetting.mockRejectedValueOnce(new Error('settings.json is unreadable')) + getSetting.mockImplementationOnce( + () => + new Promise((_resolve, reject) => { + failRead = reject + }) + ) + + const failedSave = autoStart.setStartsOnOpen('build-b', true) + await flushPromises() + await autoStart.setStartsOnOpen('build-c', true) + failRead(new Error('settings.json is unreadable')) + await failedSave + + expect(autoStart.startsOnOpen('build-c')).toBe(true) + expect(autoStart.startsOnOpen('build-a')).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..e4e19a3b3 --- /dev/null +++ b/src/renderer/src/composables/useAutoStartBuild.ts @@ -0,0 +1,47 @@ +import { onScopeDispose, ref } from 'vue' + +const AUTO_START_SETTING = 'autoLaunchOnStartup' +const AUTO_START_NONE = 'none' + +export function useAutoStartBuild() { + const autoStartValue = ref(undefined) + let confirmedValue: unknown = undefined + let revision = 0 + + async function read(): Promise { + const seen = ++revision + try { + const value = await window.api.getSetting(AUTO_START_SETTING) + if (seen !== revision) return + confirmedValue = value + autoStartValue.value = value + } catch { + if (seen === revision) autoStartValue.value = confirmedValue + } + } + + 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) + confirmedValue = 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..fc8ac48d0 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,118 @@ describe('Home builds', () => { expect(wrapper.find('[data-testid="home-open-comfyui"]').exists()).toBe(false) }) }) + +describe('Home build auto start', () => { + let saved: unknown + let settingsListeners: Array<(change: { key: string }) => void> + const setSetting = vi.fn(async (_key: string, value: unknown) => { + saved = value + }) + + beforeEach(() => { + saved = 'none' + settingsListeners = [] + Object.assign(window.api, { + getSetting: vi.fn(async (key: string) => (key === 'autoLaunchOnStartup' ? saved : undefined)), + setSetting, + onSettingsChanged: vi.fn((callback: (change: { key: string }) => void) => { + settingsListeners.push(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 + for (const listener of settingsListeners) listener({ 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/autoStartNarrowLayout.test.ts b/src/renderer/src/panel/autoStartNarrowLayout.test.ts new file mode 100644 index 000000000..bad2fd5ca --- /dev/null +++ b/src/renderer/src/panel/autoStartNarrowLayout.test.ts @@ -0,0 +1,125 @@ +import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest' +import { page as browserPage } from 'vitest/browser' +import { flushPromises, mount, type VueWrapper } from '@vue/test-utils' +import { createPinia, setActivePinia } from 'pinia' + +import '../assets/main.css' +import HomeView from './HomeView.vue' +import ChooserFamilyGrid from '../views/chooser/ChooserFamilyGrid.vue' +import { TID } from '../../../shared/testIds' +import type { Installation } from '../types/ipc' + +const SMALLEST_WINDOW_WIDTH = 800 +const LARGE_WINDOW_WIDTH = 1024 +const FRAME_AND_EXPANDED_SIDEBAR_WIDTH = 16 + 8 + 244 +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 HOME_CARD_SIDE_PADDING_AND_BORDER = 18 + 1 +const BUILDS_TILE_RIGHT_PADDING = 12 +const READABLE_NAME_WIDTH = 40 + +function build(id: string, name: string, lastLaunchedAt: number): Installation { + return { id, name, lastLaunchedAt, sourceLabel: 'Standalone', sourceCategory: 'local' } +} + +const STUDIO = build('studio', 'Flux Sandbox for the long weekend render', 400) +const PORTRAITS = build('portraits', 'Portrait retouching with the new upscaler', 300) + +let page: HTMLElement + +function boxOf(element: Element): DOMRect { + return element.getBoundingClientRect() +} + +function onlyIn(wrapper: VueWrapper, selector: string): Element { + return wrapper.get(selector).element +} + +beforeAll(() => browserPage.viewport(1280, 1400)) + +beforeEach(() => { + ;(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([STUDIO, PORTRAITS]), + onInstallationsChanged: vi.fn(() => () => {}), + onInstallationsVersionsUpdated: vi.fn(() => () => {}), + onInstallProgress: vi.fn(() => () => {}), + onComfyOutput: vi.fn(() => () => {}), + getSetting: vi.fn().mockResolvedValue('none'), + setSetting: vi.fn().mockResolvedValue(undefined), + onSettingsChanged: vi.fn(() => () => {}), + comfybuilder: { + getAuthStatus: vi.fn().mockResolvedValue({ signedIn: false }), + onAuthChanged: vi.fn(() => () => {}) + } + } + setActivePinia(createPinia()) + page = document.createElement('div') + document.body.append(page) +}) + +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 () => { + page.style.cssText = `position: absolute; left: 0; top: 0; width: ${HOME_WIDTH_IN_SMALLEST_WINDOW}px` + const wrapper = mount(HomeView, { attachTo: page }) + await flushPromises() + + for (const { id } of [STUDIO, PORTRAITS]) { + const card = onlyIn(wrapper, `button[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(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() + + 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) + + 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) + } + }) +}) 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..b5225f5c3 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..02a467762 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() @@ -412,87 +415,98 @@ function triggerInstallAction(action: 'update' | 'migrate'): void { /> -