Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@
"appUpdateReady": "Restart to update",
"installUpdateAvailable": "Update available",
"installUpdateShort": "Update",
"home": "Home",
"menu": "Menu",
"feedback": "Feedback",
"feedbackTooltip": "Send Feedback",
Expand Down
1 change: 1 addition & 0 deletions locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@
"appUpdateReady": "重启以更新",
"installUpdateAvailable": "有可用更新",
"installUpdateShort": "更新",
"home": "主页",
"menu": "菜单",
"feedback": "反馈",
"feedbackTooltip": "发送反馈",
Expand Down
68 changes: 68 additions & 0 deletions src/main/host/registry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
indexInstallationId,
nextWindowKey,
forceRevealHostWindow,
openOrFocusHomeHostWindow,
hasRunningSessionForEntry,
raiseAllHostWindows,
registerHostEntry,
Expand Down Expand Up @@ -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<typeof vi.fn> {
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)
})
})
22 changes: 22 additions & 0 deletions src/main/host/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
8 changes: 8 additions & 0 deletions src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ import {
isInstallHost,
openOrFocusAnyHostWindow,
openOrFocusChooserHostWindow,
openOrFocusHomeHostWindow,
raiseAllHostWindows,
setHostFactories,
shouldConfirmKillForEntry
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/preload/comfyTitleBarPreload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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')
},
Expand Down
108 changes: 103 additions & 5 deletions src/renderer/src/comfyTitleBar/TitleBarApp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -98,6 +99,7 @@ function installMockBridge(
installPillClicks: [],
feedbackClicks: 0,
refreshInstanceClicks: 0,
homeClicks: 0,
resetZoomClicks: 0,
showTooltipCalls: [],
hideTooltipCalls: 0,
Expand Down Expand Up @@ -209,6 +211,9 @@ function installMockBridge(
clickRefreshInstance: () => {
state.refreshInstanceClicks += 1
},
clickHome: () => {
state.homeClicks += 1
},
resetZoom: () => {
state.resetZoomClicks += 1
},
Expand Down Expand Up @@ -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)
Expand All @@ -419,37 +424,130 @@ 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)

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)

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)

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)
Expand Down
Loading
Loading