Repository navigation
feat(apps): show the apps as Desktop cards from the Comfy content catalog #1997
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
3b176a2
8773296
52a8a2c
46d7abb
6db6c72
f07cd5b
33a8ca6
853b8ce
95b7eb0
e379e0b
3f3f3bf
c86e60a
97fe656
ec8c10f
e32be9d
6dea18c
cc31494
5cd8e40
18dd764
f6c685c
55db0f6
132e825
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ import { | |
| cloudPromptBody, | ||
| collectOutputs, | ||
| isAppOpen, | ||
| isAppPage, | ||
| isAllowedAppsPermission, | ||
| isAppsFrameUrl, | ||
| isDocumentFailure, | ||
|
|
@@ -53,6 +54,7 @@ import { | |
| startLocal, | ||
| syncLocalSocket | ||
| } from './localComfy' | ||
| import { listCatalogApps } from './catalog' | ||
| import { localBuilds, openInComfy } from './openInComfy' | ||
| import { isAppsEnabled, onAppsEnabledChanged } from './appsSwitch' | ||
| import { | ||
|
|
@@ -75,16 +77,22 @@ const failedViews = new WeakSet<WebContentsView>() | |
|
|
||
| export const APPS_LOAD_FAILED_CHANNEL = 'comfy-apps:load-failed' | ||
| export const APPS_APP_OPEN_CHANNEL = 'comfy-apps:app-open' | ||
| export const APPS_SETTLED_CHANNEL = 'comfy-apps:settled' | ||
| export const APPS_PAGE_SETTLED_CHANNEL = 'comfy-apps:page-settled' | ||
| export const APPS_CATALOG_CHANNEL = 'comfy-apps:catalog' | ||
| export const APPS_ENABLED_CHANNEL = 'comfy-apps:enabled' | ||
|
|
||
| const appOpen = new Map<number, boolean>() | ||
| const awaitingCommit = new Set<number>() | ||
| const settledPages = new Set<number>() | ||
|
|
||
| export interface AppsRect { | ||
| x: number | ||
| y: number | ||
| width: number | ||
| height: number | ||
| fresh?: boolean | ||
| url?: string | ||
| } | ||
|
|
||
| export type AppsAuthState = { signedIn: false } | { signedIn: true; email?: string } | ||
|
|
@@ -112,6 +120,11 @@ function tellPanelAppOpen(key: number): void { | |
| panel.send(APPS_APP_OPEN_CHANNEL, { open: appOpen.get(key) === true }) | ||
| } | ||
|
|
||
| function tellPanelSettled(key: number): void { | ||
| const panel = comfyWindows.get(key)?.panelView?.webContents | ||
| if (panel && !panel.isDestroyed()) panel.send(APPS_SETTLED_CHANNEL) | ||
| } | ||
|
|
||
| function trackAppOpen(key: number, url: string): void { | ||
| appOpen.set(key, isAppOpen(url, APPS_URL)) | ||
| tellPanelAppOpen(key) | ||
|
|
@@ -143,7 +156,7 @@ function keepInApps(event: { preventDefault(): void }, url: string): void { | |
| openOutside(url) | ||
| } | ||
|
|
||
| function createAppsView(key: number): WebContentsView { | ||
| function createAppsView(key: number, url: string): WebContentsView { | ||
| secureAppsSession() | ||
| const view = new WebContentsView({ | ||
| webPreferences: { | ||
|
|
@@ -168,17 +181,33 @@ function createAppsView(key: number): WebContentsView { | |
| if (isMainFrame && isPageLoadFailure(errorCode)) markLoadFailed(key, view, url) | ||
| }) | ||
| wc.on('did-navigate', (_event, url, httpResponseCode) => { | ||
| awaitingCommit.delete(key) | ||
| settledPages.delete(key) | ||
| if (isDocumentFailure(httpResponseCode)) markLoadFailed(key, view, url) | ||
| trackAppOpen(key, url) | ||
| }) | ||
| wc.on('did-navigate-in-page', (_event, url, isMainFrame) => { | ||
| if (isMainFrame) trackAppOpen(key, url) | ||
| }) | ||
| wc.loadURL(APPS_URL).catch(() => {}) | ||
| appOpen.set(key, isAppOpen(url, APPS_URL)) | ||
| awaitingCommit.add(key) | ||
| settledPages.delete(key) | ||
| wc.loadURL(url).catch(() => {}) | ||
| void desktopAppIds() | ||
| return view | ||
| } | ||
|
|
||
| function requestedUrl(r: Partial<AppsRect>): string { | ||
| return typeof r.url === 'string' && isAppsFrameUrl(r.url, APPS_URL) ? r.url : APPS_URL | ||
| } | ||
|
|
||
| function openUrl(key: number, view: WebContentsView, url: string): void { | ||
| appOpen.set(key, isAppOpen(url, APPS_URL)) | ||
| awaitingCommit.add(key) | ||
| settledPages.delete(key) | ||
| view.webContents.loadURL(url).catch(() => {}) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A fragment-only card open can leave the list page on screen. When the apps view already shows Two parts depend on code outside this repository:
Choose one fix:
|
||
| } | ||
|
|
||
| function entryForPanel( | ||
| sender: WebContents | ||
| ): [number, NonNullable<ReturnType<typeof comfyWindows.get>>] | null { | ||
|
|
@@ -197,19 +226,24 @@ function showApps(event: IpcMainEvent, rect: unknown): void { | |
| const r = rect as Partial<AppsRect> | null | ||
| if (!r || ![r.x, r.y, r.width, r.height].every((n) => typeof n === 'number' && isFinite(n))) | ||
| return | ||
| const url = requestedUrl(r) | ||
| let view = views.get(key) | ||
| if (view?.webContents.isDestroyed()) view = undefined | ||
| if (view && failedViews.has(view)) { | ||
| if (r.fresh !== true) return | ||
| failedViews.delete(view) | ||
| view.webContents.loadURL(APPS_URL).catch(() => {}) | ||
| openUrl(key, view, url) | ||
| } else if (view && r.fresh === true && view.webContents.getURL() !== url) { | ||
| openUrl(key, view, url) | ||
| } | ||
| if (!view) { | ||
| view = createAppsView(key) | ||
| view = createAppsView(key, url) | ||
| views.set(key, view) | ||
| entry.window.once('closed', () => { | ||
| views.delete(key) | ||
| appOpen.delete(key) | ||
| awaitingCommit.delete(key) | ||
| settledPages.delete(key) | ||
| if (!view!.webContents.isDestroyed()) view!.webContents.close() | ||
| syncLocalSocket() | ||
| }) | ||
|
|
@@ -223,7 +257,19 @@ function showApps(event: IpcMainEvent, rect: unknown): void { | |
| }) | ||
| entry.window.contentView.addChildView(view) | ||
| view.setVisible(true) | ||
| if (r.fresh === true) tellPanelAppOpen(key) | ||
| if (r.fresh !== true) return | ||
| tellPanelAppOpen(key) | ||
| if (settledPages.has(key)) tellPanelSettled(key) | ||
| } | ||
|
|
||
| function relayPageSettled(event: IpcMainEvent): void { | ||
| for (const [key, view] of views) { | ||
| if (view.webContents !== event.sender) continue | ||
| if (awaitingCommit.has(key) || !isAppPage(event.senderFrame?.url ?? '', APPS_URL)) return | ||
| settledPages.add(key) | ||
| tellPanelSettled(key) | ||
| return | ||
| } | ||
| } | ||
|
|
||
| function hideApps(event: IpcMainEvent): void { | ||
|
|
@@ -668,6 +714,10 @@ function appsPages(): WebContents[] { | |
| export function registerAppsIpc(): void { | ||
| ipcMain.on('comfy-apps:show', showApps) | ||
| ipcMain.on('comfy-apps:hide', hideApps) | ||
| ipcMain.on(APPS_PAGE_SETTLED_CHANNEL, relayPageSettled) | ||
| ipcMain.handle(APPS_CATALOG_CHANNEL, (event) => | ||
|
PabloWiedemann marked this conversation as resolved.
Resolved
|
||
| entryForPanel(event.sender) ? listCatalogApps(APPS_URL) : [] | ||
| ) | ||
| onAppsEnabledChanged(tellPanelsAppsEnabled) | ||
| initLocalComfy(appsPages) | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,181 @@ | ||
| import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' | ||
|
|
||
| import { _resetCatalogAppsForTest, catalogUrl, listCatalogApps, toCatalogApp } from './catalog' | ||
|
|
||
| const LIST = 'https://apps.example/apps/' | ||
| const fetchMock = vi.fn() | ||
|
|
||
| function item(uid: string, data: Record<string, unknown>) { | ||
| return { uid, data } | ||
| } | ||
|
|
||
| function catalogApp(slug: string, title: string, order: number) { | ||
| return item(`uid-${slug}`, { | ||
| title, | ||
| slug, | ||
| description: `${title} description`, | ||
| sort_order: order, | ||
| website_media: { '$.static_thumb': `/catalog-media/${slug}/v1` } | ||
| }) | ||
| } | ||
|
|
||
| beforeEach(() => { | ||
| _resetCatalogAppsForTest() | ||
| vi.stubGlobal('fetch', fetchMock) | ||
| }) | ||
|
|
||
| afterEach(() => { | ||
| vi.unstubAllGlobals() | ||
| vi.clearAllMocks() | ||
| }) | ||
|
|
||
| describe('catalogUrl', () => { | ||
| it('asks the Cloud catalog for the apps of the Desktop surface', () => { | ||
| const url = new URL(catalogUrl()) | ||
| expect(url.origin + url.pathname).toBe('https://cloud.comfy.org/api/v1/catalog/items') | ||
| expect(Object.fromEntries(url.searchParams)).toEqual({ | ||
| type: 'app', | ||
| surface: 'desktop_starters', | ||
| limit: '100' | ||
| }) | ||
| }) | ||
| }) | ||
|
|
||
| describe('toCatalogApp', () => { | ||
| it('takes the title, description and thumbnail, and opens the app on its slug route', () => { | ||
| expect(toCatalogApp(catalogApp('text-to-image', 'Text to Image', 2), LIST)).toEqual({ | ||
| id: 'uid-text-to-image', | ||
| title: 'Text to Image', | ||
| description: 'Text to Image description', | ||
| thumbnailUrl: 'https://comfy.org/catalog-media/text-to-image/v1', | ||
| url: 'https://apps.example/apps/#/text-to-image' | ||
| }) | ||
| }) | ||
|
|
||
| it('keeps an odd slug inside the route', () => { | ||
| const app = toCatalogApp(item('a', { title: 'A', slug: 'a b/../c' }), LIST) | ||
| expect(app?.url).toBe('https://apps.example/apps/#/a%20b%2F..%2Fc') | ||
| expect(app?.description).toBe('') | ||
| expect(app?.thumbnailUrl).toBeNull() | ||
| }) | ||
|
|
||
| it('falls back to the hero poster and ignores media outside the catalog', () => { | ||
| const poster = item('a', { | ||
| title: 'A', | ||
| slug: 'a', | ||
| website_media: { '$.hero_poster': '/catalog-media/a/poster' } | ||
| }) | ||
| const outside = item('b', { | ||
| title: 'B', | ||
| slug: 'b', | ||
| website_media: { '$.static_thumb': 'https://evil.example/x.png' } | ||
| }) | ||
| expect(toCatalogApp(poster, LIST)?.thumbnailUrl).toBe( | ||
| 'https://comfy.org/catalog-media/a/poster' | ||
| ) | ||
| expect(toCatalogApp(outside, LIST)?.thumbnailUrl).toBeNull() | ||
| }) | ||
|
|
||
| it('ignores media that climbs out of the catalog folder', () => { | ||
| const climbing = item('a', { | ||
| title: 'A', | ||
| slug: 'a', | ||
| website_media: { | ||
| '$.static_thumb': '/catalog-media/../account/delete', | ||
| '$.hero_poster': '/catalog-media/a/poster' | ||
| } | ||
| }) | ||
| expect(toCatalogApp(climbing, LIST)?.thumbnailUrl).toBe( | ||
| 'https://comfy.org/catalog-media/a/poster' | ||
| ) | ||
| }) | ||
|
|
||
| it('skips an app without a title or a slug', () => { | ||
| expect(toCatalogApp(item('a', { slug: 'a' }), LIST)).toBeNull() | ||
| expect(toCatalogApp(item('b', { title: 'No slug' }), LIST)).toBeNull() | ||
| expect(toCatalogApp(item('c', { title: 'Blank slug', slug: ' ' }), LIST)).toBeNull() | ||
| }) | ||
| }) | ||
|
|
||
| describe('listCatalogApps', () => { | ||
| it('lists every app the catalog returns, in catalog order, and leaves out ones it cannot open', async () => { | ||
| fetchMock.mockResolvedValue( | ||
| Response.json({ | ||
| items: [ | ||
| catalogApp('product-ads', 'Second', 1), | ||
| item('x', { title: 'No slug' }), | ||
| catalogApp('upscale', 'Third', 2), | ||
| catalogApp('genjutsu', 'First', 0) | ||
| ] | ||
| }) | ||
| ) | ||
| const apps = await listCatalogApps(LIST) | ||
| expect(apps.map((app) => app.title)).toEqual(['First', 'Second', 'Third']) | ||
| }) | ||
|
|
||
| it('skips entries that are not objects and lists each app once', async () => { | ||
| fetchMock.mockResolvedValue( | ||
| Response.json({ | ||
| items: [ | ||
| null, | ||
| 'genjutsu', | ||
| catalogApp('genjutsu', 'First', 0), | ||
| catalogApp('genjutsu', 'Again', 1) | ||
| ] | ||
| }) | ||
| ) | ||
| const apps = await listCatalogApps(LIST) | ||
| expect(apps.map((app) => app.title)).toEqual(['First']) | ||
| }) | ||
|
|
||
| it('keeps an empty catalog empty', async () => { | ||
| fetchMock.mockResolvedValue(Response.json({ items: [] })) | ||
| await expect(listCatalogApps(LIST)).resolves.toEqual([]) | ||
| }) | ||
|
|
||
| it('fails when the catalog answers without an item list', async () => { | ||
| fetchMock.mockResolvedValue(Response.json({ items: null })) | ||
| await expect(listCatalogApps(LIST)).rejects.toThrow('no item list') | ||
| fetchMock.mockResolvedValue(Response.json(null)) | ||
| await expect(listCatalogApps(LIST)).rejects.toThrow('no item list') | ||
| }) | ||
|
|
||
| it('fails when the catalog does not answer', async () => { | ||
| fetchMock.mockResolvedValue(new Response(null, { status: 503 })) | ||
| await expect(listCatalogApps(LIST)).rejects.toThrow('HTTP 503') | ||
| }) | ||
|
|
||
| it('answers again from the last list without asking the catalog', async () => { | ||
| fetchMock.mockResolvedValue(Response.json({ items: [catalogApp('genjutsu', 'First', 0)] })) | ||
| await listCatalogApps(LIST) | ||
| const again = await listCatalogApps(LIST) | ||
| expect(again.map((app) => app.title)).toEqual(['First']) | ||
| expect(fetchMock).toHaveBeenCalledTimes(1) | ||
| }) | ||
|
|
||
| it('shares one request between callers that ask at the same time', async () => { | ||
| fetchMock.mockImplementation(async () => | ||
| Response.json({ items: [catalogApp('genjutsu', 'First', 0)] }) | ||
| ) | ||
| const [first, second] = await Promise.all([listCatalogApps(LIST), listCatalogApps(LIST)]) | ||
| expect(second).toBe(first) | ||
| expect(fetchMock).toHaveBeenCalledTimes(1) | ||
| }) | ||
|
|
||
| it('keeps the last list when a later request fails', async () => { | ||
| vi.useFakeTimers() | ||
| try { | ||
| fetchMock.mockResolvedValueOnce( | ||
| Response.json({ items: [catalogApp('genjutsu', 'First', 0)] }) | ||
| ) | ||
| await listCatalogApps(LIST) | ||
| vi.advanceTimersByTime(11 * 60 * 1000) | ||
| fetchMock.mockResolvedValueOnce(new Response(null, { status: 503 })) | ||
| const apps = await listCatalogApps(LIST) | ||
| expect(apps.map((app) => app.title)).toEqual(['First']) | ||
| expect(fetchMock).toHaveBeenCalledTimes(2) | ||
| } finally { | ||
| vi.useRealTimers() | ||
| } | ||
| }) | ||
| }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 Medium —
awaitingCommitis only cleared in thedid-navigatehandler, but loading a URL that differs from the current one only by fragment — exactly the shapetoCatalogAppproduces — commits as a same-document navigation and firesdid-navigate-in-pageinstead. After the second app open the key stays inawaitingCommitindefinitely andrelayPageSettledreturns early for every later settle. The same gap exists for failed loads, sincedid-fail-loaddoes not clear the flag either. Raised by 4 of 8 reviewers (claude-opus-5-thinking-max adversarial, claude-opus-5-thinking-max edge-case, gemini-3.1-pro adversarial, kimi-k2.7-code edge-case).