From 716959e3d6062744e0e07b94afc7bb113800fd83 Mon Sep 17 00:00:00 2001 From: Benjamin Lu Date: Mon, 16 Nov 2026 10:16:22 -0800 Subject: [PATCH 1/7] =?UTF-8?q?feat(titlebar):=20Home=20button=20in=20buil?= =?UTF-8?q?d=20windows,=20and=20the=20=E2=98=B0=20menu=20on=20the=20right?= =?UTF-8?q?=20(DESK-293)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A build window's title bar now starts with a Home button. It brings the Desktop window to the front, or opens one when none is open. The Desktop window itself has no Home button. The ☰ menu moves to the right end of the title bar in every window, after Downloads, and refresh moves to the right with the other build controls. Why: once a build opened in the Desktop window there was no way back to Desktop (Alexis, 1.1.11 QA, Nov 12). Pablo and Alexis settled on Home in build windows only and the ☰ on the right. The layout follows Mar's title bar in the New-Home Figma (Components > Organisms/Title bar, and the M2 Apps title bars): house icon and "Home" at 13px, no fill at rest, a grey pill on hover, ☰ last on the right. Home skips a Desktop window that is turning into a build window (it has claimed a launch or is previewing one), so it never brings forward a window that is about to show ComfyUI. This redoes the title bar part of Comfy-Org/Comfy-Desktop#2027 on main. That PR also opens every build in its own window; that is left for a separate change. --- locales/en.json | 1 + locales/zh.json | 1 + src/main/host/registry.test.ts | 68 +++++++++++ src/main/host/registry.ts | 22 ++++ src/main/index.ts | 8 ++ src/preload/comfyTitleBarPreload.ts | 4 + .../src/comfyTitleBar/TitleBarApp.test.ts | 108 +++++++++++++++++- .../src/comfyTitleBar/TitleBarApp.vue | 58 +++++++--- 8 files changed, 247 insertions(+), 23 deletions(-) diff --git a/locales/en.json b/locales/en.json index 2ea667807..c457f752d 100644 --- a/locales/en.json +++ b/locales/en.json @@ -241,6 +241,7 @@ "appUpdateReady": "Restart to update", "installUpdateAvailable": "Update available", "installUpdateShort": "Update", + "home": "Home", "menu": "Menu", "feedback": "Feedback", "feedbackTooltip": "Send Feedback", diff --git a/locales/zh.json b/locales/zh.json index 228c181d0..502ac2d03 100644 --- a/locales/zh.json +++ b/locales/zh.json @@ -241,6 +241,7 @@ "appUpdateReady": "重启以更新", "installUpdateAvailable": "有可用更新", "installUpdateShort": "更新", + "home": "主页", "menu": "菜单", "feedback": "反馈", "feedbackTooltip": "发送反馈", diff --git a/src/main/host/registry.test.ts b/src/main/host/registry.test.ts index 7c65453d9..a9f280553 100644 --- a/src/main/host/registry.test.ts +++ b/src/main/host/registry.test.ts @@ -32,6 +32,7 @@ import { indexInstallationId, nextWindowKey, forceRevealHostWindow, + openOrFocusHomeHostWindow, hasRunningSessionForEntry, raiseAllHostWindows, registerHostEntry, @@ -601,3 +602,70 @@ describe('raiseAllHostWindows', () => { expect(fakeWin(min).raised).toContain('focus') }) }) + +describe('openOrFocusHomeHostWindow', () => { + function fakeWin(entry: ComfyWindowEntry): FakeWindow { + return entry.window as unknown as FakeWindow + } + + function trackChooserFactory(): ReturnType { + const createChooser = vi.fn(() => makeWindow() as unknown as ComfyWindowEntry['window']) + setHostFactories({ createChooser }) + return createChooser + } + + it('brings the open Desktop window to the front instead of opening another', () => { + const createChooser = trackChooserFactory() + const home = makeEntry({ installationId: null }) + const build = makeEntry({ installationId: 'inst-A' }) + registerHostEntry(home) + registerHostEntry(build) + + expect(openOrFocusHomeHostWindow()).toBe(home.window) + expect(fakeWin(home).raised).toContain('focus') + expect(fakeWin(build).raised).toEqual([]) + expect(createChooser).not.toHaveBeenCalled() + }) + + it('restores a minimised Desktop window', () => { + const createChooser = trackChooserFactory() + const home = makeEntry({ installationId: null, minimized: true }) + registerHostEntry(home) + + expect(openOrFocusHomeHostWindow()).toBe(home.window) + expect(fakeWin(home).raised).toEqual(expect.arrayContaining(['restore', 'focus'])) + expect(createChooser).not.toHaveBeenCalled() + }) + + it('opens a Desktop window when only build windows are open', () => { + const createChooser = trackChooserFactory() + registerHostEntry(makeEntry({ installationId: 'inst-A' })) + registerHostEntry(makeEntry({ installationId: 'inst-B' })) + + openOrFocusHomeHostWindow() + expect(createChooser).toHaveBeenCalledTimes(1) + }) + + it('opens a Desktop window when the only one is turning into a build window', () => { + const createChooser = trackChooserFactory() + const claimed = makeEntry({ installationId: null }) + const previewing = makeEntry({ installationId: null }) + previewing.previewInstallationId = 'inst-B' + registerHostEntry(claimed) + registerHostEntry(previewing) + claimAttachHost('inst-A', claimed.windowKey) + + openOrFocusHomeHostWindow() + expect(createChooser).toHaveBeenCalledTimes(1) + expect(fakeWin(claimed).raised).toEqual([]) + expect(fakeWin(previewing).raised).toEqual([]) + }) + + it('skips a closed Desktop window', () => { + const createChooser = trackChooserFactory() + registerHostEntry(makeEntry({ installationId: null, destroyed: true })) + + openOrFocusHomeHostWindow() + expect(createChooser).toHaveBeenCalledTimes(1) + }) +}) diff --git a/src/main/host/registry.ts b/src/main/host/registry.ts index 6d76b1946..e6166c3ca 100644 --- a/src/main/host/registry.ts +++ b/src/main/host/registry.ts @@ -327,6 +327,28 @@ export function openOrFocusChooserHostWindow(): BrowserWindow { return requireChooserFactory()() } +function isHandingOffToBuild(entry: ComfyWindowEntry): boolean { + if (entry.previewInstallationId !== null) return true + for (const claimedKey of pendingAttachClaims.values()) { + if (claimedKey === entry.windowKey) return true + } + return false +} + +function findHomeHostWindow(): BrowserWindow | null { + const entry = findPreferredHostByVisibility((e) => isChooserHost(e) && !isHandingOffToBuild(e)) + return entry?.window ?? null +} + +export function openOrFocusHomeHostWindow(): BrowserWindow { + const existing = findHomeHostWindow() + if (existing) { + bringToFront(existing) + return existing + } + return requireChooserFactory()() +} + export function openOrFocusAnyHostWindow(): BrowserWindow { const installWin = findPreferredInstallHostWindow() if (installWin) { diff --git a/src/main/index.ts b/src/main/index.ts index 89b51ea66..6bcffbd9e 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -147,6 +147,7 @@ import { isInstallHost, openOrFocusAnyHostWindow, openOrFocusChooserHostWindow, + openOrFocusHomeHostWindow, raiseAllHostWindows, setHostFactories, shouldConfirmKillForEntry @@ -759,6 +760,13 @@ ipcMain.on('comfy-window:new-chooser-window', () => { openChooserHostWindow() }) +ipcMain.on('comfy-window:show-home', (event) => { + const found = findEntryByTitleBarSender(event.sender) + if (!found || !isInstallHost(found.entry)) return + recordIpcInvocation('comfy-window:show-home') + openOrFocusHomeHostWindow() +}) + function focusOpenComfyWindow(installationId: string): boolean { const entry = getEntryByInstallationId(installationId) if (!entry || entry.window.isDestroyed()) return false diff --git a/src/preload/comfyTitleBarPreload.ts b/src/preload/comfyTitleBarPreload.ts index dae5abd25..22f68d036 100644 --- a/src/preload/comfyTitleBarPreload.ts +++ b/src/preload/comfyTitleBarPreload.ts @@ -76,6 +76,7 @@ export interface ComfyTitleBarBridge { clickFeedback(): void clickAnnouncement(): void clickRefreshInstance(): void + clickHome(): void resetZoom(): void showTooltip(payload: { text: string; leftX: number; rightX: number; bottomY: number }): void hideTooltip(): void @@ -266,6 +267,9 @@ const bridge: ComfyTitleBarBridge = { clickRefreshInstance: () => { ipcRenderer.send('comfy-window:click-refresh-instance') }, + clickHome: () => { + ipcRenderer.send('comfy-window:show-home') + }, resetZoom: () => { ipcRenderer.send('comfy-window:reset-zoom') }, diff --git a/src/renderer/src/comfyTitleBar/TitleBarApp.test.ts b/src/renderer/src/comfyTitleBar/TitleBarApp.test.ts index 88c2cbb33..d76663291 100644 --- a/src/renderer/src/comfyTitleBar/TitleBarApp.test.ts +++ b/src/renderer/src/comfyTitleBar/TitleBarApp.test.ts @@ -48,6 +48,7 @@ interface MockBridgeState { installPillClicks: { x: number; y: number }[] feedbackClicks: number refreshInstanceClicks: number + homeClicks: number resetZoomClicks: number showTooltipCalls: { text: string; leftX: number; rightX: number; bottomY: number }[] hideTooltipCalls: number @@ -98,6 +99,7 @@ function installMockBridge( installPillClicks: [], feedbackClicks: 0, refreshInstanceClicks: 0, + homeClicks: 0, resetZoomClicks: 0, showTooltipCalls: [], hideTooltipCalls: 0, @@ -209,6 +211,9 @@ function installMockBridge( clickRefreshInstance: () => { state.refreshInstanceClicks += 1 }, + clickHome: () => { + state.homeClicks += 1 + }, resetZoom: () => { state.resetZoomClicks += 1 }, @@ -410,7 +415,7 @@ describe('TitleBarApp', () => { const { default: TitleBarApp } = await import('./TitleBarApp.vue') const wrapper = mount(TitleBarApp) await flushPromises() - expect(wrapper.find('.title-menu-button--icon').exists()).toBe(true) + expect(wrapper.find('.title-menu-button[aria-haspopup="menu"]').exists()).toBe(true) expect(wrapper.find('.title-downloads-tray').exists()).toBe(true) expect(wrapper.find('.title-feedback-button').exists()).toBe(true) expect(wrapper.find('.title-install-pill.is-interactive').exists()).toBe(true) @@ -419,7 +424,7 @@ describe('TitleBarApp', () => { bridgeState.firstUseModeChangedCallbacks.forEach((cb) => cb('consent-lockdown')) await flushPromises() expect(wrapper.find('header').classes()).toContain('is-consent-lockdown') - expect(wrapper.find('.title-menu-button--icon').exists()).toBe(false) + expect(wrapper.find('.title-menu-button[aria-haspopup="menu"]').exists()).toBe(false) expect(wrapper.find('.title-downloads-tray').exists()).toBe(false) expect(wrapper.find('.title-feedback-button').exists()).toBe(false) expect(wrapper.find('.title-install-pill.is-interactive').exists()).toBe(false) @@ -427,7 +432,7 @@ describe('TitleBarApp', () => { bridgeState.firstUseModeChangedCallbacks.forEach((cb) => cb('post-consent')) await flushPromises() expect(wrapper.find('header').classes()).not.toContain('is-consent-lockdown') - expect(wrapper.find('.title-menu-button--icon').exists()).toBe(true) + expect(wrapper.find('.title-menu-button[aria-haspopup="menu"]').exists()).toBe(true) expect(wrapper.find('.title-downloads-tray').exists()).toBe(false) expect(wrapper.find('.title-feedback-button').exists()).toBe(false) expect(wrapper.find('.title-install-pill.is-interactive').exists()).toBe(false) @@ -435,7 +440,7 @@ describe('TitleBarApp', () => { bridgeState.firstUseModeChangedCallbacks.forEach((cb) => cb('loading-lockdown')) await flushPromises() expect(wrapper.find('header').classes()).not.toContain('is-consent-lockdown') - expect(wrapper.find('.title-menu-button--icon').exists()).toBe(true) + expect(wrapper.find('.title-menu-button[aria-haspopup="menu"]').exists()).toBe(true) expect(wrapper.find('.title-downloads-tray').exists()).toBe(true) expect(wrapper.find('.title-feedback-button').exists()).toBe(true) expect(wrapper.find('.title-install-pill.is-interactive').exists()).toBe(true) @@ -443,13 +448,106 @@ describe('TitleBarApp', () => { bridgeState.firstUseModeChangedCallbacks.forEach((cb) => cb('none')) await flushPromises() expect(wrapper.find('header').classes()).not.toContain('is-consent-lockdown') - expect(wrapper.find('.title-menu-button--icon').exists()).toBe(true) + expect(wrapper.find('.title-menu-button[aria-haspopup="menu"]').exists()).toBe(true) expect(wrapper.find('.title-downloads-tray').exists()).toBe(true) expect(wrapper.find('.title-feedback-button').exists()).toBe(true) expect(wrapper.find('.title-install-pill.is-interactive').exists()).toBe(true) wrapper.unmount() }) + describe('Home button and the ☰ on the right', () => { + const menuButton = '.title-menu-button[aria-haspopup="menu"]' + + it('puts Home alone on the left of a build window and sends the click to the Desktop window', async () => { + const { default: TitleBarApp } = await import('./TitleBarApp.vue') + const wrapper = mount(TitleBarApp) + await flushPromises() + bridgeState.sourceCategoryChangedCallbacks.forEach((cb) => cb('local')) + await flushPromises() + + const leading = wrapper.find('.title-cluster') + const home = leading.find('.title-home-button') + expect(home.exists()).toBe(true) + expect(home.text()).toBe('Home') + expect(leading.find(menuButton).exists()).toBe(false) + expect(leading.find('.title-refresh-button').exists()).toBe(false) + + await home.trigger('click') + expect(bridgeState.homeClicks).toBe(1) + wrapper.unmount() + }) + + it("ends the right side with the ☰, after refresh, What's new, Feedback and Downloads", async () => { + const { default: TitleBarApp } = await import('./TitleBarApp.vue') + const wrapper = mount(TitleBarApp) + await flushPromises() + bridgeState.sourceCategoryChangedCallbacks.forEach((cb) => cb('local')) + await flushPromises() + + const trailing = wrapper.find('.title-trailing').element + const controls: [string, string][] = [ + ['.title-refresh-button', 'refresh'], + ['.title-announcement-button', 'whats-new'], + ['.title-feedback-button', 'feedback'], + ['.title-downloads-tray', 'downloads'], + [menuButton, 'menu'] + ] + const order = Array.from(trailing.children).flatMap((el) => + controls.filter(([selector]) => el.matches(selector)).map(([, name]) => name) + ) + expect(order).toEqual(['refresh', 'whats-new', 'feedback', 'downloads', 'menu']) + wrapper.unmount() + }) + + it('shows no Home button in the Desktop window, and keeps its ☰ on the right', async () => { + bridgeState = installMockBridge({ installationId: null }) + vi.resetModules() + const { default: TitleBarApp } = await import('./TitleBarApp.vue') + const wrapper = mount(TitleBarApp) + await flushPromises() + + expect(wrapper.find('.title-home-button').exists()).toBe(false) + expect(wrapper.find('.title-cluster').element.children.length).toBe(0) + expect(wrapper.find('.title-trailing').element.lastElementChild?.matches(menuButton)).toBe( + true + ) + wrapper.unmount() + }) + + it('adds Home when the Desktop window starts a build in place', async () => { + bridgeState = installMockBridge({ installationId: null }) + vi.resetModules() + const { default: TitleBarApp } = await import('./TitleBarApp.vue') + const wrapper = mount(TitleBarApp) + await flushPromises() + expect(wrapper.find('.title-home-button').exists()).toBe(false) + + bridgeState.installationIdChangedCallbacks.forEach((cb) => cb('inst-started-here')) + await flushPromises() + expect(wrapper.find('.title-home-button').exists()).toBe(true) + wrapper.unmount() + }) + + it('hides Home through the first-use takeover and brings it back for loading', async () => { + const { default: TitleBarApp } = await import('./TitleBarApp.vue') + const wrapper = mount(TitleBarApp) + await flushPromises() + + bridgeState.firstUseModeChangedCallbacks.forEach((cb) => cb('consent-lockdown')) + await flushPromises() + expect(wrapper.find('.title-home-button').exists()).toBe(false) + + bridgeState.firstUseModeChangedCallbacks.forEach((cb) => cb('post-consent')) + await flushPromises() + expect(wrapper.find('.title-home-button').exists()).toBe(false) + + bridgeState.firstUseModeChangedCallbacks.forEach((cb) => cb('loading-lockdown')) + await flushPromises() + expect(wrapper.find('.title-home-button').exists()).toBe(true) + wrapper.unmount() + }) + }) + it('toggles is-fullscreen in response to onFullscreenChanged', async () => { const { default: TitleBarApp } = await import('./TitleBarApp.vue') const wrapper = mount(TitleBarApp) diff --git a/src/renderer/src/comfyTitleBar/TitleBarApp.vue b/src/renderer/src/comfyTitleBar/TitleBarApp.vue index 914dde843..134b2e789 100644 --- a/src/renderer/src/comfyTitleBar/TitleBarApp.vue +++ b/src/renderer/src/comfyTitleBar/TitleBarApp.vue @@ -6,6 +6,7 @@ import { Bell, ChevronDown, CloudDownload, + House, Loader2, Menu as MenuIcon, MessageSquarePlus, @@ -113,6 +114,7 @@ interface Bridge { clickFeedback: () => void clickAnnouncement: () => void clickRefreshInstance: () => void + clickHome: () => void resetZoom: () => void ready: () => void } @@ -139,6 +141,9 @@ const titleInstallPillClass = [ '[.title-bar.is-light_&.is-interactive.is-open]:border-[color-mix(in_srgb,var(--neutral-700)_55%,transparent)] [.title-bar.is-light_&.is-interactive.is-open]:text-neutral-700' ].join(' ') +const titleHomeButtonClass = + '[-webkit-app-region:no-drag] inline-flex h-7 shrink-0 items-center gap-2 rounded-control border border-solid border-transparent bg-transparent py-0 pr-2.5 pl-2 [font-family:inherit] text-[13px] leading-5 font-normal text-[var(--titlebar-icon)] opacity-85 cursor-pointer transition-[background-color,opacity] duration-[120ms] ease-[ease] [.title-bar.is-hover-active_&]:hover:opacity-100 [.title-bar.is-hover-active_&]:hover:bg-secondary focus-visible:outline-2 focus-visible:[outline-style:solid] focus-visible:outline-[var(--focus-ring)] focus-visible:outline-offset-1' + const titleDownloadsBadgeClass = 'pointer-events-none absolute -top-1 -right-1 inline-flex h-3.5 min-w-3.5 items-center justify-center rounded-[999px] bg-[var(--action,#60a5fa)] px-1 py-0 text-[9px] leading-none font-bold text-white tabular-nums [box-shadow:0_0_0_2px_var(--titlebar-bg-active,var(--titlebar-bg,var(--neutral-900)))] [.title-bar:not(.is-light)_&:not(.is-unseen,.is-error)]:text-background [&.is-unseen]:bg-[#22c55e] [&.is-error]:bg-[var(--danger)] [.title-downloads-tray.has-active_&]:animate-[title-downloads-pulse_1.6s_ease-in-out_infinite] [.title-downloads-tray.is-flashing_&]:[animation:title-downloads-flash_0.55s_cubic-bezier(0.2,0.9,0.3,1.4)_1,title-downloads-pulse_1.6s_ease-in-out_infinite_0.6s]' @@ -173,6 +178,8 @@ const showRefreshButton = computed( !isFirstUseLockdown.value ) +const showHomeButton = computed(() => !isInstallLess.value && !isFirstUseLockdown.value) + const zoomLevel = ref(0) const zoomPercent = computed(() => Math.round(Math.pow(1.2, zoomLevel.value) * 100)) const showZoomReset = computed( @@ -198,6 +205,11 @@ function handleRefreshInstance(): void { bridge?.clickRefreshInstance() } +function handleHome(): void { + hideTip() + bridge?.clickHome() +} + function handleResetZoom(): void { bridge?.resetZoom() } @@ -586,26 +598,14 @@ onUnmounted(() => { " > - @@ -741,6 +741,16 @@ onUnmounted(() => { {{ zoomPercent }}% + + From a0d1ec383d83c4cdd2473b7b38ce3ee24d3cfd25 Mon Sep 17 00:00:00 2001 From: Benjamin Lu Date: Mon, 16 Nov 2026 10:47:13 -0800 Subject: [PATCH 2/7] feat(windows): every build opens in its own window, never in place of another Picking another build from a build window's title-bar picker used to replace that window's build ("Switch", after a "Switch build?" prompt). Now it opens the build in its own window: main starts it from the Desktop window, whose card shows "Starting ComfyUI", and the build gets its own window when it is ready, the way a start from the Desktop window has worked since Comfy-Org/Comfy-Desktop#2074. The window you were in keeps its build. "Open in new window" used to open a fresh Desktop window just to run the launch. Since #2074 that window stayed behind once the build got its own window. It now reuses the Desktop window that asked, or the existing Desktop window (opening one only when none is open). With nothing left to switch in place, the picker and the build page lose their "Open in new window" caret items, which now did the same as the main button. The nav table's secondary decisions, the new-window intent, allowDuplicate, the switch confirms in the renderer and in main (main's had hard-coded English strings), the `confirmed` flag on pick, and the build page's open-in-new-window IPC go with them. The `switch` verb is renamed `start`, since it no longer switches anything. Labels: a stopped build seen from a build or Cloud window reads Start (was Switch or Open in new window), and another Cloud build reads Open Cloud. A running build still reads Switch and focuses its window. The routing decision moves into `routeBuildOpen` in the registry, so the rule "a build window never receives another build" is unit-tested. --- e2e/nav-matrix-cloud.test.ts | 48 ++-- e2e/nav-matrix-dashboard.test.ts | 24 +- e2e/nav-matrix-instance.test.ts | 27 +- e2e/support/navMatrixHelpers.ts | 14 ++ locales/en.json | 7 - locales/zh.json | 7 - src/main/host/registry.test.ts | 47 ++++ src/main/host/registry.ts | 24 +- src/main/index.ts | 143 ++++------- src/main/popups/titlePopup.test.ts | 40 --- src/main/popups/titlePopup.ts | 51 ++-- src/preload/api.ts | 2 - src/preload/comfyTitlePopupPreload.ts | 18 +- .../InstancePickerView.test.ts | 57 +++-- .../comfyTitlePopup/InstancePickerView.vue | 23 +- .../settings/ComfyUISettingsContent.test.ts | 18 +- .../settings/ComfyUISettingsContent.vue | 28 +-- .../composables/useInstanceActions.test.ts | 47 +--- .../src/composables/useInstanceActions.ts | 24 +- .../composables/useInstanceNavState.test.ts | 38 ++- .../src/composables/useInstanceNavState.ts | 7 +- .../src/panel/BuildDetailsView.test.ts | 24 +- src/renderer/src/panel/BuildDetailsView.vue | 5 - src/shared/navigation/navDecision.test.ts | 233 +++++------------- src/shared/navigation/navDecision.ts | 167 +++---------- src/types/ipc.ts | 1 - 26 files changed, 397 insertions(+), 727 deletions(-) diff --git a/e2e/nav-matrix-cloud.test.ts b/e2e/nav-matrix-cloud.test.ts index cb3abc57d..a1c802460 100644 --- a/e2e/nav-matrix-cloud.test.ts +++ b/e2e/nav-matrix-cloud.test.ts @@ -3,7 +3,7 @@ import { launchApp, type AppContext } from './launchApp' import { expectChooserVisible } from './support/chooserHelpers' import { closeTitlePopupIfOpen, isPopupVisible, titlePopupPage } from './support/cdpPages' import { clearRunningSessions, getIpcInvocations, resetIpcInvocations } from './support/devHooks' -import { liveWindowCount, openPicker } from './support/navMatrixHelpers' +import { desktopWindowCount, openPicker } from './support/navMatrixHelpers' import { byTestId, TID } from './support/testIds' let ctx: AppContext @@ -13,21 +13,26 @@ const CLOUD_NAME = 'Nav Cloud Target' test.describe.configure({ mode: 'serial' }) -async function newWindowCalls(): Promise<{ installationId?: string; focusedExisting?: boolean }[]> { - return (await getIpcInvocations(ctx.app, 'open-install-new-window')) as never +async function cloudRunActions(): Promise<{ installationId?: string }[]> { + return (await getIpcInvocations(ctx.app, 'run-action')) as never } -async function openCloudInNewWindow(): Promise { - await openPicker(ctx.app, ctx.panel, 'openInstallNewWindow') +async function openCloudFromPicker(): Promise { + await openPicker(ctx.app, ctx.panel, 'pickInstall') const popup = titlePopupPage(ctx.app) const cloudRow = byTestId(TID.pickerRow(CLOUD_ID)) await popup.waitForVisible(cloudRow) expect(await popup.click(cloudRow), 'Cloud instance selected').toBe(true) - await popup.waitForVisible(byTestId(TID.pickerNewWindow)) - expect(await popup.click(byTestId(TID.pickerNewWindow)), 'Window options clicked').toBe(true) - const openNewItem = byTestId(TID.pinBottomAction('nav:0')) - await popup.waitForVisible(openNewItem) - expect(await popup.click(openNewItem), 'Open in new window clicked').toBe(true) + await expect + .poll(() => popup.textOf(byTestId(TID.pickerPrimaryCta)), { + timeout: 5_000, + intervals: [100, 200] + }) + .toContain('Open Cloud') + expect(await popup.exists(byTestId(TID.pickerNewWindow)), 'no "Open in new window" caret').toBe( + false + ) + expect(await popup.click(byTestId(TID.pickerPrimaryCta)), 'Open Cloud clicked').toBe(true) await expect .poll(() => isPopupVisible(ctx.app, 'comfyTitlePopup.html'), { timeout: 5_000, @@ -52,24 +57,19 @@ test.afterAll(async () => { test.beforeEach(async () => { await closeTitlePopupIfOpen(ctx.app) - await resetIpcInvocations(ctx.app, 'open-install-new-window') + await resetIpcInvocations(ctx.app, 'run-action') await clearRunningSessions(ctx.app) }) -test('cloud target with no window: opens a new window @windows @macos @linux', async () => { - const before = await liveWindowCount(ctx.app) - await openCloudInNewWindow() +test('cloud target with no window: Open Cloud starts it from the Desktop window, no second Desktop window @windows @macos @linux', async () => { + const desktopWindowsBefore = await desktopWindowCount(ctx.app) + await openCloudFromPicker() await expect - .poll( - async () => - (await newWindowCalls()).some( - (c) => c.installationId === CLOUD_ID && c.focusedExisting === false - ), - { timeout: 5_000, intervals: [100, 250] } - ) + .poll(async () => (await cloudRunActions()).some((c) => c.installationId === CLOUD_ID), { + timeout: 10_000, + intervals: [200, 500] + }) .toBe(true) - await expect - .poll(() => liveWindowCount(ctx.app), { timeout: 5_000, intervals: [200, 400] }) - .toBe(before + 1) + expect(await desktopWindowCount(ctx.app), 'no second Desktop window').toBe(desktopWindowsBefore) }) diff --git a/e2e/nav-matrix-dashboard.test.ts b/e2e/nav-matrix-dashboard.test.ts index b3493df2d..91cf510d0 100644 --- a/e2e/nav-matrix-dashboard.test.ts +++ b/e2e/nav-matrix-dashboard.test.ts @@ -11,7 +11,12 @@ import { resetIpcInvocations, seedRunningSession } from './support/devHooks' -import { expectNoIpcInvocation, liveWindowCount, openPicker } from './support/navMatrixHelpers' +import { + desktopWindowCount, + expectNoIpcInvocation, + liveWindowCount, + openPicker +} from './support/navMatrixHelpers' import { byTestId, TID } from './support/testIds' let ctx: AppContext @@ -160,8 +165,8 @@ test('Dashboard → running instance: focus existing window @windows @macos @lin expect(await liveWindowCount(ctx.app)).toBe(before) }) -test('Dashboard → cloud via "Open in new window": spawns a new window @windows @macos @linux', async () => { - const before = await liveWindowCount(ctx.app) +test('Dashboard → cloud via "Open in new window": starts it from this Desktop window, no second Desktop window @windows @macos @linux', async () => { + const desktopWindowsBefore = await desktopWindowCount(ctx.app) await openPicker(ctx.app, ctx.panel, 'pickInstall') const popup = titlePopupPage(ctx.app) @@ -183,6 +188,15 @@ test('Dashboard → cloud via "Open in new window": spawns a new window @windows .toBe(true) await expect - .poll(() => liveWindowCount(ctx.app), { timeout: 5_000, intervals: [200, 400] }) - .toBe(before + 1) + .poll( + async () => { + const calls = (await getIpcInvocations(ctx.app, 'run-action')) as { + installationId?: string + }[] + return calls.some((c) => c.installationId === CLOUD_ID) + }, + { timeout: 10_000, intervals: [200, 500] } + ) + .toBe(true) + expect(await desktopWindowCount(ctx.app), 'no second Desktop window').toBe(desktopWindowsBefore) }) diff --git a/e2e/nav-matrix-instance.test.ts b/e2e/nav-matrix-instance.test.ts index 598fb9367..9df3e80ca 100644 --- a/e2e/nav-matrix-instance.test.ts +++ b/e2e/nav-matrix-instance.test.ts @@ -11,7 +11,12 @@ import { resetIpcInvocations, seedRunningSession } from './support/devHooks' -import { expectNoIpcInvocation, liveWindowCount, openPicker } from './support/navMatrixHelpers' +import { + desktopWindowCount, + expectNoIpcInvocation, + liveWindowCount, + openPicker +} from './support/navMatrixHelpers' let ctx: AppContext let installPathA: string @@ -72,8 +77,8 @@ test.beforeEach(async () => { await clearRunningSessions(ctx.app) }) -test('Instance B via "Open in new window": spawns a new window (no swap of the host) @windows @macos @linux', async () => { - const before = await liveWindowCount(ctx.app) +test('Instance B via "Open in new window": starts B from this Desktop window and opens no second Desktop window @windows @macos @linux', async () => { + const desktopWindowsBefore = await desktopWindowCount(ctx.app) await openPicker(ctx.app, ctx.panel, 'openInstallNewWindow') const popup = titlePopupPage(ctx.app) @@ -95,10 +100,20 @@ test('Instance B via "Open in new window": spawns a new window (no swap of the h .toBe(true) await expect - .poll(() => liveWindowCount(ctx.app), { timeout: 5_000, intervals: [200, 400] }) - .toBe(before + 1) + .poll( + async () => { + const calls = (await getIpcInvocations(ctx.app, 'run-action')) as { + installationId?: string + actionId?: string + }[] + return calls.some((c) => c.installationId === INSTALL_B_ID && c.actionId === 'launch') + }, + { timeout: 10_000, intervals: [200, 500] } + ) + .toBe(true) + expect(await desktopWindowCount(ctx.app), 'no second Desktop window').toBe(desktopWindowsBefore) await expectNoIpcInvocation(ctx.app, 'focus-comfy-window', () => true, { - message: 'unexpected focus-comfy-window when opening B in a new window' + message: 'unexpected focus-comfy-window when starting B' }) }) diff --git a/e2e/support/navMatrixHelpers.ts b/e2e/support/navMatrixHelpers.ts index 0a1afddd0..4d2226088 100644 --- a/e2e/support/navMatrixHelpers.ts +++ b/e2e/support/navMatrixHelpers.ts @@ -13,6 +13,20 @@ export async function liveWindowCount(app: ElectronApplication): Promise ) } +export async function desktopWindowCount(app: ElectronApplication): Promise { + return evalWithRetry(() => + app.evaluate( + ({ webContents }) => + webContents.getAllWebContents().filter((wc) => { + if (wc.isDestroyed()) return false + const url = wc.getURL() + if (!url.includes('panel.html')) return false + return new URL(url).searchParams.get('installationId') === '' + }).length + ) + ) +} + export async function openPicker( app: ElectronApplication, panel: WebContentsPage, diff --git a/locales/en.json b/locales/en.json index c457f752d..33d8b9069 100644 --- a/locales/en.json +++ b/locales/en.json @@ -1953,7 +1953,6 @@ "switch": "Switch", "openCloud": "Open Cloud", "openRemote": "Open Remote", - "openInNewWindow": "Open in new window", "windowOptions": "Window options", "moreWindowOptions": "Window options", "restartConfirmTitle": "Restart this build?", @@ -1963,12 +1962,6 @@ "confirmHeadsUp": "Heads up", "restartConfirmItem1": "Restarting will stop the running session.", "restartConfirmItem2": "Any unsaved work in the workflow will be lost.", - "switchConfirmTitle": "Switch build?", - "switchConfirmMessage": "Switch to {name}?", - "switchConfirmAction": "Switch", - "switchConfirmSecondary": "Open in new window", - "switchConfirmItem1": "Switch stops the current build and replaces it in this window.", - "switchConfirmItem2": "Open in new window keeps the current build running.", "more": "More", "settings": "Settings", "snapshots": "Snapshots", diff --git a/locales/zh.json b/locales/zh.json index 502ac2d03..ebe69c26f 100644 --- a/locales/zh.json +++ b/locales/zh.json @@ -1953,7 +1953,6 @@ "switch": "切换", "openCloud": "打开云端", "openRemote": "打开远程", - "openInNewWindow": "在新窗口中打开", "windowOptions": "窗口选项", "moreWindowOptions": "窗口选项", "restartConfirmTitle": "重启此构建?", @@ -1963,12 +1962,6 @@ "confirmHeadsUp": "请注意", "restartConfirmItem1": "重启将停止正在运行的会话。", "restartConfirmItem2": "工作流中任何未保存的工作都会丢失。", - "switchConfirmTitle": "切换构建?", - "switchConfirmMessage": "切换到 {name}?", - "switchConfirmAction": "切换", - "switchConfirmSecondary": "在新窗口中打开", - "switchConfirmItem1": "切换会停止当前构建并在此窗口中将其替换。", - "switchConfirmItem2": "在新窗口中打开会让当前构建继续运行。", "more": "更多", "settings": "设置", "snapshots": "快照", diff --git a/src/main/host/registry.test.ts b/src/main/host/registry.test.ts index a9f280553..81a875465 100644 --- a/src/main/host/registry.test.ts +++ b/src/main/host/registry.test.ts @@ -33,6 +33,7 @@ import { nextWindowKey, forceRevealHostWindow, openOrFocusHomeHostWindow, + routeBuildOpen, hasRunningSessionForEntry, raiseAllHostWindows, registerHostEntry, @@ -669,3 +670,49 @@ describe('openOrFocusHomeHostWindow', () => { expect(createChooser).toHaveBeenCalledTimes(1) }) }) + +describe('routeBuildOpen', () => { + it('focuses the window a build already has, whoever asks', () => { + const buildWindow = makeEntry({ installationId: 'inst-B' }) + const desktop = makeEntry({ installationId: null }) + registerHostEntry(buildWindow) + registerHostEntry(desktop) + + expect(routeBuildOpen('inst-B', desktop)).toEqual({ kind: 'focus', entry: buildWindow }) + expect(routeBuildOpen('inst-B', undefined)).toEqual({ kind: 'focus', entry: buildWindow }) + }) + + it('starts a build from the Desktop window that asked for it', () => { + const desktop = makeEntry({ installationId: null }) + registerHostEntry(desktop) + + expect(routeBuildOpen('inst-B', desktop)).toEqual({ kind: 'start-from', entry: desktop }) + }) + + it('never hands another build to a build window: it starts from the Desktop window instead', () => { + const buildA = makeEntry({ installationId: 'inst-A' }) + registerHostEntry(buildA) + + expect(routeBuildOpen('inst-B', buildA)).toEqual({ kind: 'start-from-home' }) + }) + + it('treats a Desktop window that is becoming a build window like a build window', () => { + const claimed = makeEntry({ installationId: null }) + registerHostEntry(claimed) + claimAttachHost('inst-A', claimed.windowKey) + + expect(routeBuildOpen('inst-B', claimed)).toEqual({ kind: 'start-from-home' }) + }) + + it('does nothing when a build window asks for itself', () => { + const buildA = makeEntry({ installationId: 'inst-A' }) + buildA.window.isDestroyed = () => false + comfyWindows.set(buildA.windowKey, buildA) + + expect(routeBuildOpen('inst-A', buildA)).toEqual({ kind: 'ignore' }) + }) + + it('starts from the Desktop window when the request names no window', () => { + expect(routeBuildOpen('inst-B', undefined)).toEqual({ kind: 'start-from-home' }) + }) +}) diff --git a/src/main/host/registry.ts b/src/main/host/registry.ts index e6166c3ca..456da05fd 100644 --- a/src/main/host/registry.ts +++ b/src/main/host/registry.ts @@ -335,9 +335,12 @@ function isHandingOffToBuild(entry: ComfyWindowEntry): boolean { return false } +export function isHomeHostEntry(entry: ComfyWindowEntry): boolean { + return !entry.window.isDestroyed() && isChooserHost(entry) && !isHandingOffToBuild(entry) +} + function findHomeHostWindow(): BrowserWindow | null { - const entry = findPreferredHostByVisibility((e) => isChooserHost(e) && !isHandingOffToBuild(e)) - return entry?.window ?? null + return findPreferredHostByVisibility(isHomeHostEntry)?.window ?? null } export function openOrFocusHomeHostWindow(): BrowserWindow { @@ -349,6 +352,23 @@ export function openOrFocusHomeHostWindow(): BrowserWindow { return requireChooserFactory()() } +export type BuildOpenRoute = + | { kind: 'focus'; entry: ComfyWindowEntry } + | { kind: 'start-from'; entry: ComfyWindowEntry } + | { kind: 'start-from-home' } + | { kind: 'ignore' } + +export function routeBuildOpen( + installationId: string, + requester: ComfyWindowEntry | undefined +): BuildOpenRoute { + const existing = getEntryByInstallationId(installationId) + if (existing && !existing.window.isDestroyed()) return { kind: 'focus', entry: existing } + if (requester?.installationId === installationId) return { kind: 'ignore' } + if (requester && isHomeHostEntry(requester)) return { kind: 'start-from', entry: requester } + return { kind: 'start-from-home' } +} + export function openOrFocusAnyHostWindow(): BrowserWindow { const installWin = findPreferredInstallHostWindow() if (installWin) { diff --git a/src/main/index.ts b/src/main/index.ts index 6bcffbd9e..f7111955a 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -36,12 +36,7 @@ import { pruneCrashDumps } from './lib/crashDumps' import { createStartupReentryGate } from './lib/startupReentryGate' import { registerTitleTooltipIpc } from './popups/titleTooltip' import { registerTitleCoachmarkIpc } from './popups/titleCoachmark' -import { - openSystemModal, - openSystemModalAsync, - openSystemModalChoiceAsync, - registerSystemModalIpc -} from './popups/systemModal' +import { openSystemModal, openSystemModalAsync, registerSystemModalIpc } from './popups/systemModal' import { registerTitlePopupIpc, triggerPickerSnapshotBroadcast, @@ -133,6 +128,7 @@ import { initUserTier } from './lib/userTier' import { readSmartAppControlState } from './lib/smartAppControl' import { + bringToFront, canRestartFromPicker, claimAttachHost, comfyWindows, @@ -149,10 +145,11 @@ import { openOrFocusChooserHostWindow, openOrFocusHomeHostWindow, raiseAllHostWindows, + routeBuildOpen, setHostFactories, shouldConfirmKillForEntry } from './host/registry' -import type { ComfyWindowEntry } from './host/registry' +import type { BuildOpenRoute, ComfyWindowEntry } from './host/registry' import { applyChooserHostThemeToAll, createHostWindow, @@ -1077,108 +1074,60 @@ if (app.isPackaged && !app.requestSingleInstanceLock()) { }) } - const openInstallInNewWindow = async ( + const openBuild = async ( installationId: string, - opts?: { allowDuplicate?: boolean } + requesterEntryId: number | undefined, + onRoute?: (route: BuildOpenRoute) => void ): Promise => { - const existing = getEntryByInstallationId(installationId) - const willFocusExisting = - !!existing && !existing.window.isDestroyed() && !opts?.allowDuplicate - recordIpcInvocation('open-install-new-window', { - installationId, - allowDuplicate: opts?.allowDuplicate === true, - focusedExisting: willFocusExisting - }) - if (willFocusExisting) { - existing.window.show() - existing.window.focus() - return - } - try { - const inst = await getInstallation(installationId) - if (!inst) { - console.error('openInstallInNewWindow: unknown installation, not spawning', { - installationId - }) + const requester = + requesterEntryId === undefined ? undefined : comfyWindows.get(requesterEntryId) + const route = routeBuildOpen(installationId, requester) + onRoute?.(route) + switch (route.kind) { + case 'ignore': return - } - const target = findEntryByHostWindow(openChooserHostWindow()) - if (!target) { - console.error('openInstallInNewWindow: spawned chooser host not in registry', { - installationId - }) + case 'focus': + bringToFront(route.entry.window) + return + case 'start-from': + deliverPickToEntry(route.entry, installationId) + return + case 'start-from-home': { + const inst = await getInstallation(installationId) + if (!inst) { + console.error('openBuild: unknown installation, not starting it', { installationId }) + return + } + const homeEntry = findEntryByHostWindow(openOrFocusHomeHostWindow()) + if (!homeEntry) { + console.error('openBuild: Desktop window not in registry', { installationId }) + return + } + deliverPickToEntry(homeEntry, installationId) return } - mainTelemetry.emit('comfy.desktop.instance.opened_new_window', { - to_installation_id: installationId, - method: 'picker' - }) - deliverPickToEntry(target, installationId) - } catch (err) { - console.error('openInstallInNewWindow failed:', err) } } - const pickInstallFromPicker = async ( + const openInstallInNewWindow = ( installationId: string, - parentEntryId: number, - opts?: { confirmed?: boolean } - ): Promise => { - const existing = getEntryByInstallationId(installationId) - if (existing && !existing.window.isDestroyed()) { - existing.window.show() - existing.window.focus() - return - } - const parentEntry = comfyWindows.get(parentEntryId) - if (!parentEntry || parentEntry.window.isDestroyed()) return - - if (parentEntry.installationId === installationId) return - - if (parentEntry.installationId != null) { - if (!opts?.confirmed && shouldConfirmKillForEntry(parentEntry)) { - let targetName = installationId - try { - const target = await getInstallation(installationId) - if (target?.name) targetName = target.name - } catch {} - const choice = await openSystemModalChoiceAsync({ - parent: parentEntry.window, - spec: { - title: 'Switch instance?', - message: `Switch to ${targetName}?`, - details: [ - { - label: 'Heads up', - items: [ - 'Switch stops the current instance and replaces it in this window.', - 'Open in new window keeps the current instance running.' - ] - } - ], - confirmLabel: 'Switch', - secondaryLabel: 'Open in new window', - cancelLabel: 'Cancel', - confirmStyle: 'primary', - theme: parentEntry.lastTheme - } + requesterEntryId?: number + ): Promise => + openBuild(installationId, requesterEntryId, (route) => { + recordIpcInvocation('open-install-new-window', { + installationId, + focusedExisting: route.kind === 'focus' + }) + if (route.kind === 'start-from' || route.kind === 'start-from-home') { + mainTelemetry.emit('comfy.desktop.instance.opened_new_window', { + to_installation_id: installationId, + method: 'picker' }) - if (choice === 'cancel') return - if (choice === 'secondary') { - openInstallInNewWindow(installationId) - return - } } - mainTelemetry.emit('comfy.desktop.instance.switched', { - from_installation_id: parentEntry.installationId, - to_installation_id: installationId, - method: 'picker' - }) - parentEntry.detachInstall() - } + }).catch((err) => console.error('openInstallInNewWindow failed:', err)) - deliverPickToEntry(parentEntry, installationId) - } + const pickInstallFromPicker = (installationId: string, parentEntryId: number): Promise => + openBuild(installationId, parentEntryId) registerTitlePopupIpc({ openChooserHostWindow, diff --git a/src/main/popups/titlePopup.test.ts b/src/main/popups/titlePopup.test.ts index fdac8828a..f00f698a2 100644 --- a/src/main/popups/titlePopup.test.ts +++ b/src/main/popups/titlePopup.test.ts @@ -907,43 +907,3 @@ describe('buildGlobalSettingsSnapshot telemetry grant', () => { expect(snapshotWithConsent(false).telemetryGranted).toBe(false) }) }) - -describe('build page open-in-new-window IPC', () => { - type IpcListener = (event: Electron.IpcMainEvent, installationId: unknown) => void - const panelContents = {} - const openInstallInNewWindow = vi.fn(async () => {}) - let open: IpcListener - - beforeAll(async () => { - const { ipcMain } = await import('electron') - vi.mocked(ipcMain.on).mockClear() - registerTitlePopupIpc({ openInstallInNewWindow } as unknown as TitlePopupHostBindings) - const call = vi - .mocked(ipcMain.on) - .mock.calls.find(([channel]) => channel === 'comfy-window:open-install-new-window') - if (!call) throw new Error('IPC listener not registered') - open = call[1] as IpcListener - }) - - beforeEach(() => { - openInstallInNewWindow.mockClear() - comfyWindows.set(nextWindowKey(), { - panelView: { webContents: panelContents } - } as unknown as ComfyWindowEntry) - }) - - it('opens the build for a window panel', () => { - open({ sender: panelContents } as Electron.IpcMainEvent, 'inst-a') - - expect(openInstallInNewWindow).toHaveBeenCalledExactlyOnceWith('inst-a') - }) - - it.each([ - ['a sender that is not a panel', {}, 'inst-a'], - ['a missing installation id', panelContents, undefined] - ])('ignores %s', (_label, sender, installationId) => { - open({ sender } as Electron.IpcMainEvent, installationId) - - expect(openInstallInNewWindow).not.toHaveBeenCalled() - }) -}) diff --git a/src/main/popups/titlePopup.ts b/src/main/popups/titlePopup.ts index e8e0b87bb..2a5d834c7 100644 --- a/src/main/popups/titlePopup.ts +++ b/src/main/popups/titlePopup.ts @@ -48,7 +48,6 @@ import { getEntryByInstallationId, hostInstallEvents, isChooserHost, - isPanelSender, unhostedLaunches } from '../host/registry' import type { ComfyPanelKey, ComfyWindowEntry } from '../host/registry' @@ -981,14 +980,10 @@ export interface TitlePopupHostBindings { getRunningInstallationIds: () => string[] getRunningSessionStartedAt?: () => Record getLaunchingInstallationIds: () => string[] - pickInstallFromPicker: ( - installationId: string, - parentEntryId: number, - opts?: { confirmed?: boolean } - ) => Promise | void + pickInstallFromPicker: (installationId: string, parentEntryId: number) => Promise | void openInstallInNewWindow: ( installationId: string, - opts?: { allowDuplicate?: boolean } + requesterEntryId?: number ) => Promise | void restartInstallFromPicker: ( installationId: string, @@ -1762,45 +1757,31 @@ export function registerTitlePopupIpc(bindings: TitlePopupHostBindings): void { } ) - ipcMain.on( - 'comfy-titlepopup:pick-install', - (event, payload: { installationId?: unknown; confirmed?: unknown }) => { - const entry = titlePopupsByWebContents.get(event.sender.id) - if (!entry || entry.kind !== POPUP_KIND.instancePicker) return - const installationId = payload?.installationId - if (typeof installationId !== 'string' || installationId.length === 0) return - const confirmed = payload?.confirmed === true - hideTitlePopup(entry, { releaseFocusToParent: false }) - Promise.resolve( - bindings.pickInstallFromPicker(installationId, entry.parentEntryId, { confirmed }) - ).catch((err) => console.error('pickInstallFromPicker failed:', err)) - } - ) + ipcMain.on('comfy-titlepopup:pick-install', (event, payload: { installationId?: unknown }) => { + const entry = titlePopupsByWebContents.get(event.sender.id) + if (!entry || entry.kind !== POPUP_KIND.instancePicker) return + const installationId = payload?.installationId + if (typeof installationId !== 'string' || installationId.length === 0) return + hideTitlePopup(entry, { releaseFocusToParent: false }) + Promise.resolve(bindings.pickInstallFromPicker(installationId, entry.parentEntryId)).catch( + (err) => console.error('pickInstallFromPicker failed:', err) + ) + }) ipcMain.on( 'comfy-titlepopup:open-install-new-window', - (event, payload: { installationId?: unknown; allowDuplicate?: unknown }) => { + (event, payload: { installationId?: unknown }) => { const entry = titlePopupsByWebContents.get(event.sender.id) if (!entry || entry.kind !== POPUP_KIND.instancePicker) return const installationId = payload?.installationId if (typeof installationId !== 'string' || installationId.length === 0) return hideTitlePopup(entry, { releaseFocusToParent: false }) - Promise.resolve( - bindings.openInstallInNewWindow(installationId, { - allowDuplicate: payload?.allowDuplicate === true - }) - ).catch((err) => console.error('openInstallInNewWindow failed:', err)) + Promise.resolve(bindings.openInstallInNewWindow(installationId, entry.parentEntryId)).catch( + (err) => console.error('openInstallInNewWindow failed:', err) + ) } ) - ipcMain.on('comfy-window:open-install-new-window', (event, installationId: unknown) => { - if (!isPanelSender(event.sender)) return - if (typeof installationId !== 'string' || installationId.length === 0) return - Promise.resolve(bindings.openInstallInNewWindow(installationId)).catch((err) => - console.error('openInstallInNewWindow failed:', err) - ) - }) - ipcMain.on( 'comfy-titlepopup:restart-install', (event, payload: { installationId?: unknown; confirmed?: unknown }) => { diff --git a/src/preload/api.ts b/src/preload/api.ts index 8c2e2541a..7e726b16a 100644 --- a/src/preload/api.ts +++ b/src/preload/api.ts @@ -84,8 +84,6 @@ export function buildElectronApi(): ElectronApi { terminalResize: (installationId, cols, rows) => ipcRenderer.invoke('terminal-resize', installationId, cols, rows), terminalRestart: (installationId) => ipcRenderer.invoke('terminal-restart', installationId), - openInstallInNewWindow: (installationId) => - ipcRenderer.send('comfy-window:open-install-new-window', installationId), openInstallWindow: (installationId) => ipcRenderer.invoke('open-install-window', installationId), closeComfyWindow: (installationId, opts) => diff --git a/src/preload/comfyTitlePopupPreload.ts b/src/preload/comfyTitlePopupPreload.ts index 511bd6e5f..710efd644 100644 --- a/src/preload/comfyTitlePopupPreload.ts +++ b/src/preload/comfyTitlePopupPreload.ts @@ -157,8 +157,8 @@ export interface ComfyTitlePopupBridge { openDownloadsModal(): void requestSize(height: number): void onInstancePickerSnapshot(cb: (snapshot: PopupInstancePickerSnapshot) => void): () => void - pickInstall(installationId: string, opts?: { confirmed?: boolean }): void - openInstallNewWindow(installationId: string, opts?: { allowDuplicate?: boolean }): void + pickInstall(installationId: string): void + openInstallNewWindow(installationId: string): void openNewInstall(): void restartInstall(installationId: string, opts?: { confirmed?: boolean }): void getDownloadThumbnail(savePath: string): Promise @@ -452,17 +452,11 @@ const bridge: ComfyTitlePopupBridge = { ipcRenderer.on('comfy-titlepopup:installs-changed', handler) return () => ipcRenderer.removeListener('comfy-titlepopup:installs-changed', handler) }, - pickInstall: (installationId, opts) => { - ipcRenderer.send('comfy-titlepopup:pick-install', { - installationId, - confirmed: opts?.confirmed === true - }) + pickInstall: (installationId) => { + ipcRenderer.send('comfy-titlepopup:pick-install', { installationId }) }, - openInstallNewWindow: (installationId, opts) => { - ipcRenderer.send('comfy-titlepopup:open-install-new-window', { - installationId, - allowDuplicate: opts?.allowDuplicate === true - }) + openInstallNewWindow: (installationId) => { + ipcRenderer.send('comfy-titlepopup:open-install-new-window', { installationId }) }, openNewInstall: () => { ipcRenderer.send('comfy-titlepopup:open-new-install') diff --git a/src/renderer/src/comfyTitlePopup/InstancePickerView.test.ts b/src/renderer/src/comfyTitlePopup/InstancePickerView.test.ts index 3c973a974..6a250724e 100644 --- a/src/renderer/src/comfyTitlePopup/InstancePickerView.test.ts +++ b/src/renderer/src/comfyTitlePopup/InstancePickerView.test.ts @@ -6,27 +6,9 @@ import { useSessionStore } from '../stores/sessionStore' import { NAV_LABEL, type NavDecision } from '../../../shared/navigation/navDecision' import InstancePickerView from './InstancePickerView.vue' -const SWITCH_DECISION: NavDecision = { - window: 'same', - verb: 'switch', - primaryLabel: NAV_LABEL.start, - secondary: [], - telemetry: 'instance.switched' -} -const RESTART_DECISION: NavDecision = { - window: 'same', - verb: 'restart', - primaryLabel: NAV_LABEL.restart, - secondary: [], - telemetry: null -} -const FOCUS_DECISION: NavDecision = { - window: 'same', - verb: 'focus', - primaryLabel: NAV_LABEL.switch, - secondary: [], - telemetry: null -} +const START_DECISION: NavDecision = { verb: 'start', primaryLabel: NAV_LABEL.start } +const RESTART_DECISION: NavDecision = { verb: 'restart', primaryLabel: NAV_LABEL.restart } +const FOCUS_DECISION: NavDecision = { verb: 'focus', primaryLabel: NAV_LABEL.switch } import type { SnapshotListData } from '../types/ipc' vi.mock('../views/comfyUISettings/ConsoleTerminalPane.vue', () => ({ @@ -83,10 +65,13 @@ interface MockSnapshot { pickerSelectionEpoch?: number selectedSettings?: unknown[] | null selectedSnapshots?: unknown | null + currentView?: 'dashboard' | 'instance' | 'cloud' + currentCategory?: string | null } interface BridgeState { picks: string[] + newWindows: string[] restarts: { id: string; opts?: { confirmed?: boolean } }[] backgroundOps: { installationId: string; actionId: string }[] newInstallCount: number @@ -98,6 +83,7 @@ interface BridgeState { function installMockBridge(): BridgeState { const state: BridgeState = { picks: [], + newWindows: [], restarts: [], backgroundOps: [], newInstallCount: 0, @@ -109,6 +95,9 @@ function installMockBridge(): BridgeState { pickInstall: (id: string) => { state.picks.push(id) }, + openInstallNewWindow: (id: string) => { + state.newWindows.push(id) + }, restartInstall: (id: string, opts?: { confirmed?: boolean }) => { state.restarts.push({ id, opts }) }, @@ -513,7 +502,7 @@ describe('comfyTitlePopup/InstancePickerView', () => { }) const settings = wrapper.findComponent(ComfyUISettingsContent) expect(settings.exists()).toBe(true) - settings.vm.$emit('primary-action', SWITCH_DECISION) + settings.vm.$emit('primary-action', START_DECISION) await flushPromises() expect(bridge.picks).toEqual(['a']) expect(bridge.restarts).toEqual([]) @@ -566,6 +555,30 @@ describe('comfyTitlePopup/InstancePickerView', () => { expect(bridge.picks).toEqual([]) }) + it('starts another stopped build from a build window in its own window, with no Switch prompt', async () => { + const { useDialogs } = await import('../composables/useDialogs') + const wrapper = await mountPicker({ + installs: [ + makeInstall({ id: 'a', name: 'Alpha', sourceCategory: 'local' }), + makeInstall({ id: 'b', name: 'Bravo', sourceCategory: 'local' }) + ], + activeInstallationId: 'a', + selectedInstallationId: 'b', + runningInstallationIds: ['a'], + currentView: 'instance', + currentCategory: 'local' + }) + await flushPromises() + const primary = wrapper.get('[data-testid="picker-primary-cta"]') + expect(primary.text()).toBe('Start') + await primary.trigger('click') + await flushPromises() + expect(useDialogs().state.open).toBe(false) + expect(bridge.newWindows).toEqual(['b']) + expect(bridge.picks).toEqual([]) + expect(bridge.restarts).toEqual([]) + }) + it('keeps Switch from the dashboard for a build another window is starting', async () => { const wrapper = await mountPicker({ installs: [makeInstall({ id: 'a', name: 'Alpha', sourceCategory: 'local' })], diff --git a/src/renderer/src/comfyTitlePopup/InstancePickerView.vue b/src/renderer/src/comfyTitlePopup/InstancePickerView.vue index 7e16c5ff3..841cf39ad 100644 --- a/src/renderer/src/comfyTitlePopup/InstancePickerView.vue +++ b/src/renderer/src/comfyTitlePopup/InstancePickerView.vue @@ -130,7 +130,7 @@ interface PickerBridge { activate?: (id: string) => void close?: () => void pickInstall: (installationId: string) => void - openInstallNewWindow: (installationId: string, opts?: { allowDuplicate?: boolean }) => void + openInstallNewWindow: (installationId: string) => void restartInstall: (installationId: string, opts?: { confirmed?: boolean }) => void setPickerSelectedInstall: (installationId: string | null) => void pickerUpdateField: ( @@ -433,26 +433,6 @@ const instanceActions = useInstanceActions({ ] }) return result === 'primary' - }, - confirmSwitch: async (inst) => { - const hostIsLocalInstall = - props.snapshot.currentView === 'instance' && props.snapshot.currentCategory === 'local' - if (!hostIsLocalInstall) return 'switch' - const result = await dialogs.confirm({ - title: t('instancePicker.switchConfirmTitle'), - message: t('instancePicker.switchConfirmMessage', { name: inst.name }), - confirmLabel: t('instancePicker.switchConfirmAction'), - secondaryLabel: t('instancePicker.switchConfirmSecondary'), - cancelLabel: t('common.cancel'), - showCancel: true, - messageDetails: [ - { - label: t('instancePicker.confirmHeadsUp'), - items: [t('instancePicker.switchConfirmItem1'), t('instancePicker.switchConfirmItem2')] - } - ] - }) - return result === 'primary' ? 'switch' : result === 'secondary' ? 'new-window' : 'cancel' } }) @@ -600,7 +580,6 @@ async function handleExpandedNav(decision: NavDecision): Promise { @request-close="handleSettingsNavigateList" @request-dismiss="handleClose" @primary-action="handleExpandedNav" - @open-new-window="handleExpandedNav" @op-cancel="handleInlineProgressCancel" @op-retry="handleInlineProgressRetry" @op-dismiss="handleInlineProgressDismiss" diff --git a/src/renderer/src/components/settings/ComfyUISettingsContent.test.ts b/src/renderer/src/components/settings/ComfyUISettingsContent.test.ts index 61d325cec..0726dd78c 100644 --- a/src/renderer/src/components/settings/ComfyUISettingsContent.test.ts +++ b/src/renderer/src/components/settings/ComfyUISettingsContent.test.ts @@ -540,10 +540,10 @@ describe('ComfyUISettingsContent', () => { function emittedDecision(wrapper: VueWrapper) { const calls = wrapper.emitted('primary-action') as unknown[][] | undefined - return calls?.[0]?.[0] as { window: string; verb: string } | undefined + return calls?.[0]?.[0] as { verb: string } | undefined } - it('labels "Start" and emits a same-window switch decision when not running', async () => { + it('labels "Start" and emits a start decision when not running', async () => { const w = await mountContent({ currentView: 'dashboard', currentCategory: null, @@ -551,7 +551,7 @@ describe('ComfyUISettingsContent', () => { }) expect(w.find('.settings-v2-relaunch').text()).toBe('Start') await w.find('.settings-v2-relaunch').trigger('click') - expect(emittedDecision(w)).toMatchObject({ window: 'same', verb: 'switch' }) + expect(emittedDecision(w)).toMatchObject({ verb: 'start' }) }) it('labels "Restart" and emits a restart decision when running in THIS window', async () => { @@ -563,7 +563,7 @@ describe('ComfyUISettingsContent', () => { }) expect(w.find('.settings-v2-relaunch').text()).toBe('Restart') await w.find('.settings-v2-relaunch').trigger('click') - expect(emittedDecision(w)).toMatchObject({ window: 'same', verb: 'restart' }) + expect(emittedDecision(w)).toMatchObject({ verb: 'restart' }) }) it('labels "Switch" and emits a focus decision when running in ANOTHER window', async () => { @@ -602,7 +602,7 @@ describe('ComfyUISettingsContent', () => { }) expect(w.find('.settings-v2-relaunch').text()).toBe('Restart to apply changes') await w.find('.settings-v2-relaunch').trigger('click') - expect(emittedDecision(w)).toMatchObject({ window: 'same', verb: 'restart' }) + expect(emittedDecision(w)).toMatchObject({ verb: 'restart' }) } finally { useComfyUISettingsState.pendingRestartFieldIds.value = new Set() } @@ -622,7 +622,7 @@ describe('ComfyUISettingsContent', () => { const menu = wrapper .findAllComponents({ name: 'MoreMenu' }) .map((m) => m.props('actions') as { id: string }[] | undefined) - .find((acts) => acts?.some((a) => a.id === 'stop' || a.id.startsWith('nav:'))) + .find((acts) => acts?.some((a) => a.id === 'stop')) return menu } @@ -653,7 +653,7 @@ describe('ComfyUISettingsContent', () => { expect(w.find('.settings-v2-cta-caret').exists()).toBe(false) }) - it('stopped cloud target (dashboard host) → caret still offers "Open in new window"', async () => { + it('stopped cloud target (dashboard host) → Open Cloud with no "Open in new window" caret', async () => { useComfyUISettingsState.pinBottomActions.value = [] const w = await mountContent({ currentView: 'dashboard', @@ -661,8 +661,8 @@ describe('ComfyUISettingsContent', () => { activeInstallationId: null, installation: { ...SAMPLE_INSTALL, sourceCategory: 'cloud' } }) - const actions = caretActions(w) - expect(actions?.some((a) => a.id.startsWith('nav:'))).toBe(true) + expect(w.find('.settings-v2-relaunch').text()).toBe('Open Cloud') + expect(w.find('.settings-v2-cta-caret').exists()).toBe(false) }) }) diff --git a/src/renderer/src/components/settings/ComfyUISettingsContent.vue b/src/renderer/src/components/settings/ComfyUISettingsContent.vue index ee2f26d85..f4c34b2a3 100644 --- a/src/renderer/src/components/settings/ComfyUISettingsContent.vue +++ b/src/renderer/src/components/settings/ComfyUISettingsContent.vue @@ -21,7 +21,6 @@ import { Play, RotateCcw, LayoutDashboard, - SquareArrowOutUpRight, Copy, CopyPlus, FolderOpen, @@ -117,7 +116,6 @@ const emit = defineEmits<{ 'request-close': [] 'request-dismiss': [] 'primary-action': [decision: NavDecision] - 'open-new-window': [decision: NavDecision] 'op-cancel': [] 'op-retry': [] 'op-dismiss': [] @@ -478,7 +476,7 @@ function handleSnapshotsRefresh(): void { const isRunningInThisWindow = installCta.runningInThisWindow -const primaryDecision = computed(() => decideNavigation(navState.navInput('primary'))) +const primaryDecision = computed(() => decideNavigation(navState.navInput())) const primaryRestartsTarget = computed( () => isRunningInThisWindow.value || primaryDecision.value.verb === 'restart' @@ -513,8 +511,6 @@ function navIcon(labelKey: string): Component { return RotateCcw case 'instancePicker.switch': return Repeat2 - case 'instancePicker.openInNewWindow': - return SquareArrowOutUpRight case 'instancePicker.open': return Play default: @@ -536,20 +532,10 @@ const primaryActionIcon = computed(() => const stopAction = computed(() => pinBottomActions.value.find((a) => a.id === 'stop') ) -const NAV_ITEM_PREFIX = 'nav:' const caretActions = computed(() => { - if (primaryDecision.value.verb === 'focus') { - return stopAction.value ? [{ ...stopAction.value, icon: actionIcon('stop') }] : [] - } - const navItems: MenuAction[] = primaryDecision.value.secondary.map((alt, i) => ({ - id: `${NAV_ITEM_PREFIX}${i}`, - label: resolveNavLabel(alt.primaryLabel), - icon: navIconFor(alt.primaryLabel) - })) - if (primaryDecision.value.verb === 'restart' && stopAction.value) { - navItems.push({ ...stopAction.value, icon: actionIcon('stop') }) - } - return navItems + const verb = primaryDecision.value.verb + if (!stopAction.value || (verb !== 'focus' && verb !== 'restart')) return [] + return [{ ...stopAction.value, icon: actionIcon('stop') }] }) function actionIcon(id: string): Component { @@ -614,12 +600,6 @@ function closeCaretMenu(): void { } function handleCaretPick(action: ActionDef): void { if (!installation.value) return - if (action.id.startsWith(NAV_ITEM_PREFIX)) { - const index = Number(action.id.slice(NAV_ITEM_PREFIX.length)) - const picked = primaryDecision.value.secondary[index] - if (picked) emit('open-new-window', picked) - return - } void runAction(action) } diff --git a/src/renderer/src/composables/useInstanceActions.test.ts b/src/renderer/src/composables/useInstanceActions.test.ts index ad07a6745..6ab2300ef 100644 --- a/src/renderer/src/composables/useInstanceActions.test.ts +++ b/src/renderer/src/composables/useInstanceActions.test.ts @@ -18,11 +18,8 @@ function installation(over: Partial = {}): Installation { function decision(over: Partial): NavDecision { return { - window: 'same', - verb: 'switch', - primaryLabel: 'instancePicker.switch', - secondary: [], - telemetry: null, + verb: 'start', + primaryLabel: 'instancePicker.open', ...over } } @@ -34,33 +31,17 @@ function makeDeps( return { bridge, confirmLocalKill: vi.fn().mockResolvedValue(true), - confirmSwitch: vi.fn().mockResolvedValue('switch'), ...over } } describe('useInstanceActions.dispatch', () => { - it('switch → confirm in-drawer then pickInstall(confirmed:true)', async () => { + it('start → pickInstall, with no confirm because nothing is replaced', async () => { const bridge = makeBridge() const deps = makeDeps(bridge) - await useInstanceActions(deps).dispatch(decision({ verb: 'switch' }), installation()) - expect(deps.confirmSwitch).toHaveBeenCalled() - expect(bridge.pickInstall).toHaveBeenCalledWith('a', { confirmed: true }) - }) - - it('switch → "new-window" choice routes to openInstallNewWindow, not pickInstall', async () => { - const bridge = makeBridge() - const deps = makeDeps(bridge, { confirmSwitch: vi.fn().mockResolvedValue('new-window') }) - await useInstanceActions(deps).dispatch(decision({ verb: 'switch' }), installation()) - expect(bridge.openInstallNewWindow).toHaveBeenCalledWith('a') - expect(bridge.pickInstall).not.toHaveBeenCalled() - }) - - it('switch → cancel fires nothing', async () => { - const bridge = makeBridge() - const deps = makeDeps(bridge, { confirmSwitch: vi.fn().mockResolvedValue('cancel') }) - await useInstanceActions(deps).dispatch(decision({ verb: 'switch' }), installation()) - expect(bridge.pickInstall).not.toHaveBeenCalled() + await useInstanceActions(deps).dispatch(decision({ verb: 'start' }), installation()) + expect(bridge.pickInstall).toHaveBeenCalledExactlyOnceWith('a') + expect(deps.confirmLocalKill).not.toHaveBeenCalled() expect(bridge.openInstallNewWindow).not.toHaveBeenCalled() }) @@ -82,19 +63,11 @@ describe('useInstanceActions.dispatch', () => { it('routes open-new → openInstallNewWindow', async () => { const bridge = makeBridge() await useInstanceActions(makeDeps(bridge)).dispatch( - decision({ verb: 'open-new', window: 'new' }), + decision({ verb: 'open-new' }), installation() ) - expect(bridge.openInstallNewWindow).toHaveBeenCalledWith('a', expect.objectContaining({})) - }) - - it('passes allowDuplicate through to openInstallNewWindow when a decision sets it', async () => { - const bridge = makeBridge() - await useInstanceActions(makeDeps(bridge)).dispatch( - decision({ verb: 'open-new', window: 'new', allowDuplicate: true }), - installation({ sourceCategory: 'cloud' }) - ) - expect(bridge.openInstallNewWindow).toHaveBeenCalledWith('a', { allowDuplicate: true }) + expect(bridge.openInstallNewWindow).toHaveBeenCalledExactlyOnceWith('a') + expect(bridge.pickInstall).not.toHaveBeenCalled() }) it('routes focus → pickInstall (main short-circuits to focus when already up)', async () => { @@ -123,7 +96,7 @@ describe('useInstanceActions.dispatch', () => { it('no-ops when the bridge is undefined', async () => { const deps = { ...makeDeps(makeBridge()), bridge: undefined } await expect( - useInstanceActions(deps).dispatch(decision({ verb: 'switch' }), installation()) + useInstanceActions(deps).dispatch(decision({ verb: 'start' }), installation()) ).resolves.toBeUndefined() }) diff --git a/src/renderer/src/composables/useInstanceActions.ts b/src/renderer/src/composables/useInstanceActions.ts index 424559add..76c736d18 100644 --- a/src/renderer/src/composables/useInstanceActions.ts +++ b/src/renderer/src/composables/useInstanceActions.ts @@ -1,19 +1,16 @@ import type { NavDecision } from '../../../shared/navigation/navDecision' import type { Installation } from '../types/ipc' -export type SwitchChoice = 'switch' | 'new-window' | 'cancel' - export interface InstanceActionsBridge { - pickInstall: (installationId: string, opts?: { confirmed?: boolean }) => void + pickInstall: (installationId: string) => void restartInstall: (installationId: string, opts?: { confirmed?: boolean }) => void - openInstallNewWindow?: (installationId: string, opts?: { allowDuplicate?: boolean }) => void + openInstallNewWindow?: (installationId: string) => void openNewInstall?: () => void } export interface InstanceActionsDeps { bridge: InstanceActionsBridge | undefined confirmLocalKill: (inst: Installation) => Promise - confirmSwitch: (inst: Installation) => Promise } export interface InstanceActions { @@ -32,22 +29,13 @@ export function useInstanceActions(deps: InstanceActionsDeps): InstanceActions { bridge.restartInstall(target.id, { confirmed: true }) return } - case 'switch': { - const choice = await deps.confirmSwitch(target) - if (choice === 'cancel') return - if (choice === 'new-window') { - bridge.openInstallNewWindow?.(target.id) - return - } - bridge.pickInstall(target.id, { confirmed: true }) + case 'start': + case 'focus': { + bridge.pickInstall(target.id) return } case 'open-new': { - bridge.openInstallNewWindow?.(target.id, { allowDuplicate: decision.allowDuplicate }) - return - } - case 'focus': { - bridge.pickInstall(target.id) + bridge.openInstallNewWindow?.(target.id) return } case 'install-wizard': { diff --git a/src/renderer/src/composables/useInstanceNavState.test.ts b/src/renderer/src/composables/useInstanceNavState.test.ts index 1962acac4..dd18cbbaf 100644 --- a/src/renderer/src/composables/useInstanceNavState.test.ts +++ b/src/renderer/src/composables/useInstanceNavState.test.ts @@ -152,34 +152,30 @@ describe('useInstanceNavState → decideNavigation (end to end)', () => { activeInstallationId: null, startingWithoutWindow: true }) - const decision = decideNavigation(navState.navInput('primary')) + const decision = decideNavigation(navState.navInput()) expect(decision.verb).toBe('restart') expect(decision.primaryLabel).toBe(NAV_LABEL.restart) }) - it('instance host picking a stopped local instance → switch in place', () => { + it('instance host picking a stopped local instance → Start in its own window', () => { const navState = useInstanceNavState(ref(installation('B', 'local')), { currentView: 'instance' as ViewKind, currentCategory: 'local' as Category, activeInstallationId: 'A' }) - const decision = decideNavigation(navState.navInput('primary')) - expect(decision).toMatchObject({ window: 'same', verb: 'switch' }) + const decision = decideNavigation(navState.navInput()) + expect(decision).toEqual({ verb: 'open-new', primaryLabel: NAV_LABEL.start }) }) - it('dashboard host picking a stopped cloud install → Open Cloud + new-window caret', () => { + it('dashboard host picking a stopped cloud install → Open Cloud', () => { const navState = useInstanceNavState(ref(installation('cloud', 'cloud')), { currentView: 'dashboard' as ViewKind, currentCategory: null, activeInstallationId: null }) - const primaryDecision = decideNavigation(navState.navInput('primary')) - expect(primaryDecision).toMatchObject({ verb: 'switch', primaryLabel: NAV_LABEL.openCloud }) - const caretDecision = decideNavigation(navState.navInput('new-window')) - expect(caretDecision).toMatchObject({ - window: 'new', - verb: 'open-new', - primaryLabel: NAV_LABEL.openInNewWindow + expect(decideNavigation(navState.navInput())).toEqual({ + verb: 'start', + primaryLabel: NAV_LABEL.openCloud }) }) @@ -189,8 +185,8 @@ describe('useInstanceNavState → decideNavigation (end to end)', () => { currentCategory: 'cloud' as Category, activeInstallationId: 'cloud' }) - const decision = decideNavigation(navState.navInput('primary')) - expect(decision).toMatchObject({ window: 'new', verb: 'open-new' }) + const decision = decideNavigation(navState.navInput()) + expect(decision).toEqual({ verb: 'open-new', primaryLabel: NAV_LABEL.start }) }) it('cloud host picking a stopped REMOTE connection → opens in a new window (not a dead no-op)', () => { @@ -199,12 +195,8 @@ describe('useInstanceNavState → decideNavigation (end to end)', () => { currentCategory: 'cloud' as Category, activeInstallationId: 'cloud' }) - const decision = decideNavigation(navState.navInput('primary')) - expect(decision).toMatchObject({ - window: 'new', - verb: 'open-new', - primaryLabel: NAV_LABEL.openInNewWindow - }) + const decision = decideNavigation(navState.navInput()) + expect(decision).toEqual({ verb: 'open-new', primaryLabel: NAV_LABEL.openCloud }) }) it('instance host → stopped REMOTE routes identically to stopped Cloud (no in-place 3-way)', () => { @@ -214,12 +206,12 @@ describe('useInstanceNavState → decideNavigation (end to end)', () => { activeInstallationId: 'A' } const remote = decideNavigation( - useInstanceNavState(ref(installation('R', 'remote')), sources).navInput('primary') + useInstanceNavState(ref(installation('R', 'remote')), sources).navInput() ) const cloud = decideNavigation( - useInstanceNavState(ref(installation('C', 'cloud')), sources).navInput('primary') + useInstanceNavState(ref(installation('C', 'cloud')), sources).navInput() ) - expect(remote).toMatchObject({ window: 'new', verb: 'open-new' }) + expect(remote).toEqual({ verb: 'open-new', primaryLabel: NAV_LABEL.openCloud }) expect(remote).toEqual(cloud) }) }) diff --git a/src/renderer/src/composables/useInstanceNavState.ts b/src/renderer/src/composables/useInstanceNavState.ts index f565d8539..685736ace 100644 --- a/src/renderer/src/composables/useInstanceNavState.ts +++ b/src/renderer/src/composables/useInstanceNavState.ts @@ -15,7 +15,7 @@ export interface InstanceNavState { isTargetCurrentHost: ComputedRef isTargetRunningElsewhere: ComputedRef isTargetRunningHere: ComputedRef - navInput: (intent: NavInput['intent']) => NavInput + navInput: () => NavInput } export interface InstanceNavStateSources { @@ -62,11 +62,10 @@ export function useInstanceNavState( return 'stopped' }) - const navInput = (intent: NavInput['intent']): NavInput => ({ + const navInput = (): NavInput => ({ currentView: toValue(sources.currentView), target: targetKind.value, - targetRun: targetRun.value, - intent + targetRun: targetRun.value }) return { diff --git a/src/renderer/src/panel/BuildDetailsView.test.ts b/src/renderer/src/panel/BuildDetailsView.test.ts index 48c0c8423..785a731c7 100644 --- a/src/renderer/src/panel/BuildDetailsView.test.ts +++ b/src/renderer/src/panel/BuildDetailsView.test.ts @@ -10,14 +10,7 @@ vi.mock('../components/settings/ComfyUISettingsContent.vue', () => ({ default: { name: 'ComfyUISettingsContent', props: ['installation', 'globalSettingsSnapshot', 'pageActionsTarget', 'pageTitleTarget'], - emits: [ - 'show-progress', - 'navigate-list', - 'request-close', - 'request-dismiss', - 'primary-action', - 'open-new-window' - ], + emits: ['show-progress', 'navigate-list', 'request-close', 'request-dismiss', 'primary-action'], template: '
{{ installation.name }}
' } @@ -38,7 +31,6 @@ const INSTALL: Installation = { } const unsubscribeSettings = vi.fn() -const openInstallInNewWindow = vi.fn() beforeEach(() => { vi.clearAllMocks() @@ -46,8 +38,7 @@ beforeEach(() => { getBuildStorageSnapshot: vi.fn().mockResolvedValue(SNAPSHOT), onSettingsChanged: vi.fn(() => unsubscribeSettings), onInstallationsChanged: vi.fn(() => () => {}), - onInstallationsVersionsUpdated: vi.fn(() => () => {}), - openInstallInNewWindow + onInstallationsVersionsUpdated: vi.fn(() => () => {}) } setActivePinia(createPinia()) }) @@ -95,20 +86,11 @@ describe('BuildDetailsView', () => { it('launches the build from the primary action', async () => { const { wrapper, content } = await mountDetails() - content.vm.$emit('primary-action', { verb: 'switch' }) + content.vm.$emit('primary-action', { verb: 'start' }) expect(wrapper.emitted('launch')).toEqual([[INSTALL]]) }) - it('opens the build in its own window instead of launching it into this one', async () => { - const { wrapper, content } = await mountDetails() - - content.vm.$emit('open-new-window', { verb: 'open-new' }) - - expect(openInstallInNewWindow).toHaveBeenCalledExactlyOnceWith('a') - expect(wrapper.emitted('launch')).toBeUndefined() - }) - it.each(['navigate-list', 'request-close', 'request-dismiss'])( 'returns to the list on %s', async (event) => { diff --git a/src/renderer/src/panel/BuildDetailsView.vue b/src/renderer/src/panel/BuildDetailsView.vue index 6a7c1604a..21daef5e4 100644 --- a/src/renderer/src/panel/BuildDetailsView.vue +++ b/src/renderer/src/panel/BuildDetailsView.vue @@ -71,10 +71,6 @@ const status = computed(() => { const storage = ref() -function openInNewWindow(): void { - window.api.openInstallInNewWindow(installation.id) -} - async function loadStorage(): Promise { storage.value = await window.api.getBuildStorageSnapshot() } @@ -159,7 +155,6 @@ onUnmounted(() => unsubscribeSettings?.()) @request-close="emit('back')" @request-dismiss="emit('back')" @primary-action="emit('launch', installation)" - @open-new-window="openInNewWindow" /> diff --git a/src/shared/navigation/navDecision.test.ts b/src/shared/navigation/navDecision.test.ts index 0f8759517..8e84e1359 100644 --- a/src/shared/navigation/navDecision.test.ts +++ b/src/shared/navigation/navDecision.test.ts @@ -2,7 +2,6 @@ import { describe, expect, it } from 'vitest' import { decideNavigation, NAV_LABEL, - type Intent, type NavInput, type TargetKind, type TargetRun @@ -13,14 +12,12 @@ import en from '../../../locales/en.json' const VIEWS: ViewKind[] = ['dashboard', 'instance', 'cloud'] const TARGETS: TargetKind[] = ['dashboard', 'instance', 'cloud', 'new-instance'] const RUNS: TargetRun[] = ['stopped', 'running-elsewhere', 'self', 'starting-unhosted'] -const INTENTS: Intent[] = ['primary', 'new-window'] function input(over: Partial): NavInput { return { currentView: 'dashboard', target: 'instance', targetRun: 'stopped', - intent: 'primary', ...over } } @@ -29,15 +26,24 @@ describe('decideNavigation — totality', () => { it('returns a valid decision for the entire input cross-product', () => { for (const currentView of VIEWS) for (const target of TARGETS) - for (const targetRun of RUNS) - for (const intent of INTENTS) { - const d = decideNavigation(input({ currentView, target, targetRun, intent })) - expect(d).toBeDefined() - expect(['same', 'new']).toContain(d.window) - expect(d.verb).toBeTruthy() - expect(Object.values(NAV_LABEL)).toContain(d.primaryLabel) - expect(Array.isArray(d.secondary)).toBe(true) - } + for (const targetRun of RUNS) { + const d = decideNavigation(input({ currentView, target, targetRun })) + expect(d).toBeDefined() + expect(d.verb).toBeTruthy() + expect(Object.values(NAV_LABEL)).toContain(d.primaryLabel) + } + }) + + it('never puts a different build into a build or Cloud window', () => { + for (const currentView of ['instance', 'cloud'] as const) + for (const target of ['instance', 'cloud'] as const) + for (const targetRun of RUNS) { + if (targetRun === 'self') continue + const d = decideNavigation(input({ currentView, target, targetRun })) + expect(['open-new', 'focus'], `${currentView} → ${target} (${targetRun})`).toContain( + d.verb + ) + } }) it('never produces a dead no-op CTA for a reachable (host, install-target, run) combo', () => { @@ -66,39 +72,37 @@ describe('decideNavigation — totality', () => { }) }) -describe('decideNavigation — the CURRENT-behavior matrix (baseline before #926 deltas)', () => { +describe('decideNavigation — every build opens in its own window', () => { const decisionFor = (currentView: ViewKind, target: TargetKind, targetRun: TargetRun) => decideNavigation(input({ currentView, target, targetRun })) it('Dashboard → Dashboard: no-op', () => { expect(decisionFor('dashboard', 'dashboard', 'self').verb).toBe('no-op') }) - it('Dashboard → Instance (stopped): Start in same window, no caret', () => { - const decision = decisionFor('dashboard', 'instance', 'stopped') - expect(decision).toMatchObject({ - window: 'same', - verb: 'switch', + it('Dashboard → stopped build: Start from this Desktop window', () => { + expect(decisionFor('dashboard', 'instance', 'stopped')).toEqual({ + verb: 'start', primaryLabel: NAV_LABEL.start }) - expect(decision.secondary).toHaveLength(0) }) - it('Dashboard → Instance (running elsewhere): focus, label Switch, no caret', () => { - const decision = decisionFor('dashboard', 'instance', 'running-elsewhere') - expect(decision).toMatchObject({ - window: 'same', + it('Dashboard → closed Cloud: Open Cloud from this Desktop window', () => { + expect(decisionFor('dashboard', 'cloud', 'stopped')).toEqual({ + verb: 'start', + primaryLabel: NAV_LABEL.openCloud + }) + }) + it('Dashboard → build running elsewhere: focus its window, label Switch', () => { + expect(decisionFor('dashboard', 'instance', 'running-elsewhere')).toEqual({ verb: 'focus', primaryLabel: NAV_LABEL.switch }) - expect(decision.secondary).toHaveLength(0) + expect(decisionFor('dashboard', 'cloud', 'running-elsewhere').verb).toBe('focus') }) - it('Dashboard → Instance (starting with no window): Restart, no caret', () => { - const decision = decisionFor('dashboard', 'instance', 'starting-unhosted') - expect(decision).toMatchObject({ - window: 'same', + it('Dashboard → build starting with no window: Restart', () => { + expect(decisionFor('dashboard', 'instance', 'starting-unhosted')).toEqual({ verb: 'restart', primaryLabel: NAV_LABEL.restart }) - expect(decision.secondary).toHaveLength(0) }) it('a build starting with no window reads as running elsewhere outside Dashboard → Instance', () => { const elsewhere: Array<[ViewKind, TargetKind]> = [ @@ -114,176 +118,71 @@ describe('decideNavigation — the CURRENT-behavior matrix (baseline before #926 ) } }) - it('Dashboard → Cloud (closed): Open Cloud same window + new-window caret', () => { - const decision = decisionFor('dashboard', 'cloud', 'stopped') - expect(decision).toMatchObject({ - window: 'same', - verb: 'switch', - primaryLabel: NAV_LABEL.openCloud - }) - expect(decision.secondary.some((alt) => alt.window === 'new' && alt.verb === 'open-new')).toBe( - true - ) - }) it('Dashboard → New Instance: install wizard', () => { expect(decisionFor('dashboard', 'new-instance', 'stopped').verb).toBe('install-wizard') }) - it('Instance → Dashboard: NEW window (instance keeps running)', () => { - const decision = decisionFor('instance', 'dashboard', 'self') - expect(decision).toMatchObject({ - window: 'new', + it('build window → stopped build B: Start opens B in its own window', () => { + expect(decisionFor('instance', 'instance', 'stopped')).toEqual({ verb: 'open-new', - primaryLabel: NAV_LABEL.openDashboard + primaryLabel: NAV_LABEL.start }) }) - it('Instance → self: Restart in place', () => { - const decision = decisionFor('instance', 'instance', 'self') - expect(decision).toMatchObject({ - window: 'same', + it('build window → closed Cloud: Open Cloud in its own window', () => { + expect(decisionFor('instance', 'cloud', 'stopped')).toEqual({ + verb: 'open-new', + primaryLabel: NAV_LABEL.openCloud + }) + }) + it('build window → itself: Restart in place', () => { + expect(decisionFor('instance', 'instance', 'self')).toEqual({ verb: 'restart', primaryLabel: NAV_LABEL.restart }) }) - it('Instance → Instance B (stopped): switch in place + new-window caret (matrix row 9)', () => { - const decision = decisionFor('instance', 'instance', 'stopped') - expect(decision).toMatchObject({ window: 'same', verb: 'switch' }) - expect(decision.secondary.some((alt) => alt.window === 'new' && alt.verb === 'open-new')).toBe( - true - ) - }) - it('Instance → Instance B (running elsewhere): focus, no caret', () => { - const decision = decisionFor('instance', 'instance', 'running-elsewhere') - expect(decision.verb).toBe('focus') - expect(decision.secondary).toHaveLength(0) + it('build window → build running elsewhere: focus its window', () => { + expect(decisionFor('instance', 'instance', 'running-elsewhere').verb).toBe('focus') + expect(decisionFor('instance', 'cloud', 'running-elsewhere').verb).toBe('focus') }) - it('Instance → Cloud (closed): NEW window, keeps the instance running', () => { - const decision = decisionFor('instance', 'cloud', 'stopped') - expect(decision).toMatchObject({ - window: 'new', + it('build window → Dashboard: open-new', () => { + expect(decisionFor('instance', 'dashboard', 'self')).toEqual({ verb: 'open-new', - primaryLabel: NAV_LABEL.openCloud + primaryLabel: NAV_LABEL.openDashboard }) }) - it('Cloud → Dashboard: new window today (chip is not table-driven)', () => { - const decision = decisionFor('cloud', 'dashboard', 'self') - expect(decision).toMatchObject({ - window: 'new', + it('Cloud window → stopped build: Start opens it in its own window', () => { + expect(decisionFor('cloud', 'instance', 'stopped')).toEqual({ verb: 'open-new', - primaryLabel: NAV_LABEL.openDashboard + primaryLabel: NAV_LABEL.start }) }) - it('Cloud → Instance (stopped): NEW window, keeps the cloud session running', () => { - const decision = decisionFor('cloud', 'instance', 'stopped') - expect(decision).toMatchObject({ - window: 'new', + it('Cloud window → another closed Cloud or remote build: Open Cloud in its own window', () => { + expect(decisionFor('cloud', 'cloud', 'stopped')).toEqual({ verb: 'open-new', - primaryLabel: NAV_LABEL.openInNewWindow + primaryLabel: NAV_LABEL.openCloud }) }) - it('Cloud/Remote → self: Restart in place (second view of one session unsupported)', () => { - const decision = decisionFor('cloud', 'cloud', 'self') - expect(decision).toMatchObject({ - window: 'same', + it('Cloud window → itself: Restart in place', () => { + expect(decisionFor('cloud', 'cloud', 'self')).toEqual({ verb: 'restart', primaryLabel: NAV_LABEL.restart }) }) - it('Cloud → a DIFFERENT cloud/remote running elsewhere: focus (not a dead Start)', () => { - const decision = decisionFor('cloud', 'cloud', 'running-elsewhere') - expect(decision).toMatchObject({ - window: 'same', + it('Cloud window → build running elsewhere: focus its window', () => { + expect(decisionFor('cloud', 'cloud', 'running-elsewhere')).toEqual({ verb: 'focus', primaryLabel: NAV_LABEL.switch }) + expect(decisionFor('cloud', 'instance', 'running-elsewhere').verb).toBe('focus') }) - it('Cloud → a stopped cloud/remote target: opens in a new window (not a dead Start)', () => { - const decision = decisionFor('cloud', 'cloud', 'stopped') - expect(decision).toMatchObject({ - window: 'new', - verb: 'open-new', - primaryLabel: NAV_LABEL.openInNewWindow - }) - }) - it('Cloud → New Instance: install wizard in a new window', () => { - const decision = decisionFor('cloud', 'new-instance', 'stopped') - expect(decision).toMatchObject({ window: 'new', verb: 'install-wizard' }) - }) -}) - -describe('decideNavigation — boundary rules', () => { - it('new-window intent selects the new-window secondary when offered', () => { - const d = decideNavigation( - input({ - currentView: 'dashboard', - target: 'cloud', - targetRun: 'stopped', - intent: 'new-window' - }) - ) - expect(d).toMatchObject({ - window: 'new', - verb: 'open-new', - primaryLabel: NAV_LABEL.openInNewWindow - }) - }) - - it('new-window intent falls back to the primary when no secondary exists', () => { - const primary = decideNavigation( - input({ currentView: 'instance', target: 'instance', targetRun: 'self', intent: 'primary' }) - ) - const viaCaret = decideNavigation( - input({ - currentView: 'instance', - target: 'instance', - targetRun: 'self', - intent: 'new-window' - }) - ) - expect(viaCaret).toEqual(primary) + it('Cloud window → New Instance: install wizard', () => { + expect(decisionFor('cloud', 'new-instance', 'stopped').verb).toBe('install-wizard') }) -}) - -describe('decideNavigation — caret (new-window intent)', () => { - it('instance host → stopped instance B: caret selects the new-window alternative', () => { - const primary = decideNavigation( - input({ - currentView: 'instance', - target: 'instance', - targetRun: 'stopped', - intent: 'primary' - }) - ) - expect(primary).toMatchObject({ window: 'same', verb: 'switch' }) - const caret = decideNavigation( - input({ - currentView: 'instance', - target: 'instance', - targetRun: 'stopped', - intent: 'new-window' - }) - ) - expect(caret).toMatchObject({ - window: 'new', + it('Cloud window → Dashboard: open-new', () => { + expect(decisionFor('cloud', 'dashboard', 'self')).toEqual({ verb: 'open-new', - primaryLabel: NAV_LABEL.openInNewWindow - }) - }) - - it('dashboard host → open cloud: caret selects the new-window alternative', () => { - const caret = decideNavigation( - input({ - currentView: 'dashboard', - target: 'cloud', - targetRun: 'stopped', - intent: 'new-window' - }) - ) - expect(caret).toMatchObject({ - window: 'new', - verb: 'open-new', - primaryLabel: NAV_LABEL.openInNewWindow + primaryLabel: NAV_LABEL.openDashboard }) }) }) diff --git a/src/shared/navigation/navDecision.ts b/src/shared/navigation/navDecision.ts index 6421e7bb8..d804734e5 100644 --- a/src/shared/navigation/navDecision.ts +++ b/src/shared/navigation/navDecision.ts @@ -4,9 +4,7 @@ export type TargetKind = 'dashboard' | 'instance' | 'cloud' | 'new-instance' export type TargetRun = 'stopped' | 'running-elsewhere' | 'self' | 'starting-unhosted' -export type Intent = 'primary' | 'new-window' - -export type Verb = 'switch' | 'restart' | 'open-new' | 'focus' | 'no-op' | 'install-wizard' +export type Verb = 'start' | 'restart' | 'open-new' | 'focus' | 'no-op' | 'install-wizard' export const NAV_LABEL = { start: 'instancePicker.open', @@ -14,165 +12,60 @@ export const NAV_LABEL = { switch: 'instancePicker.switch', openDashboard: 'instancePicker.openDashboard', openCloud: 'instancePicker.openCloud', - openInNewWindow: 'instancePicker.openInNewWindow', newInstall: 'instancePicker.newInstance' } as const export type NavLabelKey = (typeof NAV_LABEL)[keyof typeof NAV_LABEL] export interface NavDecision { - readonly window: 'same' | 'new' readonly verb: Verb readonly primaryLabel: NavLabelKey - readonly secondary: readonly NavDecision[] - readonly allowDuplicate?: true } export interface NavInput { currentView: ViewKind target: TargetKind targetRun: TargetRun - intent: Intent } type CellKey = `${ViewKind}|${TargetKind}|${TargetRun}` const cellKey = (view: ViewKind, target: TargetKind, run: TargetRun): CellKey => `${view}|${target}|${run}` -const NO_OP: NavDecision = Object.freeze({ - window: 'same', - verb: 'no-op', - primaryLabel: NAV_LABEL.start, - secondary: [] -}) - -const dec = ( - over: Partial & Pick -): NavDecision => - Object.freeze({ - ...over, - secondary: Object.freeze(over.secondary ?? []) - }) +const dec = (verb: Verb, primaryLabel: NavLabelKey): NavDecision => + Object.freeze({ verb, primaryLabel }) -const OPEN_NEW_WINDOW_SECONDARY: NavDecision = dec({ - window: 'new', - verb: 'open-new', - primaryLabel: NAV_LABEL.openInNewWindow -}) +const NO_OP = dec('no-op', NAV_LABEL.start) const TABLE: ReadonlyMap = new Map([ [cellKey('dashboard', 'dashboard', 'self'), NO_OP], - [ - cellKey('dashboard', 'instance', 'stopped'), - dec({ window: 'same', verb: 'switch', primaryLabel: NAV_LABEL.start }) - ], - [ - cellKey('dashboard', 'instance', 'running-elsewhere'), - dec({ window: 'same', verb: 'focus', primaryLabel: NAV_LABEL.switch }) - ], - [ - cellKey('dashboard', 'instance', 'starting-unhosted'), - dec({ window: 'same', verb: 'restart', primaryLabel: NAV_LABEL.restart }) - ], - [ - cellKey('dashboard', 'cloud', 'stopped'), - dec({ - window: 'same', - verb: 'switch', - primaryLabel: NAV_LABEL.openCloud, - secondary: [OPEN_NEW_WINDOW_SECONDARY] - }) - ], - [ - cellKey('dashboard', 'cloud', 'running-elsewhere'), - dec({ - window: 'same', - verb: 'focus', - primaryLabel: NAV_LABEL.switch, - secondary: [OPEN_NEW_WINDOW_SECONDARY] - }) - ], - [ - cellKey('dashboard', 'new-instance', 'stopped'), - dec({ window: 'same', verb: 'install-wizard', primaryLabel: NAV_LABEL.newInstall }) - ], - - [ - cellKey('instance', 'dashboard', 'self'), - dec({ window: 'new', verb: 'open-new', primaryLabel: NAV_LABEL.openDashboard }) - ], - [ - cellKey('instance', 'instance', 'self'), - dec({ window: 'same', verb: 'restart', primaryLabel: NAV_LABEL.restart }) - ], - [ - cellKey('instance', 'instance', 'stopped'), - dec({ - window: 'same', - verb: 'switch', - primaryLabel: NAV_LABEL.switch, - secondary: [OPEN_NEW_WINDOW_SECONDARY] - }) - ], - [ - cellKey('instance', 'instance', 'running-elsewhere'), - dec({ window: 'same', verb: 'focus', primaryLabel: NAV_LABEL.switch }) - ], - [ - cellKey('instance', 'cloud', 'stopped'), - dec({ window: 'new', verb: 'open-new', primaryLabel: NAV_LABEL.openCloud }) - ], - [ - cellKey('instance', 'cloud', 'running-elsewhere'), - dec({ - window: 'same', - verb: 'focus', - primaryLabel: NAV_LABEL.switch, - secondary: [OPEN_NEW_WINDOW_SECONDARY] - }) - ], - - [ - cellKey('cloud', 'dashboard', 'self'), - dec({ window: 'new', verb: 'open-new', primaryLabel: NAV_LABEL.openDashboard }) - ], - [ - cellKey('cloud', 'instance', 'stopped'), - dec({ window: 'new', verb: 'open-new', primaryLabel: NAV_LABEL.openInNewWindow }) - ], - [ - cellKey('cloud', 'instance', 'running-elsewhere'), - dec({ window: 'same', verb: 'focus', primaryLabel: NAV_LABEL.switch }) - ], - [ - cellKey('cloud', 'cloud', 'self'), - dec({ window: 'same', verb: 'restart', primaryLabel: NAV_LABEL.restart }) - ], - [ - cellKey('cloud', 'cloud', 'running-elsewhere'), - dec({ window: 'same', verb: 'focus', primaryLabel: NAV_LABEL.switch }) - ], - [ - cellKey('cloud', 'cloud', 'stopped'), - dec({ window: 'new', verb: 'open-new', primaryLabel: NAV_LABEL.openInNewWindow }) - ], - [ - cellKey('cloud', 'new-instance', 'stopped'), - dec({ window: 'new', verb: 'install-wizard', primaryLabel: NAV_LABEL.newInstall }) - ] + [cellKey('dashboard', 'instance', 'stopped'), dec('start', NAV_LABEL.start)], + [cellKey('dashboard', 'instance', 'running-elsewhere'), dec('focus', NAV_LABEL.switch)], + [cellKey('dashboard', 'instance', 'starting-unhosted'), dec('restart', NAV_LABEL.restart)], + [cellKey('dashboard', 'cloud', 'stopped'), dec('start', NAV_LABEL.openCloud)], + [cellKey('dashboard', 'cloud', 'running-elsewhere'), dec('focus', NAV_LABEL.switch)], + [cellKey('dashboard', 'new-instance', 'stopped'), dec('install-wizard', NAV_LABEL.newInstall)], + + [cellKey('instance', 'dashboard', 'self'), dec('open-new', NAV_LABEL.openDashboard)], + [cellKey('instance', 'instance', 'self'), dec('restart', NAV_LABEL.restart)], + [cellKey('instance', 'instance', 'stopped'), dec('open-new', NAV_LABEL.start)], + [cellKey('instance', 'instance', 'running-elsewhere'), dec('focus', NAV_LABEL.switch)], + [cellKey('instance', 'cloud', 'stopped'), dec('open-new', NAV_LABEL.openCloud)], + [cellKey('instance', 'cloud', 'running-elsewhere'), dec('focus', NAV_LABEL.switch)], + + [cellKey('cloud', 'dashboard', 'self'), dec('open-new', NAV_LABEL.openDashboard)], + [cellKey('cloud', 'instance', 'stopped'), dec('open-new', NAV_LABEL.start)], + [cellKey('cloud', 'instance', 'running-elsewhere'), dec('focus', NAV_LABEL.switch)], + [cellKey('cloud', 'cloud', 'self'), dec('restart', NAV_LABEL.restart)], + [cellKey('cloud', 'cloud', 'running-elsewhere'), dec('focus', NAV_LABEL.switch)], + [cellKey('cloud', 'cloud', 'stopped'), dec('open-new', NAV_LABEL.openCloud)], + [cellKey('cloud', 'new-instance', 'stopped'), dec('install-wizard', NAV_LABEL.newInstall)] ]) -function tableCell(input: NavInput): NavDecision | undefined { - const exact = TABLE.get(cellKey(input.currentView, input.target, input.targetRun)) - if (exact || input.targetRun !== 'starting-unhosted') return exact - return TABLE.get(cellKey(input.currentView, input.target, 'running-elsewhere')) -} - export function decideNavigation(input: NavInput): NavDecision { - const primary = tableCell(input) ?? NO_OP - - if (input.intent === 'new-window') { - const alt = primary.secondary.find((s) => s.window === 'new') - return alt ?? primary + const exact = TABLE.get(cellKey(input.currentView, input.target, input.targetRun)) + if (exact) return exact + if (input.targetRun === 'starting-unhosted') { + return TABLE.get(cellKey(input.currentView, input.target, 'running-elsewhere')) ?? NO_OP } - return primary + return NO_OP } diff --git a/src/types/ipc.ts b/src/types/ipc.ts index 0bf443e7f..263658151 100644 --- a/src/types/ipc.ts +++ b/src/types/ipc.ts @@ -1153,7 +1153,6 @@ export interface ElectronApi { terminalResize(installationId: string, cols: number, rows: number): Promise terminalRestart(installationId: string): Promise openInstallWindow(installationId: string): Promise - openInstallInNewWindow(installationId: string): void closeComfyWindow(installationId: string, opts?: { skipConfirm?: boolean }): Promise closeHostWindow(): Promise returnToDashboard(): Promise From 123323817291be9de101eaca43802505b16fe114 Mon Sep 17 00:00:00 2001 From: Benjamin Lu Date: Mon, 16 Nov 2026 11:27:22 -0800 Subject: [PATCH 3/7] test(e2e): Start on another build from a build window keeps this window and opens a new one The nav-matrix specs only open builds from the Desktop window, so nothing end-to-end covered a build window asking for another build. launch-own-window now runs a second fake ComfyUI. After the first build is running in its own window, the spec opens the picker from that window's title bar, starts the second build, and checks the first build's window is the same window, the second build has a window of its own, and there is still exactly one Desktop window. --- e2e/launch-own-window.test.ts | 103 ++++++++++++++++++++++++++++++---- 1 file changed, 91 insertions(+), 12 deletions(-) diff --git a/e2e/launch-own-window.test.ts b/e2e/launch-own-window.test.ts index f68f64c5f..0ab8ce07d 100644 --- a/e2e/launch-own-window.test.ts +++ b/e2e/launch-own-window.test.ts @@ -5,37 +5,57 @@ import { test, expect } from '@playwright/test' import { launchApp, type AppContext } from './launchApp' import { reserveFreePort, writeFakeComfyInstall } from './support/fakeComfyInstall' import { evalWithRetry } from './support/evalRetry' +import { openPickerViaTitlePill } from './support/chooserHelpers' +import { WebContentsPage } from './support/cdpPages' +import { byTestId, TID } from './support/testIds' const INSTALL_ID = 'inst-own-window' const INSTALL_NAME = 'Own Window Fixture' const CARD = `[data-testid="home-build"][data-build-id="${INSTALL_ID}"]` +const SECOND_INSTALL_ID = 'inst-own-window-second' +const SECOND_INSTALL_NAME = 'Second Window Fixture' let ctx: AppContext let installPath: string +let secondInstallPath: string let port = 0 +let secondPort = 0 + +function fakeComfyBuilderInstall(id: string, name: string, path: string, buildPort: number) { + return { + id, + name, + sourceId: 'comfybuilder', + sourceLabel: 'ComfyBuilder', + installPath: path, + status: 'installed', + launchArgs: `--port ${buildPort}`, + launchMode: 'window', + browserPartition: 'unique', + seen: true + } +} test.describe.configure({ mode: 'serial', timeout: 180_000 }) test.beforeAll(async () => { installPath = await mkdtemp(path.join(os.tmpdir(), 'comfyui-own-window-')) + secondInstallPath = await mkdtemp(path.join(os.tmpdir(), 'comfyui-own-window-second-')) port = await reserveFreePort() + secondPort = await reserveFreePort() await writeFakeComfyInstall({ installPath, port }) + await writeFakeComfyInstall({ installPath: secondInstallPath, port: secondPort }) ctx = await launchApp( { settings: { firstUseCompleted: true, telemetryEnabled: false }, installations: [ - { - id: INSTALL_ID, - name: INSTALL_NAME, - sourceId: 'comfybuilder', - sourceLabel: 'ComfyBuilder', - installPath, - status: 'installed', - launchArgs: `--port ${port}`, - launchMode: 'window', - browserPartition: 'unique', - seen: true - } + fakeComfyBuilderInstall(INSTALL_ID, INSTALL_NAME, installPath, port), + fakeComfyBuilderInstall( + SECOND_INSTALL_ID, + SECOND_INSTALL_NAME, + secondInstallPath, + secondPort + ) ] }, { stayOnHome: true } @@ -46,6 +66,7 @@ test.beforeAll(async () => { test.afterAll(async () => { await ctx?.cleanup() if (installPath) await rm(installPath, { recursive: true, force: true }) + if (secondInstallPath) await rm(secondInstallPath, { recursive: true, force: true }) }) interface WindowState { @@ -94,3 +115,61 @@ test('Start on a Home card opens ComfyUI in its own window and the dashboard sta message: 'the Home card never showed Running' }) }) + +interface TwoBuildWindows { + windows: number + firstBuildWindowIds: number[] + secondBuildWindows: number + desktopWindows: number +} + +function twoBuildWindows(): Promise { + return evalWithRetry(() => + ctx.app.evaluate( + ({ BrowserWindow, WebContentsView }, ports) => { + const wins = BrowserWindow.getAllWindows().filter((w) => !w.isDestroyed()) + const hosts = (w: Electron.BrowserWindow, p: number): boolean => + w.contentView.children.some( + (v) => v instanceof WebContentsView && v.webContents.getURL().includes(`:${p}`) + ) + return { + windows: wins.length, + firstBuildWindowIds: wins.filter((w) => hosts(w, ports.first)).map((w) => w.id), + secondBuildWindows: wins.filter((w) => hosts(w, ports.second)).length, + desktopWindows: wins.filter((w) => !hosts(w, ports.first) && !hosts(w, ports.second)) + .length + } + }, + { first: port, second: secondPort } + ) + ) +} + +test('Start on another build from a build window opens it in its own window and keeps this one @linux', async () => { + const before = await twoBuildWindows() + expect(before.firstBuildWindowIds, 'the first build is running in its own window').toHaveLength(1) + const [firstBuildWindowId] = before.firstBuildWindowIds + + const firstBuildTitleBar = new WebContentsPage( + ctx.app, + `comfyTitleBar.html?installationId=${INSTALL_ID}` + ) + const popup = await openPickerViaTitlePill(ctx.app, firstBuildTitleBar) + const secondRow = byTestId(TID.pickerRow(SECOND_INSTALL_ID)) + await popup.waitForVisible(secondRow, { timeout: 15_000 }) + expect(await popup.click(secondRow), 'second build selected').toBe(true) + await expect + .poll(() => popup.textOf(byTestId(TID.pickerPrimaryCta)), { + timeout: 10_000, + intervals: [200, 400] + }) + .toContain('Start') + expect(await popup.click(byTestId(TID.pickerPrimaryCta)), 'Start clicked').toBe(true) + + await expect.poll(twoBuildWindows, { timeout: 90_000, intervals: [250, 500, 1_000] }).toEqual({ + windows: 3, + firstBuildWindowIds: [firstBuildWindowId], + secondBuildWindows: 1, + desktopWindows: 1 + }) +}) From fd18cc98a6b08d121bcdf5ba6a92b62d689d4af9 Mon Sep 17 00:00:00 2001 From: Benjamin Lu Date: Mon, 16 Nov 2026 11:27:29 -0800 Subject: [PATCH 4/7] fix(windows): Switch on a starting build shows it instead of starting it again routeBuildOpen only knew a build's window once the build was attached. Two cases slipped through: - A Desktop window that has claimed a build (a startup restore) is that build's window-to-be. Picking the build elsewhere read "Switch" but routed to start-from-home, which skips claimed windows, so it opened a second Desktop window and asked it to launch the build again. It now focuses the claiming window. - A build starting from the Desktop window without a window yet shows "Switch" in a build window's picker. Clicking it re-sent the pick to the Desktop window, whose launch guard then asked whether to cancel the start in progress. It now just brings the Desktop window forward, where the build's Starting card is. Also removes openSystemModalChoiceAsync, unused since the Switch prompt went away. --- src/main/host/registry.test.ts | 37 +++++++++++++++++++++++++++------- src/main/host/registry.ts | 17 +++++++++++++--- src/main/index.ts | 5 ++++- src/main/popups/systemModal.ts | 6 ------ 4 files changed, 48 insertions(+), 17 deletions(-) diff --git a/src/main/host/registry.test.ts b/src/main/host/registry.test.ts index 81a875465..061c678b6 100644 --- a/src/main/host/registry.test.ts +++ b/src/main/host/registry.test.ts @@ -678,22 +678,45 @@ describe('routeBuildOpen', () => { registerHostEntry(buildWindow) registerHostEntry(desktop) - expect(routeBuildOpen('inst-B', desktop)).toEqual({ kind: 'focus', entry: buildWindow }) - expect(routeBuildOpen('inst-B', undefined)).toEqual({ kind: 'focus', entry: buildWindow }) + expect(routeBuildOpen('inst-B', desktop, [])).toEqual({ kind: 'focus', entry: buildWindow }) + expect(routeBuildOpen('inst-B', undefined, [])).toEqual({ kind: 'focus', entry: buildWindow }) + }) + + it('focuses the Desktop window that is becoming the build window, instead of opening another Desktop window', () => { + const becomingB = makeEntry({ installationId: null }) + const buildA = makeEntry({ installationId: 'inst-A' }) + registerHostEntry(becomingB) + registerHostEntry(buildA) + claimAttachHost('inst-B', becomingB.windowKey) + + expect(routeBuildOpen('inst-B', buildA, ['inst-B'])).toEqual({ + kind: 'focus', + entry: becomingB + }) + }) + + it('shows a build that is already starting from the Desktop window instead of starting it again', () => { + const desktop = makeEntry({ installationId: null }) + const buildA = makeEntry({ installationId: 'inst-A' }) + registerHostEntry(desktop) + registerHostEntry(buildA) + + expect(routeBuildOpen('inst-B', buildA, ['inst-B'])).toEqual({ kind: 'show-starting' }) + expect(routeBuildOpen('inst-B', desktop, ['inst-B'])).toEqual({ kind: 'show-starting' }) }) it('starts a build from the Desktop window that asked for it', () => { const desktop = makeEntry({ installationId: null }) registerHostEntry(desktop) - expect(routeBuildOpen('inst-B', desktop)).toEqual({ kind: 'start-from', entry: desktop }) + expect(routeBuildOpen('inst-B', desktop, [])).toEqual({ kind: 'start-from', entry: desktop }) }) it('never hands another build to a build window: it starts from the Desktop window instead', () => { const buildA = makeEntry({ installationId: 'inst-A' }) registerHostEntry(buildA) - expect(routeBuildOpen('inst-B', buildA)).toEqual({ kind: 'start-from-home' }) + expect(routeBuildOpen('inst-B', buildA, [])).toEqual({ kind: 'start-from-home' }) }) it('treats a Desktop window that is becoming a build window like a build window', () => { @@ -701,7 +724,7 @@ describe('routeBuildOpen', () => { registerHostEntry(claimed) claimAttachHost('inst-A', claimed.windowKey) - expect(routeBuildOpen('inst-B', claimed)).toEqual({ kind: 'start-from-home' }) + expect(routeBuildOpen('inst-B', claimed, [])).toEqual({ kind: 'start-from-home' }) }) it('does nothing when a build window asks for itself', () => { @@ -709,10 +732,10 @@ describe('routeBuildOpen', () => { buildA.window.isDestroyed = () => false comfyWindows.set(buildA.windowKey, buildA) - expect(routeBuildOpen('inst-A', buildA)).toEqual({ kind: 'ignore' }) + expect(routeBuildOpen('inst-A', buildA, [])).toEqual({ kind: 'ignore' }) }) it('starts from the Desktop window when the request names no window', () => { - expect(routeBuildOpen('inst-B', undefined)).toEqual({ kind: 'start-from-home' }) + expect(routeBuildOpen('inst-B', undefined, [])).toEqual({ kind: 'start-from-home' }) }) }) diff --git a/src/main/host/registry.ts b/src/main/host/registry.ts index 456da05fd..6f2b55f79 100644 --- a/src/main/host/registry.ts +++ b/src/main/host/registry.ts @@ -356,15 +356,26 @@ export type BuildOpenRoute = | { kind: 'focus'; entry: ComfyWindowEntry } | { kind: 'start-from'; entry: ComfyWindowEntry } | { kind: 'start-from-home' } + | { kind: 'show-starting' } | { kind: 'ignore' } +function findWindowForBuild(installationId: string): ComfyWindowEntry | undefined { + const hosted = getEntryByInstallationId(installationId) + if (hosted && !hosted.window.isDestroyed()) return hosted + const claimedKey = pendingAttachClaims.get(installationId) + const claimed = claimedKey === undefined ? undefined : comfyWindows.get(claimedKey) + return claimed && !claimed.window.isDestroyed() ? claimed : undefined +} + export function routeBuildOpen( installationId: string, - requester: ComfyWindowEntry | undefined + requester: ComfyWindowEntry | undefined, + launchingInstallationIds: readonly string[] ): BuildOpenRoute { - const existing = getEntryByInstallationId(installationId) - if (existing && !existing.window.isDestroyed()) return { kind: 'focus', entry: existing } + const own = findWindowForBuild(installationId) + if (own) return { kind: 'focus', entry: own } if (requester?.installationId === installationId) return { kind: 'ignore' } + if (launchingInstallationIds.includes(installationId)) return { kind: 'show-starting' } if (requester && isHomeHostEntry(requester)) return { kind: 'start-from', entry: requester } return { kind: 'start-from-home' } } diff --git a/src/main/index.ts b/src/main/index.ts index f7111955a..672ff4120 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -1081,7 +1081,7 @@ if (app.isPackaged && !app.requestSingleInstanceLock()) { ): Promise => { const requester = requesterEntryId === undefined ? undefined : comfyWindows.get(requesterEntryId) - const route = routeBuildOpen(installationId, requester) + const route = routeBuildOpen(installationId, requester, _getLaunchingInstallationIds()) onRoute?.(route) switch (route.kind) { case 'ignore': @@ -1089,6 +1089,9 @@ if (app.isPackaged && !app.requestSingleInstanceLock()) { case 'focus': bringToFront(route.entry.window) return + case 'show-starting': + openOrFocusHomeHostWindow() + return case 'start-from': deliverPickToEntry(route.entry, installationId) return diff --git a/src/main/popups/systemModal.ts b/src/main/popups/systemModal.ts index 92264a64b..93907875c 100644 --- a/src/main/popups/systemModal.ts +++ b/src/main/popups/systemModal.ts @@ -165,12 +165,6 @@ export function openSystemModalAsync(opts: OpenSystemModalOpts): Promise action === 'confirm') } -export function openSystemModalChoiceAsync( - opts: OpenSystemModalOpts -): Promise<'confirm' | 'cancel' | 'secondary'> { - return openSystemModalResolving(opts, (action) => action) -} - export function registerSystemModalIpc(): void { ipcMain.on('comfy-systemmodal:ready', (event) => { const entry = systemModalsByWebContents.get(event.sender.id) From 60070737da3875e2b25333ee7fea488f120e5271 Mon Sep 17 00:00:00 2001 From: Benjamin Lu Date: Mon, 16 Nov 2026 11:35:24 -0800 Subject: [PATCH 5/7] test(e2e): answer the Run All prompt when a build window starts a second build CI showed the second build's start reach the Desktop window, which asked "An instance is already running" (Run All or Close & Launch) because the first build was still running. The spec never answered it, so the second build never got a window. It now checks that the prompt appears in the Desktop window and chooses Run All, which keeps the first build running, before waiting for the second build's own window. --- e2e/launch-own-window.test.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/e2e/launch-own-window.test.ts b/e2e/launch-own-window.test.ts index 0ab8ce07d..4729662bb 100644 --- a/e2e/launch-own-window.test.ts +++ b/e2e/launch-own-window.test.ts @@ -166,6 +166,14 @@ test('Start on another build from a build window opens it in its own window and .toContain('Start') expect(await popup.click(byTestId(TID.pickerPrimaryCta)), 'Start clicked').toBe(true) + const runAll = '[data-testid="base-alert-secondary"]' + await ctx.panel.waitForVisible(runAll, { timeout: 15_000 }) + expect( + await ctx.panel.textOf(runAll), + 'the Desktop window asks before running a second build' + ).toContain('Run All') + expect(await ctx.panel.click(runAll), 'Run All keeps the first build running').toBe(true) + await expect.poll(twoBuildWindows, { timeout: 90_000, intervals: [250, 500, 1_000] }).toEqual({ windows: 3, firstBuildWindowIds: [firstBuildWindowId], From 84d41bdfc2d96cbd5aac877d35c6805ad4e69fd8 Mon Sep 17 00:00:00 2001 From: Benjamin Lu Date: Mon, 16 Nov 2026 11:40:11 -0800 Subject: [PATCH 6/7] Merge origin/main; keep the asking Desktop window for a starting build Merging main brings in the panel preview harness (#2144), whose typed fake bridge still stubbed openInstallInNewWindow, which this branch removed from the preload bridge. The stub goes, which fixes Typecheck. routeBuildOpen's show-starting route now carries the requesting Desktop window when it is one, so picking a starting build from a second Desktop window keeps that window in front instead of focusing whichever Desktop window was registered first. A build-window requester still falls back to the Desktop window. --- src/main/host/registry.test.ts | 22 ++++++++++++++++++++-- src/main/host/registry.ts | 9 ++++++--- src/main/index.ts | 3 ++- src/renderer/src/preview/fakeBridge.ts | 1 - 4 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/main/host/registry.test.ts b/src/main/host/registry.test.ts index 061c678b6..3d100d50d 100644 --- a/src/main/host/registry.test.ts +++ b/src/main/host/registry.test.ts @@ -701,8 +701,26 @@ describe('routeBuildOpen', () => { registerHostEntry(desktop) registerHostEntry(buildA) - expect(routeBuildOpen('inst-B', buildA, ['inst-B'])).toEqual({ kind: 'show-starting' }) - expect(routeBuildOpen('inst-B', desktop, ['inst-B'])).toEqual({ kind: 'show-starting' }) + expect(routeBuildOpen('inst-B', buildA, ['inst-B'])).toEqual({ + kind: 'show-starting', + entry: null + }) + expect(routeBuildOpen('inst-B', desktop, ['inst-B'])).toEqual({ + kind: 'show-starting', + entry: desktop + }) + }) + + it('shows a starting build in the Desktop window that asked, not the first one registered', () => { + const firstDesktop = makeEntry({ installationId: null }) + const secondDesktop = makeEntry({ installationId: null }) + registerHostEntry(firstDesktop) + registerHostEntry(secondDesktop) + + expect(routeBuildOpen('inst-B', secondDesktop, ['inst-B'])).toEqual({ + kind: 'show-starting', + entry: secondDesktop + }) }) it('starts a build from the Desktop window that asked for it', () => { diff --git a/src/main/host/registry.ts b/src/main/host/registry.ts index 6f2b55f79..d73360688 100644 --- a/src/main/host/registry.ts +++ b/src/main/host/registry.ts @@ -356,7 +356,7 @@ export type BuildOpenRoute = | { kind: 'focus'; entry: ComfyWindowEntry } | { kind: 'start-from'; entry: ComfyWindowEntry } | { kind: 'start-from-home' } - | { kind: 'show-starting' } + | { kind: 'show-starting'; entry: ComfyWindowEntry | null } | { kind: 'ignore' } function findWindowForBuild(installationId: string): ComfyWindowEntry | undefined { @@ -375,8 +375,11 @@ export function routeBuildOpen( const own = findWindowForBuild(installationId) if (own) return { kind: 'focus', entry: own } if (requester?.installationId === installationId) return { kind: 'ignore' } - if (launchingInstallationIds.includes(installationId)) return { kind: 'show-starting' } - if (requester && isHomeHostEntry(requester)) return { kind: 'start-from', entry: requester } + const homeRequester = requester && isHomeHostEntry(requester) ? requester : null + if (launchingInstallationIds.includes(installationId)) { + return { kind: 'show-starting', entry: homeRequester } + } + if (homeRequester) return { kind: 'start-from', entry: homeRequester } return { kind: 'start-from-home' } } diff --git a/src/main/index.ts b/src/main/index.ts index 672ff4120..86aede12c 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -1090,7 +1090,8 @@ if (app.isPackaged && !app.requestSingleInstanceLock()) { bringToFront(route.entry.window) return case 'show-starting': - openOrFocusHomeHostWindow() + if (route.entry) bringToFront(route.entry.window) + else openOrFocusHomeHostWindow() return case 'start-from': deliverPickToEntry(route.entry, installationId) diff --git a/src/renderer/src/preview/fakeBridge.ts b/src/renderer/src/preview/fakeBridge.ts index cf5f2bb9e..21033098f 100644 --- a/src/renderer/src/preview/fakeBridge.ts +++ b/src/renderer/src/preview/fakeBridge.ts @@ -242,7 +242,6 @@ export function createFakeBridge(seed: BridgeSeed = {}): FakeBridge { terminalResize: async () => {}, terminalRestart: async () => ({ buffer: [], size: { cols: 80, rows: 24 }, exited: false }), openInstallWindow: async () => true, - openInstallInNewWindow: () => {}, closeComfyWindow: async () => true, closeHostWindow: async () => true, returnToDashboard: async () => true, From ab97562f7392820cee98412eab6f4d129c734572 Mon Sep 17 00:00:00 2001 From: Benjamin Lu Date: Mon, 16 Nov 2026 11:48:53 -0800 Subject: [PATCH 7/7] refactor(windows): one pick channel for every build start, counted the same from every window After this PR, Start from a build or Cloud window (verb open-new, sent on comfy-titlepopup:open-install-new-window) and Start from the Desktop window (verb start, sent on comfy-titlepopup:pick-install) reached the same openBuild route. Only their telemetry differed: opened_new_window fired for the first and never for the second, though both start the build from the Desktop window. - Build and Cloud windows now get verb start for a stopped build, like the Desktop window. Main's routeBuildOpen decides the window, so the nav table no longer encodes a window split that changes nothing. - The open-install-new-window channel, the openInstallNewWindow bridge method and the openInstallInNewWindow binding are removed. pick-install carries every pick. - openBuild records each route (E2E record open-build) and emits opened_new_window for every start, whichever window asked. - nav-matrix-instance and nav-matrix-dashboard drove the removed channel from the Desktop window; they now click through pickInstall and assert the start-from route. openPicker loses its single-valued bridgeFn parameter. --- e2e/nav-matrix-cloud.test.ts | 2 +- e2e/nav-matrix-dashboard.test.ts | 20 ++++----- e2e/nav-matrix-instance.test.ts | 16 +++---- e2e/support/navMatrixHelpers.ts | 8 +--- src/main/index.ts | 44 ++++++------------- src/main/popups/titlePopup.ts | 18 -------- src/preload/comfyTitlePopupPreload.ts | 4 -- .../InstancePickerView.test.ts | 8 +--- .../comfyTitlePopup/InstancePickerView.vue | 1 - .../composables/useInstanceActions.test.ts | 8 +--- .../src/composables/useInstanceActions.ts | 8 +--- .../composables/useInstanceNavState.test.ts | 8 ++-- src/shared/navigation/navDecision.test.ts | 24 +++++----- src/shared/navigation/navDecision.ts | 8 ++-- 14 files changed, 57 insertions(+), 120 deletions(-) diff --git a/e2e/nav-matrix-cloud.test.ts b/e2e/nav-matrix-cloud.test.ts index a1c802460..2f02dcd7a 100644 --- a/e2e/nav-matrix-cloud.test.ts +++ b/e2e/nav-matrix-cloud.test.ts @@ -18,7 +18,7 @@ async function cloudRunActions(): Promise<{ installationId?: string }[]> { } async function openCloudFromPicker(): Promise { - await openPicker(ctx.app, ctx.panel, 'pickInstall') + await openPicker(ctx.app, ctx.panel) const popup = titlePopupPage(ctx.app) const cloudRow = byTestId(TID.pickerRow(CLOUD_ID)) await popup.waitForVisible(cloudRow) diff --git a/e2e/nav-matrix-dashboard.test.ts b/e2e/nav-matrix-dashboard.test.ts index 91cf510d0..b1af70ccf 100644 --- a/e2e/nav-matrix-dashboard.test.ts +++ b/e2e/nav-matrix-dashboard.test.ts @@ -77,7 +77,7 @@ test.beforeEach(async () => { await closeTitlePopupIfOpen(ctx.app) await resetIpcInvocations(ctx.app, 'focus-comfy-window') await resetIpcInvocations(ctx.app, 'run-action') - await resetIpcInvocations(ctx.app, 'open-install-new-window') + await resetIpcInvocations(ctx.app, 'open-build') await clearRunningSessions(ctx.app) }) @@ -101,7 +101,7 @@ test('Home → Builds → Update settings opens the selected installation @windo test('Dashboard → stopped instance: same-window launch, no new window @windows @macos @linux', async () => { const before = await liveWindowCount(ctx.app) - await openPicker(ctx.app, ctx.panel, 'pickInstall') + await openPicker(ctx.app, ctx.panel) const popup = titlePopupPage(ctx.app) await popup.evaluate( @@ -140,7 +140,7 @@ test('Dashboard → running instance: focus existing window @windows @macos @lin installationName: INSTALL_A_NAME }) const before = await liveWindowCount(ctx.app) - await openPicker(ctx.app, ctx.panel, 'pickInstall') + await openPicker(ctx.app, ctx.panel) const popup = titlePopupPage(ctx.app) await popup.evaluate( @@ -165,23 +165,21 @@ test('Dashboard → running instance: focus existing window @windows @macos @lin expect(await liveWindowCount(ctx.app)).toBe(before) }) -test('Dashboard → cloud via "Open in new window": starts it from this Desktop window, no second Desktop window @windows @macos @linux', async () => { +test('Dashboard → closed Cloud: Open Cloud starts it from this Desktop window, no second Desktop window @windows @macos @linux', async () => { const desktopWindowsBefore = await desktopWindowCount(ctx.app) - await openPicker(ctx.app, ctx.panel, 'pickInstall') + await openPicker(ctx.app, ctx.panel) const popup = titlePopupPage(ctx.app) - await popup.evaluate( - `window.__comfyTitlePopup.openInstallNewWindow(${JSON.stringify(CLOUD_ID)})` - ) + await popup.evaluate(`window.__comfyTitlePopup.pickInstall(${JSON.stringify(CLOUD_ID)})`) await expect .poll( async () => { - const calls = (await getIpcInvocations(ctx.app, 'open-install-new-window')) as { + const calls = (await getIpcInvocations(ctx.app, 'open-build')) as { installationId?: string - focusedExisting?: boolean + route?: string }[] - return calls.some((c) => c.installationId === CLOUD_ID && c.focusedExisting === false) + return calls.some((c) => c.installationId === CLOUD_ID && c.route === 'start-from') }, { timeout: 5_000, intervals: [100, 250] } ) diff --git a/e2e/nav-matrix-instance.test.ts b/e2e/nav-matrix-instance.test.ts index 9df3e80ca..f6d2663c9 100644 --- a/e2e/nav-matrix-instance.test.ts +++ b/e2e/nav-matrix-instance.test.ts @@ -73,27 +73,27 @@ test.beforeEach(async () => { await closeTitlePopupIfOpen(ctx.app) await resetIpcInvocations(ctx.app, 'focus-comfy-window') await resetIpcInvocations(ctx.app, 'run-action') - await resetIpcInvocations(ctx.app, 'open-install-new-window') + await resetIpcInvocations(ctx.app, 'open-build') await clearRunningSessions(ctx.app) }) -test('Instance B via "Open in new window": starts B from this Desktop window and opens no second Desktop window @windows @macos @linux', async () => { +test('Instance B (stopped): Start starts B from this Desktop window and opens no second Desktop window @windows @macos @linux', async () => { const desktopWindowsBefore = await desktopWindowCount(ctx.app) - await openPicker(ctx.app, ctx.panel, 'openInstallNewWindow') + await openPicker(ctx.app, ctx.panel) const popup = titlePopupPage(ctx.app) await popup.evaluate( - `window.__comfyTitlePopup.openInstallNewWindow(${JSON.stringify(INSTALL_B_ID)})` + `window.__comfyTitlePopup.pickInstall(${JSON.stringify(INSTALL_B_ID)})` ) await expect .poll( async () => { - const calls = (await getIpcInvocations(ctx.app, 'open-install-new-window')) as { + const calls = (await getIpcInvocations(ctx.app, 'open-build')) as { installationId?: string - focusedExisting?: boolean + route?: string }[] - return calls.some((c) => c.installationId === INSTALL_B_ID && c.focusedExisting === false) + return calls.some((c) => c.installationId === INSTALL_B_ID && c.route === 'start-from') }, { timeout: 5_000, intervals: [100, 250] } ) @@ -123,7 +123,7 @@ test('Instance B (running elsewhere): focus its existing window @windows @macos installationName: INSTALL_B_NAME }) const before = await liveWindowCount(ctx.app) - await openPicker(ctx.app, ctx.panel, 'openInstallNewWindow') + await openPicker(ctx.app, ctx.panel) const popup = titlePopupPage(ctx.app) await popup.evaluate( diff --git a/e2e/support/navMatrixHelpers.ts b/e2e/support/navMatrixHelpers.ts index 4d2226088..294526c5f 100644 --- a/e2e/support/navMatrixHelpers.ts +++ b/e2e/support/navMatrixHelpers.ts @@ -27,17 +27,13 @@ export async function desktopWindowCount(app: ElectronApplication): Promise { +export async function openPicker(app: ElectronApplication, panel: WebContentsPage): Promise { await panel.evaluate(`(() => { window.api.openInstancePicker({}); return true })()`) await waitForWebContents(app, 'comfyTitlePopup.html') const popup = titlePopupPage(app) await popup.waitFor( async () => - popup.evaluate(`typeof window.__comfyTitlePopup?.${bridgeFn} === "function"`), + popup.evaluate(`typeof window.__comfyTitlePopup?.pickInstall === "function"`), { timeout: 10_000, message: 'picker bridge never appeared' } ) } diff --git a/src/main/index.ts b/src/main/index.ts index 86aede12c..6281074df 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -1074,15 +1074,20 @@ if (app.isPackaged && !app.requestSingleInstanceLock()) { }) } - const openBuild = async ( - installationId: string, - requesterEntryId: number | undefined, - onRoute?: (route: BuildOpenRoute) => void - ): Promise => { - const requester = - requesterEntryId === undefined ? undefined : comfyWindows.get(requesterEntryId) + const recordBuildOpen = (installationId: string, route: BuildOpenRoute): void => { + recordIpcInvocation('open-build', { installationId, route: route.kind }) + if (route.kind === 'start-from' || route.kind === 'start-from-home') { + mainTelemetry.emit('comfy.desktop.instance.opened_new_window', { + to_installation_id: installationId, + method: 'picker' + }) + } + } + + const openBuild = async (installationId: string, requesterEntryId: number): Promise => { + const requester = comfyWindows.get(requesterEntryId) const route = routeBuildOpen(installationId, requester, _getLaunchingInstallationIds()) - onRoute?.(route) + recordBuildOpen(installationId, route) switch (route.kind) { case 'ignore': return @@ -1113,26 +1118,6 @@ if (app.isPackaged && !app.requestSingleInstanceLock()) { } } - const openInstallInNewWindow = ( - installationId: string, - requesterEntryId?: number - ): Promise => - openBuild(installationId, requesterEntryId, (route) => { - recordIpcInvocation('open-install-new-window', { - installationId, - focusedExisting: route.kind === 'focus' - }) - if (route.kind === 'start-from' || route.kind === 'start-from-home') { - mainTelemetry.emit('comfy.desktop.instance.opened_new_window', { - to_installation_id: installationId, - method: 'picker' - }) - } - }).catch((err) => console.error('openInstallInNewWindow failed:', err)) - - const pickInstallFromPicker = (installationId: string, parentEntryId: number): Promise => - openBuild(installationId, parentEntryId) - registerTitlePopupIpc({ openChooserHostWindow, returnToDashboard, @@ -1447,8 +1432,7 @@ if (app.isPackaged && !app.requestSingleInstanceLock()) { return { ok: false, message: err instanceof Error ? err.message : 'Action failed.' } } }, - pickInstallFromPicker, - openInstallInNewWindow, + pickInstallFromPicker: openBuild, restartInstallFromPicker: async (installationId, parentEntryId, opts) => { const parentEntry = comfyWindows.get(parentEntryId) if (!parentEntry || parentEntry.window.isDestroyed()) return diff --git a/src/main/popups/titlePopup.ts b/src/main/popups/titlePopup.ts index 2a5d834c7..8cb18f4d5 100644 --- a/src/main/popups/titlePopup.ts +++ b/src/main/popups/titlePopup.ts @@ -981,10 +981,6 @@ export interface TitlePopupHostBindings { getRunningSessionStartedAt?: () => Record getLaunchingInstallationIds: () => string[] pickInstallFromPicker: (installationId: string, parentEntryId: number) => Promise | void - openInstallInNewWindow: ( - installationId: string, - requesterEntryId?: number - ) => Promise | void restartInstallFromPicker: ( installationId: string, parentEntryId: number, @@ -1768,20 +1764,6 @@ export function registerTitlePopupIpc(bindings: TitlePopupHostBindings): void { ) }) - ipcMain.on( - 'comfy-titlepopup:open-install-new-window', - (event, payload: { installationId?: unknown }) => { - const entry = titlePopupsByWebContents.get(event.sender.id) - if (!entry || entry.kind !== POPUP_KIND.instancePicker) return - const installationId = payload?.installationId - if (typeof installationId !== 'string' || installationId.length === 0) return - hideTitlePopup(entry, { releaseFocusToParent: false }) - Promise.resolve(bindings.openInstallInNewWindow(installationId, entry.parentEntryId)).catch( - (err) => console.error('openInstallInNewWindow failed:', err) - ) - } - ) - ipcMain.on( 'comfy-titlepopup:restart-install', (event, payload: { installationId?: unknown; confirmed?: unknown }) => { diff --git a/src/preload/comfyTitlePopupPreload.ts b/src/preload/comfyTitlePopupPreload.ts index 710efd644..b0d9ce31b 100644 --- a/src/preload/comfyTitlePopupPreload.ts +++ b/src/preload/comfyTitlePopupPreload.ts @@ -158,7 +158,6 @@ export interface ComfyTitlePopupBridge { requestSize(height: number): void onInstancePickerSnapshot(cb: (snapshot: PopupInstancePickerSnapshot) => void): () => void pickInstall(installationId: string): void - openInstallNewWindow(installationId: string): void openNewInstall(): void restartInstall(installationId: string, opts?: { confirmed?: boolean }): void getDownloadThumbnail(savePath: string): Promise @@ -455,9 +454,6 @@ const bridge: ComfyTitlePopupBridge = { pickInstall: (installationId) => { ipcRenderer.send('comfy-titlepopup:pick-install', { installationId }) }, - openInstallNewWindow: (installationId) => { - ipcRenderer.send('comfy-titlepopup:open-install-new-window', { installationId }) - }, openNewInstall: () => { ipcRenderer.send('comfy-titlepopup:open-new-install') }, diff --git a/src/renderer/src/comfyTitlePopup/InstancePickerView.test.ts b/src/renderer/src/comfyTitlePopup/InstancePickerView.test.ts index 6a250724e..83da1b02f 100644 --- a/src/renderer/src/comfyTitlePopup/InstancePickerView.test.ts +++ b/src/renderer/src/comfyTitlePopup/InstancePickerView.test.ts @@ -71,7 +71,6 @@ interface MockSnapshot { interface BridgeState { picks: string[] - newWindows: string[] restarts: { id: string; opts?: { confirmed?: boolean } }[] backgroundOps: { installationId: string; actionId: string }[] newInstallCount: number @@ -83,7 +82,6 @@ interface BridgeState { function installMockBridge(): BridgeState { const state: BridgeState = { picks: [], - newWindows: [], restarts: [], backgroundOps: [], newInstallCount: 0, @@ -95,9 +93,6 @@ function installMockBridge(): BridgeState { pickInstall: (id: string) => { state.picks.push(id) }, - openInstallNewWindow: (id: string) => { - state.newWindows.push(id) - }, restartInstall: (id: string, opts?: { confirmed?: boolean }) => { state.restarts.push({ id, opts }) }, @@ -574,8 +569,7 @@ describe('comfyTitlePopup/InstancePickerView', () => { await primary.trigger('click') await flushPromises() expect(useDialogs().state.open).toBe(false) - expect(bridge.newWindows).toEqual(['b']) - expect(bridge.picks).toEqual([]) + expect(bridge.picks).toEqual(['b']) expect(bridge.restarts).toEqual([]) }) diff --git a/src/renderer/src/comfyTitlePopup/InstancePickerView.vue b/src/renderer/src/comfyTitlePopup/InstancePickerView.vue index 841cf39ad..be2f2a86b 100644 --- a/src/renderer/src/comfyTitlePopup/InstancePickerView.vue +++ b/src/renderer/src/comfyTitlePopup/InstancePickerView.vue @@ -130,7 +130,6 @@ interface PickerBridge { activate?: (id: string) => void close?: () => void pickInstall: (installationId: string) => void - openInstallNewWindow: (installationId: string) => void restartInstall: (installationId: string, opts?: { confirmed?: boolean }) => void setPickerSelectedInstall: (installationId: string | null) => void pickerUpdateField: ( diff --git a/src/renderer/src/composables/useInstanceActions.test.ts b/src/renderer/src/composables/useInstanceActions.test.ts index 6ab2300ef..4728e099c 100644 --- a/src/renderer/src/composables/useInstanceActions.test.ts +++ b/src/renderer/src/composables/useInstanceActions.test.ts @@ -7,7 +7,6 @@ function makeBridge() { return { pickInstall: vi.fn(), restartInstall: vi.fn(), - openInstallNewWindow: vi.fn(), openNewInstall: vi.fn() } satisfies InstanceActionsBridge } @@ -42,7 +41,6 @@ describe('useInstanceActions.dispatch', () => { await useInstanceActions(deps).dispatch(decision({ verb: 'start' }), installation()) expect(bridge.pickInstall).toHaveBeenCalledExactlyOnceWith('a') expect(deps.confirmLocalKill).not.toHaveBeenCalled() - expect(bridge.openInstallNewWindow).not.toHaveBeenCalled() }) it('routes restart → restartInstall(confirmed:true) after a confirm', async () => { @@ -60,14 +58,13 @@ describe('useInstanceActions.dispatch', () => { expect(bridge.restartInstall).not.toHaveBeenCalled() }) - it('routes open-new → openInstallNewWindow', async () => { + it('routes open-new → pickInstall, the one channel main routes every build pick through', async () => { const bridge = makeBridge() await useInstanceActions(makeDeps(bridge)).dispatch( decision({ verb: 'open-new' }), installation() ) - expect(bridge.openInstallNewWindow).toHaveBeenCalledExactlyOnceWith('a') - expect(bridge.pickInstall).not.toHaveBeenCalled() + expect(bridge.pickInstall).toHaveBeenCalledExactlyOnceWith('a') }) it('routes focus → pickInstall (main short-circuits to focus when already up)', async () => { @@ -90,7 +87,6 @@ describe('useInstanceActions.dispatch', () => { await useInstanceActions(makeDeps(bridge)).dispatch(decision({ verb: 'no-op' }), installation()) expect(bridge.pickInstall).not.toHaveBeenCalled() expect(bridge.restartInstall).not.toHaveBeenCalled() - expect(bridge.openInstallNewWindow).not.toHaveBeenCalled() }) it('no-ops when the bridge is undefined', async () => { diff --git a/src/renderer/src/composables/useInstanceActions.ts b/src/renderer/src/composables/useInstanceActions.ts index 76c736d18..7cb345049 100644 --- a/src/renderer/src/composables/useInstanceActions.ts +++ b/src/renderer/src/composables/useInstanceActions.ts @@ -4,7 +4,6 @@ import type { Installation } from '../types/ipc' export interface InstanceActionsBridge { pickInstall: (installationId: string) => void restartInstall: (installationId: string, opts?: { confirmed?: boolean }) => void - openInstallNewWindow?: (installationId: string) => void openNewInstall?: () => void } @@ -30,12 +29,9 @@ export function useInstanceActions(deps: InstanceActionsDeps): InstanceActions { return } case 'start': - case 'focus': { - bridge.pickInstall(target.id) - return - } + case 'focus': case 'open-new': { - bridge.openInstallNewWindow?.(target.id) + bridge.pickInstall(target.id) return } case 'install-wizard': { diff --git a/src/renderer/src/composables/useInstanceNavState.test.ts b/src/renderer/src/composables/useInstanceNavState.test.ts index dd18cbbaf..0d1c347b4 100644 --- a/src/renderer/src/composables/useInstanceNavState.test.ts +++ b/src/renderer/src/composables/useInstanceNavState.test.ts @@ -164,7 +164,7 @@ describe('useInstanceNavState → decideNavigation (end to end)', () => { activeInstallationId: 'A' }) const decision = decideNavigation(navState.navInput()) - expect(decision).toEqual({ verb: 'open-new', primaryLabel: NAV_LABEL.start }) + expect(decision).toEqual({ verb: 'start', primaryLabel: NAV_LABEL.start }) }) it('dashboard host picking a stopped cloud install → Open Cloud', () => { @@ -186,7 +186,7 @@ describe('useInstanceNavState → decideNavigation (end to end)', () => { activeInstallationId: 'cloud' }) const decision = decideNavigation(navState.navInput()) - expect(decision).toEqual({ verb: 'open-new', primaryLabel: NAV_LABEL.start }) + expect(decision).toEqual({ verb: 'start', primaryLabel: NAV_LABEL.start }) }) it('cloud host picking a stopped REMOTE connection → opens in a new window (not a dead no-op)', () => { @@ -196,7 +196,7 @@ describe('useInstanceNavState → decideNavigation (end to end)', () => { activeInstallationId: 'cloud' }) const decision = decideNavigation(navState.navInput()) - expect(decision).toEqual({ verb: 'open-new', primaryLabel: NAV_LABEL.openCloud }) + expect(decision).toEqual({ verb: 'start', primaryLabel: NAV_LABEL.openCloud }) }) it('instance host → stopped REMOTE routes identically to stopped Cloud (no in-place 3-way)', () => { @@ -211,7 +211,7 @@ describe('useInstanceNavState → decideNavigation (end to end)', () => { const cloud = decideNavigation( useInstanceNavState(ref(installation('C', 'cloud')), sources).navInput() ) - expect(remote).toEqual({ verb: 'open-new', primaryLabel: NAV_LABEL.openCloud }) + expect(remote).toEqual({ verb: 'start', primaryLabel: NAV_LABEL.openCloud }) expect(remote).toEqual(cloud) }) }) diff --git a/src/shared/navigation/navDecision.test.ts b/src/shared/navigation/navDecision.test.ts index 8e84e1359..004f8afea 100644 --- a/src/shared/navigation/navDecision.test.ts +++ b/src/shared/navigation/navDecision.test.ts @@ -34,16 +34,12 @@ describe('decideNavigation — totality', () => { } }) - it('never puts a different build into a build or Cloud window', () => { - for (const currentView of ['instance', 'cloud'] as const) - for (const target of ['instance', 'cloud'] as const) - for (const targetRun of RUNS) { - if (targetRun === 'self') continue - const d = decideNavigation(input({ currentView, target, targetRun })) - expect(['open-new', 'focus'], `${currentView} → ${target} (${targetRun})`).toContain( - d.verb - ) - } + it('asks main to start a stopped build the same way from every window, since main picks the window', () => { + for (const currentView of VIEWS) + for (const target of ['instance', 'cloud'] as const) { + const d = decideNavigation(input({ currentView, target, targetRun: 'stopped' })) + expect(d.verb, `${currentView} → ${target} (stopped)`).toBe('start') + } }) it('never produces a dead no-op CTA for a reachable (host, install-target, run) combo', () => { @@ -124,13 +120,13 @@ describe('decideNavigation — every build opens in its own window', () => { it('build window → stopped build B: Start opens B in its own window', () => { expect(decisionFor('instance', 'instance', 'stopped')).toEqual({ - verb: 'open-new', + verb: 'start', primaryLabel: NAV_LABEL.start }) }) it('build window → closed Cloud: Open Cloud in its own window', () => { expect(decisionFor('instance', 'cloud', 'stopped')).toEqual({ - verb: 'open-new', + verb: 'start', primaryLabel: NAV_LABEL.openCloud }) }) @@ -153,13 +149,13 @@ describe('decideNavigation — every build opens in its own window', () => { it('Cloud window → stopped build: Start opens it in its own window', () => { expect(decisionFor('cloud', 'instance', 'stopped')).toEqual({ - verb: 'open-new', + verb: 'start', primaryLabel: NAV_LABEL.start }) }) it('Cloud window → another closed Cloud or remote build: Open Cloud in its own window', () => { expect(decisionFor('cloud', 'cloud', 'stopped')).toEqual({ - verb: 'open-new', + verb: 'start', primaryLabel: NAV_LABEL.openCloud }) }) diff --git a/src/shared/navigation/navDecision.ts b/src/shared/navigation/navDecision.ts index d804734e5..84db3853f 100644 --- a/src/shared/navigation/navDecision.ts +++ b/src/shared/navigation/navDecision.ts @@ -47,17 +47,17 @@ const TABLE: ReadonlyMap = new Map([ [cellKey('instance', 'dashboard', 'self'), dec('open-new', NAV_LABEL.openDashboard)], [cellKey('instance', 'instance', 'self'), dec('restart', NAV_LABEL.restart)], - [cellKey('instance', 'instance', 'stopped'), dec('open-new', NAV_LABEL.start)], + [cellKey('instance', 'instance', 'stopped'), dec('start', NAV_LABEL.start)], [cellKey('instance', 'instance', 'running-elsewhere'), dec('focus', NAV_LABEL.switch)], - [cellKey('instance', 'cloud', 'stopped'), dec('open-new', NAV_LABEL.openCloud)], + [cellKey('instance', 'cloud', 'stopped'), dec('start', NAV_LABEL.openCloud)], [cellKey('instance', 'cloud', 'running-elsewhere'), dec('focus', NAV_LABEL.switch)], [cellKey('cloud', 'dashboard', 'self'), dec('open-new', NAV_LABEL.openDashboard)], - [cellKey('cloud', 'instance', 'stopped'), dec('open-new', NAV_LABEL.start)], + [cellKey('cloud', 'instance', 'stopped'), dec('start', NAV_LABEL.start)], [cellKey('cloud', 'instance', 'running-elsewhere'), dec('focus', NAV_LABEL.switch)], [cellKey('cloud', 'cloud', 'self'), dec('restart', NAV_LABEL.restart)], [cellKey('cloud', 'cloud', 'running-elsewhere'), dec('focus', NAV_LABEL.switch)], - [cellKey('cloud', 'cloud', 'stopped'), dec('open-new', NAV_LABEL.openCloud)], + [cellKey('cloud', 'cloud', 'stopped'), dec('start', NAV_LABEL.openCloud)], [cellKey('cloud', 'new-instance', 'stopped'), dec('install-wizard', NAV_LABEL.newInstall)] ])