diff --git a/e2e/update-pills.test.ts b/e2e/update-pills.test.ts index 316d71df6..e8441c194 100644 --- a/e2e/update-pills.test.ts +++ b/e2e/update-pills.test.ts @@ -1,8 +1,7 @@ -import { test, expect, type ElectronApplication } from '@playwright/test' +import { test, expect } from '@playwright/test' import { launchApp, type AppContext } from './launchApp' -import { findWebContentsId } from './support/cdpPages' -import { evalWithRetry } from './support/evalRetry' import { setAppUpdateState, setInstallUpdate, type AppUpdateStateLike } from './support/devHooks' +import { byTestId, TID } from './support/testIds' let ctx: AppContext @@ -17,115 +16,77 @@ test.afterAll(async () => { }) test.beforeEach(async () => { - await closeSystemModalIfOpen(ctx.app) + await closePanelModalIfOpen() await setAppUpdateState(ctx.app, IDLE_APP_UPDATE) await setInstallUpdate(ctx.app, { available: false }) }) const IDLE_APP_UPDATE: AppUpdateStateLike = { kind: null, version: null, autoUpdate: true } +const SIDEBAR_UPDATE = '[data-testid="app-sidebar-desktop-update"]' -test('desktop-update pill is hidden when state is idle @windows @macos @linux', async () => { - expect(await ctx.titleBar.exists('.title-update-pill.is-app-update')).toBe(false) +function sidebarUpdateIn(kind: NonNullable): string { + return `${SIDEBAR_UPDATE}[data-state="${kind}"]` +} + +async function expectSidebarUpdate(kind: NonNullable): Promise { + await ctx.panel.waitForVisible(sidebarUpdateIn(kind), { timeout: 5_000 }) +} + +async function closePanelModalIfOpen(): Promise { + if (!(await ctx.panel.isVisible(byTestId(TID.modalCancel)))) return + expect(await ctx.panel.click(byTestId(TID.modalCancel))).toBe(true) + await ctx.panel.waitFor(async () => !(await ctx.panel.isVisible(byTestId(TID.modalConfirm))), { + timeout: 3_000, + message: 'panel confirm modal did not close' + }) +} + +test('desktop update is hidden in the sidebar and the title bar when state is idle @windows @macos @linux', async () => { + await ctx.panel.waitFor(async () => !(await ctx.panel.exists(SIDEBAR_UPDATE)), { + timeout: 5_000, + message: 'sidebar desktop update stayed visible while idle' + }) + expect(await ctx.titleBar.exists('.title-update-pill')).toBe(false) }) -test('desktop-update pill renders for state=available @windows @macos @linux', async () => { +test('desktop update shows in the sidebar for state=available @windows @macos @linux', async () => { await setAppUpdateState(ctx.app, { kind: 'available', version: '1.2.3', autoUpdate: false }) - await expect - .poll(() => ctx.titleBar.exists('.title-update-pill.is-app-update'), { - timeout: 5_000, - intervals: [100, 200] - }) - .toBe(true) - const label = await ctx.titleBar.textOf( - '.title-update-pill.is-app-update .title-update-pill-label' - ) - expect(label?.toLowerCase()).toContain('update') - expect(await ctx.titleBar.exists('.title-update-pill.is-app-update.is-ready')).toBe(false) - expect(await ctx.titleBar.exists('.title-update-pill.is-app-update.is-downloading')).toBe(false) + await expectSidebarUpdate('available') + expect(await ctx.titleBar.exists('.title-update-pill')).toBe(false) }) -test('desktop-update pill renders for state=downloading @windows @macos @linux', async () => { +test('desktop update shows in the sidebar for state=downloading @windows @macos @linux', async () => { await setAppUpdateState(ctx.app, { kind: 'downloading', version: '1.2.3', autoUpdate: true }) - await expect - .poll(() => ctx.titleBar.exists('.title-update-pill.is-app-update.is-downloading'), { - timeout: 5_000, - intervals: [100, 200] - }) - .toBe(true) + await expectSidebarUpdate('downloading') }) -test('desktop-update pill renders for state=ready @windows @macos @linux', async () => { +test('desktop update shows in the sidebar for state=ready @windows @macos @linux', async () => { await setAppUpdateState(ctx.app, { kind: 'ready', version: '1.2.3', autoUpdate: true }) - await expect - .poll(() => ctx.titleBar.exists('.title-update-pill.is-app-update.is-ready'), { - timeout: 5_000, - intervals: [100, 200] - }) - .toBe(true) + await expectSidebarUpdate('ready') }) -test('clicking the ready desktop-update pill opens the embedded system-modal restart prompt @windows @macos @linux', async () => { - await setAppUpdateState(ctx.app, { kind: 'ready', version: '1.2.3', autoUpdate: true }) - await expect - .poll(() => ctx.titleBar.exists('.title-update-pill.is-app-update.is-ready'), { - timeout: 5_000, - intervals: [100, 200] - }) - .toBe(true) - - const ok = await ctx.titleBar.click('.title-update-pill.is-app-update') - expect(ok, 'desktop-update pill click dispatched').toBe(true) - - await expect - .poll(() => isSystemModalVisible(ctx.app), { - timeout: 5_000, - intervals: [100, 200] - }) - .toBe(true) +test('clicking the available sidebar desktop update asks to download in the panel @windows @macos @linux', async () => { + await setAppUpdateState(ctx.app, { kind: 'available', version: '1.2.3', autoUpdate: false }) + await expectSidebarUpdate('available') + + expect(await ctx.panel.click(SIDEBAR_UPDATE), 'sidebar desktop update click dispatched').toBe( + true + ) + + await ctx.panel.waitForVisible(byTestId(TID.modalConfirm), { timeout: 5_000 }) + expect(await ctx.panel.textOf(byTestId(TID.modalConfirm))).toContain('Download') + await closePanelModalIfOpen() }) -async function isSystemModalVisible(app: ElectronApplication): Promise { - try { - return await evalWithRetry(() => - app.evaluate(({ BrowserWindow, WebContentsView }) => { - for (const win of BrowserWindow.getAllWindows()) { - for (const child of win.contentView.children) { - if (!(child instanceof WebContentsView)) continue - if (!child.webContents.getURL().includes('comfySystemModal.html')) continue - if (!child.getVisible()) return false - const b = child.getBounds() - return b.width > 0 && b.height > 0 - } - } - return false - }) - ) - } catch { - return false - } -} +test('clicking the ready sidebar desktop update asks to restart in the panel @windows @macos @linux', async () => { + await setAppUpdateState(ctx.app, { kind: 'ready', version: '1.2.3', autoUpdate: true }) + await expectSidebarUpdate('ready') -async function closeSystemModalIfOpen(app: ElectronApplication): Promise { - const id = await findWebContentsId(app, 'comfySystemModal.html') - if (id === null) return - if (!(await isSystemModalVisible(app))) return - await evalWithRetry(() => - app.evaluate(({ webContents }) => { - const wc = webContents - .getAllWebContents() - .find((w) => w.getURL().includes('comfySystemModal.html')) - if (!wc) return - return wc - .executeJavaScript( - `(() => { - const ev = new KeyboardEvent('keydown', { key: 'Escape', bubbles: true, cancelable: true }) - document.dispatchEvent(ev) - })()` - ) - .catch(() => {}) - }) + expect(await ctx.panel.click(SIDEBAR_UPDATE), 'sidebar desktop update click dispatched').toBe( + true ) - await expect - .poll(() => isSystemModalVisible(app), { timeout: 3_000, intervals: [100, 200] }) - .toBe(false) -} + + await ctx.panel.waitForVisible(byTestId(TID.modalConfirm), { timeout: 5_000 }) + expect(await ctx.panel.textOf(byTestId(TID.modalConfirm))).toContain('Restart & Update') + await closePanelModalIfOpen() +}) diff --git a/src/renderer/src/comfyTitleBar/TitleBarApp.test.ts b/src/renderer/src/comfyTitleBar/TitleBarApp.test.ts index 077eba072..5c63b9d00 100644 --- a/src/renderer/src/comfyTitleBar/TitleBarApp.test.ts +++ b/src/renderer/src/comfyTitleBar/TitleBarApp.test.ts @@ -628,86 +628,12 @@ describe('TitleBarApp', () => { expect(bridgeState.refreshInstanceClicks).toBe(1) }) - it('hides both status pills by default (no update available, no install update)', async () => { + it('leaves the Desktop update to the sidebar and shows no update pill in the title bar', async () => { const { default: TitleBarApp } = await import('./TitleBarApp.vue') const wrapper = mount(TitleBarApp) await flushPromises() - expect(wrapper.find('.title-update-pill.is-app-update').exists()).toBe(false) - expect(wrapper.find('.title-update-pill.is-install-update').exists()).toBe(false) - }) - - it('renders the app-update pill with "Desktop Update" copy when state.kind=available (auto-updates OFF)', async () => { - const { default: TitleBarApp } = await import('./TitleBarApp.vue') - const wrapper = mount(TitleBarApp) - await flushPromises() - bridgeState.appUpdateStateCallbacks.forEach((cb) => - cb({ kind: 'available', version: '2.3.4', autoUpdate: false }) - ) - await flushPromises() - const pill = wrapper.find('.title-update-pill.is-app-update') - expect(pill.exists()).toBe(true) - expect(pill.classes()).not.toContain('is-ready') - expect(pill.text()).toContain('Desktop Update') - expect(pill.attributes('title')).toBe('Desktop Update (v2.3.4)') - expect(pill.attributes('aria-label')).toBe('Desktop Update (v2.3.4)') - }) - - it('renders the app-update pill with "Desktop Update Ready" copy when state.kind=ready (auto-updates OFF)', async () => { - const { default: TitleBarApp } = await import('./TitleBarApp.vue') - const wrapper = mount(TitleBarApp) - await flushPromises() - bridgeState.appUpdateStateCallbacks.forEach((cb) => - cb({ kind: 'ready', version: '2.3.4', autoUpdate: false }) - ) - await flushPromises() - const pill = wrapper.find('.title-update-pill.is-app-update') - expect(pill.exists()).toBe(true) - expect(pill.classes()).toContain('is-ready') - expect(pill.text()).toContain('Desktop Update Ready') - expect(pill.attributes('title')).toBe('Desktop Update Ready (v2.3.4)') - }) - - it('renders the app-update pill with "Desktop Update Ready" copy when state.kind=ready (auto-updates ON)', async () => { - const { default: TitleBarApp } = await import('./TitleBarApp.vue') - const wrapper = mount(TitleBarApp) - await flushPromises() - bridgeState.appUpdateStateCallbacks.forEach((cb) => - cb({ kind: 'ready', version: '2.3.4', autoUpdate: true }) - ) - await flushPromises() - const pill = wrapper.find('.title-update-pill.is-app-update') - expect(pill.exists()).toBe(true) - expect(pill.classes()).toContain('is-ready') - expect(pill.text()).toContain('Desktop Update Ready') - }) - - it('forwards app-update pill clicks through the bridge', async () => { - const { default: TitleBarApp } = await import('./TitleBarApp.vue') - const wrapper = mount(TitleBarApp, { attachTo: document.body }) - await flushPromises() - bridgeState.appUpdateStateCallbacks.forEach((cb) => - cb({ kind: 'available', version: '1.0.0', autoUpdate: false }) - ) - await flushPromises() - await wrapper.find('.title-update-pill.is-app-update').trigger('click') - expect(bridgeState.appUpdatePillClicks).toBe(1) - wrapper.unmount() - }) - - it('hides the app-update pill when state transitions back to kind=null', async () => { - const { default: TitleBarApp } = await import('./TitleBarApp.vue') - const wrapper = mount(TitleBarApp) - await flushPromises() - bridgeState.appUpdateStateCallbacks.forEach((cb) => - cb({ kind: 'ready', version: '2.0.0', autoUpdate: false }) - ) - await flushPromises() - expect(wrapper.find('.title-update-pill.is-app-update').exists()).toBe(true) - bridgeState.appUpdateStateCallbacks.forEach((cb) => - cb({ kind: null, version: null, autoUpdate: true }) - ) - await flushPromises() - expect(wrapper.find('.title-update-pill.is-app-update').exists()).toBe(false) + expect(bridgeState.appUpdateStateCallbacks).toHaveLength(0) + expect(wrapper.find('.title-update-pill').exists()).toBe(false) }) it('renders the downloads tray with no badge in the empty steady state', async () => { @@ -1077,96 +1003,6 @@ describe('TitleBarApp', () => { } }) - describe('fitting the right side next to Home', () => { - const rect = (left: number, width: number): DOMRect => - ({ - left, - right: left + width, - width, - top: 0, - bottom: 32, - height: 32, - x: left, - y: 0 - }) as DOMRect - - let resizeCallbacks: ResizeObserverCallback[] = [] - - beforeEach(() => { - resizeCallbacks = [] - vi.stubGlobal( - 'ResizeObserver', - class { - constructor(cb: ResizeObserverCallback) { - resizeCallbacks.push(cb) - } - observe(): void {} - unobserve(): void {} - disconnect(): void {} - } - ) - }) - - afterEach(() => { - vi.unstubAllGlobals() - vi.restoreAllMocks() - }) - - async function mountWithTrailingAt(trailingLeft: number) { - vi.spyOn(Element.prototype, 'getBoundingClientRect').mockImplementation(function ( - this: Element - ) { - if (this.matches('header')) return rect(0, 800) - if (this.closest('.title-trailing')) return rect(trailingLeft, 788 - trailingLeft) - return rect(12, 88) - }) - const { default: TitleBarApp } = await import('./TitleBarApp.vue') - const wrapper = mount(TitleBarApp, { attachTo: document.body }) - const header = wrapper.find('header').element as HTMLElement - header.style.columnGap = '12px' - await flushPromises() - resizeCallbacks.forEach((cb) => cb([], {} as ResizeObserver)) - await new Promise((resolve) => requestAnimationFrame(resolve)) - await flushPromises() - return wrapper - } - - it('collapses once only the two grid gutters are left between Home and the right side', async () => { - const wrapper = await mountWithTrailingAt(124) - expect(wrapper.find('header').classes()).toContain('is-collapsed-feedback') - wrapper.unmount() - }) - - it('stays expanded while the empty middle still has room', async () => { - const wrapper = await mountWithTrailingAt(200) - expect(wrapper.find('header').classes()).not.toContain('is-collapsed-feedback') - wrapper.unmount() - }) - }) - - describe('without ResizeObserver', () => { - let originalResizeObserver: typeof globalThis.ResizeObserver | undefined - - beforeEach(() => { - originalResizeObserver = (globalThis as { ResizeObserver?: typeof globalThis.ResizeObserver }) - .ResizeObserver - delete (globalThis as { ResizeObserver?: typeof globalThis.ResizeObserver }).ResizeObserver - }) - - afterEach(() => { - ;(globalThis as { ResizeObserver?: typeof globalThis.ResizeObserver }).ResizeObserver = - originalResizeObserver - }) - - it('still mounts and renders the title bar', async () => { - const mod = await import('./TitleBarApp.vue') - const wrapper = mount(mod.default, { attachTo: document.body }) - await flushPromises() - expect(wrapper.find('.title-trailing').exists()).toBe(true) - wrapper.unmount() - }) - }) - describe('core beta activation notice', () => { let getPendingBetaNotice: ReturnType let acknowledgeBetaNotice: ReturnType diff --git a/src/renderer/src/comfyTitleBar/TitleBarApp.vue b/src/renderer/src/comfyTitleBar/TitleBarApp.vue index 53bb13fcd..21601cb16 100644 --- a/src/renderer/src/comfyTitleBar/TitleBarApp.vue +++ b/src/renderer/src/comfyTitleBar/TitleBarApp.vue @@ -4,25 +4,21 @@ import { useI18n } from 'vue-i18n' import { ArrowDownToLine, Bell, - CloudDownload, House, - Loader2, Menu as MenuIcon, MessageSquarePlus, - RefreshCw, RotateCw, ZoomIn } from '@lucide/vue' import { useTitleBarTooltip } from './useTitleBarTooltip' import { useTitleBarMenus } from './useTitleBarMenus' import { useTitleBarIdentity } from './useTitleBarIdentity' -import { useUpdatePills } from './useUpdatePills' import { useTitleBarHoverGate } from './useTitleBarHoverGate' import { useBetaActivationNotice } from './useBetaActivationNotice' import { useAppLocale, windowApiLocaleSource } from '../lib/useAppLocale' import ComfyCLogo from '../components/icons/ComfyCLogo.vue' -const { t, locale } = useI18n() +const { t } = useI18n() const { syncLocale } = useAppLocale(windowApiLocaleSource()) type ComfyPanelKey = @@ -172,14 +168,6 @@ const showZoomReset = computed( () => zoomLevel.value !== 0 && !isInstallLess.value && !isFirstUseLockdown.value ) -const { - appUpdateState, - appUpdatePillLabel, - appUpdatePillTooltip, - showAppUpdatePill, - handleAppUpdatePill -} = useUpdatePills({ bridge, isInstallLess }) - function handleFeedback(): void { bridge?.clickFeedback() } @@ -224,106 +212,12 @@ onUnmounted(() => { unsubAnnouncementSettings?.() }) -const titleBarRef = useTemplateRef('titleBar') const fileBtnRef = useTemplateRef('fileBtn') const downloadsBtnRef = useTemplateRef('downloadsBtn') const announcementBtnRef = useTemplateRef('announcementBtn') -const titleClusterRef = useTemplateRef('titleCluster') -const titleTrailingRef = useTemplateRef('titleTrailing') -type CollapseMode = 'full' | 'no-feedback' | 'icons-only' -const collapseMode = ref('full') -const collapsedFeedback = computed( - () => collapseMode.value === 'no-feedback' || collapseMode.value === 'icons-only' -) -const collapsedUpdate = computed(() => collapseMode.value === 'icons-only') - -const MIN_GAP_PX = 16 -const RESTORE_BUFFER_PX = 24 -let feedbackRestoreCostPx = 0 -let updateRestoreCostPx = 0 -let fitObserver: ResizeObserver | undefined -let fitRaf: number | null = null -let transitionRaf: number | null = null let unmounted = false -interface FitMeasurement { - gap: number - trailingWidth: number -} - -function measureFit(): FitMeasurement { - const bar = titleBarRef.value - const trailing = titleTrailingRef.value - const cluster = titleClusterRef.value - if (!bar || !trailing || !cluster) return { gap: Infinity, trailingWidth: NaN } - const barRect = bar.getBoundingClientRect() - if (barRect.width === 0) return { gap: Infinity, trailingWidth: NaN } - const trailingRect = trailing.getBoundingClientRect() - const leadingRight = Math.max( - cluster.getBoundingClientRect().left, - ...Array.from(cluster.children).map((child) => child.getBoundingClientRect().right) - ) - const guttersAroundMiddle = 2 * (Number.parseFloat(getComputedStyle(bar).columnGap) || 0) - return { - gap: trailingRect.left - leadingRight - guttersAroundMiddle, - trailingWidth: trailingRect.width - } -} - -function scheduleFit(): void { - if (unmounted || fitRaf !== null) return - fitRaf = requestAnimationFrame(() => { - fitRaf = null - if (unmounted) return - evaluateFit() - }) -} - -function evaluateFit(): void { - const { gap } = measureFit() - if (!Number.isFinite(gap)) return - const mode = collapseMode.value - if (mode === 'full') { - if (gap < MIN_GAP_PX) transitionTo('no-feedback') - } else if (mode === 'no-feedback') { - if (gap < MIN_GAP_PX) transitionTo('icons-only') - else if (gap > feedbackRestoreCostPx + RESTORE_BUFFER_PX) transitionTo('full') - } else { - if (gap > updateRestoreCostPx + RESTORE_BUFFER_PX) transitionTo('no-feedback') - } -} - -function transitionTo(next: CollapseMode): void { - const prev = collapseMode.value - if (prev === next) return - const before = measureFit() - collapseMode.value = next - void nextTick().then(() => { - if (unmounted) return - transitionRaf = requestAnimationFrame(() => { - transitionRaf = null - if (unmounted) return - const after = measureFit() - if (Number.isFinite(before.trailingWidth) && Number.isFinite(after.trailingWidth)) { - const delta = before.trailingWidth - after.trailingWidth - if (prev === 'full' && next === 'no-feedback') { - feedbackRestoreCostPx = Math.max(feedbackRestoreCostPx, delta) - } else if (prev === 'no-feedback' && next === 'icons-only') { - updateRestoreCostPx = Math.max(updateRestoreCostPx, delta) - } - } - scheduleFit() - }) - }) -} - -function invalidateRestoreCosts(): void { - feedbackRestoreCostPx = 0 - updateRestoreCostPx = 0 - scheduleFit() -} - const { tooltipAttrs, handleTooltipPointer, hideTip } = useTitleBarTooltip({ bridge, isMac @@ -402,12 +296,6 @@ let unsubCoachmarkSettled: (() => void) | undefined let unsubCoachmarkDisplaced: (() => void) | undefined onMounted(() => { - if (titleBarRef.value && typeof ResizeObserver !== 'undefined') { - fitObserver = new ResizeObserver(() => scheduleFit()) - fitObserver.observe(titleBarRef.value) - } - evaluateFit() - syncLocale().catch((err) => { console.error('TitleBar: syncLocale failed', err) }) @@ -465,10 +353,6 @@ watch( { immediate: true } ) -watch([locale, installLabel, appUpdatePillLabel, showAppUpdatePill, isFirstUseLockdown], () => - invalidateRestoreCosts() -) - onUnmounted(() => { unmounted = true unsubPanel?.() @@ -481,16 +365,6 @@ onUnmounted(() => { unsubCoachmarkDisplaced?.() bridge?.hideCoachmark() hideTip() - fitObserver?.disconnect() - fitObserver = undefined - if (fitRaf !== null) { - cancelAnimationFrame(fitRaf) - fitRaf = null - } - if (transitionRaf !== null) { - cancelAnimationFrame(transitionRaf) - transitionRaf = null - } if (flashTimer) { clearTimeout(flashTimer) flashTimer = null @@ -500,7 +374,6 @@ onUnmounted(() => {