From 3b176a244346e81dfa0f0f164f91b373ee148331 Mon Sep 17 00:00:00 2001 From: PabloWiedemann Date: Tue, 10 Nov 2026 09:41:57 -0800 Subject: [PATCH 01/13] feat(apps): show the apps as Desktop cards from the Comfy content catalog All apps now lists the apps itself instead of showing the website's apps page. Main reads the Cloud catalog (type=app, surface=desktop_starters, or COMFY_APPS_CATALOG_SURFACE) and keeps each app's title, description, thumbnail (static_thumb, else hero_poster, from comfy.org/catalog-media) and the page Desktop opens: compatibility.desktop.page on the apps origin, or the list route #/ for a steps app. Apps without either are left out. The panel draws them with the design system's content-card. A card opens its page in the Apps view over the whole page; the app's back link to the list closes it and shows the cards again. An empty or unreachable catalog shows Coming soon. --- locales/en.json | 2 +- locales/zh.json | 2 +- src/main/apps/appsView.ts | 25 ++++- src/main/apps/catalog.test.ts | 118 ++++++++++++++++++++++++ src/main/apps/catalog.ts | 82 ++++++++++++++++ src/preload/api.ts | 1 + src/renderer/panel.html | 2 +- src/renderer/src/panel/AppsGallery.vue | 112 ++++++++++++++++++++++ src/renderer/src/panel/AppsHost.vue | 6 +- src/renderer/src/panel/AppsView.test.ts | 108 +++++++++++++++------- src/renderer/src/panel/AppsView.vue | 51 +++++----- src/renderer/src/types/ipc.ts | 1 + src/types/ipc.ts | 19 +++- 13 files changed, 465 insertions(+), 64 deletions(-) create mode 100644 src/main/apps/catalog.test.ts create mode 100644 src/main/apps/catalog.ts create mode 100644 src/renderer/src/panel/AppsGallery.vue diff --git a/locales/en.json b/locales/en.json index 2cff77932..f76e11970 100644 --- a/locales/en.json +++ b/locales/en.json @@ -88,7 +88,7 @@ "browseApps": "Browse apps" }, "apps": { - "loadFailed": "The apps page at {url} could not load.", + "loadFailed": "The app at {url} could not load.", "tabsLabel": "Apps view", "tabs": { "all": "All apps", diff --git a/locales/zh.json b/locales/zh.json index ac8ae62fb..418bd7495 100644 --- a/locales/zh.json +++ b/locales/zh.json @@ -88,7 +88,7 @@ "browseApps": "浏览应用" }, "apps": { - "loadFailed": "无法加载应用页面:{url}", + "loadFailed": "无法加载应用:{url}", "tabsLabel": "应用视图", "tabs": { "all": "所有应用", diff --git a/src/main/apps/appsView.ts b/src/main/apps/appsView.ts index 7b2ee8f76..4ed96ef2e 100644 --- a/src/main/apps/appsView.ts +++ b/src/main/apps/appsView.ts @@ -40,6 +40,7 @@ import { startLocal, syncLocalSocket } from './localComfy' +import { listCatalogApps } from './catalog' import { localBuilds, openInComfy } from './openInComfy' const APPS_URL = appsUrl() @@ -52,6 +53,7 @@ const failedViews = new WeakSet() export const APPS_LOAD_FAILED_CHANNEL = 'comfy-apps:load-failed' export const APPS_APP_OPEN_CHANNEL = 'comfy-apps:app-open' +export const APPS_CATALOG_CHANNEL = 'comfy-apps:catalog' const appOpen = new Map() @@ -61,6 +63,7 @@ export interface AppsRect { width: number height: number fresh?: boolean + url?: string } export type AppsAuthState = { signedIn: false } | { signedIn: true; email?: string } @@ -90,7 +93,7 @@ function markLoadFailed(key: number, view: WebContentsView, url: string): void { tellPanelLoadFailed(comfyWindows.get(key)?.panelView?.webContents, url || APPS_URL) } -function createAppsView(key: number): WebContentsView { +function createAppsView(key: number, url: string): WebContentsView { const view = new WebContentsView({ webPreferences: { preload: path.join(__dirname, '../preload/appsPreload.js'), @@ -121,10 +124,20 @@ function createAppsView(key: number): WebContentsView { 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)) + wc.loadURL(url).catch(() => {}) return view } +function requestedUrl(r: Partial): string { + return typeof r.url === 'string' && isAppsFrameUrl(r.url, APPS_ORIGIN) ? r.url : APPS_URL +} + +function openUrl(key: number, view: WebContentsView, url: string): void { + appOpen.set(key, isAppOpen(url, APPS_URL)) + view.webContents.loadURL(url).catch(() => {}) +} + function entryForPanel( sender: WebContents ): [number, NonNullable>] | null { @@ -142,14 +155,17 @@ function showApps(event: IpcMainEvent, rect: unknown): void { const r = rect as Partial | 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 && 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.webContents.isDestroyed()) { - view = createAppsView(key) + view = createAppsView(key, url) views.set(key, view) entry.window.once('closed', () => { views.delete(key) @@ -464,6 +480,7 @@ function appsPages(): WebContents[] { export function registerAppsIpc(): void { ipcMain.on('comfy-apps:show', showApps) ipcMain.on('comfy-apps:hide', hideApps) + ipcMain.handle(APPS_CATALOG_CHANNEL, () => listCatalogApps(APPS_URL)) initLocalComfy(appsPages) handleFromApps('comfy-apps:get-auth-state', authState) diff --git a/src/main/apps/catalog.test.ts b/src/main/apps/catalog.test.ts new file mode 100644 index 000000000..515d749f9 --- /dev/null +++ b/src/main/apps/catalog.test.ts @@ -0,0 +1,118 @@ +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' + +import { catalogUrl, listCatalogApps, toCatalogApp } from './catalog' + +const LIST = 'https://apps.example/apps/' +const fetchMock = vi.fn() + +function item(uid: string, data: Record) { + return { uid, data } +} + +function pageApp(uid: string, title: string, order: number) { + return item(uid, { + title, + description: `${title} description`, + sort_order: order, + compatibility: { desktop: { page: `/apps/${uid}/desktop.html` } }, + website_media: { '$.static_thumb': `/catalog-media/${uid}/v1` } + }) +} + +beforeEach(() => { + 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, thumbnail and Desktop page of an app', () => { + expect(toCatalogApp(pageApp('studio', 'Cinematic Studio', 2), LIST)).toEqual({ + id: 'studio', + title: 'Cinematic Studio', + description: 'Cinematic Studio description', + thumbnailUrl: 'https://comfy.org/catalog-media/studio/v1', + url: 'https://apps.example/apps/studio/desktop.html', + order: 2 + }) + }) + + it('opens a steps app on its route of the apps list', () => { + const app = toCatalogApp( + item('make image', { title: 'Make an image', implementation_ref: 'steps' }), + LIST + ) + expect(app?.url).toBe('https://apps.example/apps/#/make%20image') + 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', + implementation_ref: 'steps', + website_media: { '$.hero_poster': '/catalog-media/a/poster' } + }) + const outside = item('b', { + title: 'B', + implementation_ref: 'steps', + 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('skips an app without a title or a page Desktop can open', () => { + expect(toCatalogApp(item('a', { implementation_ref: 'steps' }), LIST)).toBeNull() + expect( + toCatalogApp(item('b', { title: 'Hub only', implementation_ref: 'studio' }), LIST) + ).toBeNull() + expect( + toCatalogApp( + item('c', { + title: 'Elsewhere', + compatibility: { desktop: { page: 'https://evil.example/app' } } + }), + LIST + ) + ).toBeNull() + }) +}) + +describe('listCatalogApps', () => { + it('lists the apps Desktop can open in catalog order', async () => { + fetchMock.mockResolvedValue( + Response.json({ + items: [ + pageApp('b', 'Second', 1), + item('x', { title: 'Hub only' }), + pageApp('a', 'First', 0) + ] + }) + ) + const apps = await listCatalogApps(LIST) + expect(apps.map((app) => app.title)).toEqual(['First', 'Second']) + }) + + it('fails when the catalog does not answer', async () => { + fetchMock.mockResolvedValue(new Response(null, { status: 503 })) + await expect(listCatalogApps(LIST)).rejects.toThrow('HTTP 503') + }) +}) diff --git a/src/main/apps/catalog.ts b/src/main/apps/catalog.ts new file mode 100644 index 000000000..b9c1fd176 --- /dev/null +++ b/src/main/apps/catalog.ts @@ -0,0 +1,82 @@ +import { CLOUD_CONFIG } from '../cloud/config' +import type { CatalogApp } from '../../types/ipc' +import { appsOrigin, isAppsFrameUrl } from './guards' + +const CATALOG_SURFACE = process.env['COMFY_APPS_CATALOG_SURFACE'] || 'desktop_starters' +const CATALOG_MEDIA_ORIGIN = 'https://comfy.org' +const CATALOG_TIMEOUT_MS = 8000 +const THUMBNAIL_FIELDS = ['$.static_thumb', '$.hero_poster'] + +interface CatalogItem { + uid?: unknown + data?: { + title?: unknown + description?: unknown + sort_order?: unknown + implementation_ref?: unknown + website_media?: Record | null + compatibility?: { desktop?: { page?: unknown } | null } | null + } | null +} + +export function catalogUrl(surface = CATALOG_SURFACE): string { + const url = new URL('/api/v1/catalog/items', CLOUD_CONFIG.issuer) + url.searchParams.set('type', 'app') + url.searchParams.set('surface', surface) + url.searchParams.set('limit', '100') + return url.href +} + +function thumbnailUrl(media: Record | null | undefined): string | null { + for (const field of THUMBNAIL_FIELDS) { + const path = media?.[field] + if (typeof path === 'string' && path.startsWith('/catalog-media/')) + return `${CATALOG_MEDIA_ORIGIN}${path}` + } + return null +} + +function appPageUrl(item: CatalogItem, uid: string, listUrl: string): string | null { + const page = item.data?.compatibility?.desktop?.page + if (typeof page === 'string') { + let url: string + try { + url = new URL(page, listUrl).href + } catch { + return null + } + return isAppsFrameUrl(url, appsOrigin(listUrl)) ? url : null + } + if (item.data?.implementation_ref === 'steps') + return new URL(`#/${encodeURIComponent(uid)}`, listUrl).href + return null +} + +export function toCatalogApp(item: CatalogItem, listUrl: string): CatalogApp | null { + const uid = item.uid + const title = item.data?.title + if (typeof uid !== 'string' || typeof title !== 'string' || title.trim() === '') return null + const url = appPageUrl(item, uid, listUrl) + if (!url) return null + const description = item.data?.description + const order = item.data?.sort_order + return { + id: uid, + title, + description: typeof description === 'string' ? description : '', + thumbnailUrl: thumbnailUrl(item.data?.website_media), + url, + order: typeof order === 'number' && isFinite(order) ? order : Number.MAX_SAFE_INTEGER + } +} + +export async function listCatalogApps(listUrl: string): Promise { + const res = await fetch(catalogUrl(), { signal: AbortSignal.timeout(CATALOG_TIMEOUT_MS) }) + if (!res.ok) throw new Error(`Catalog request failed: HTTP ${res.status}`) + const body = (await res.json()) as { items?: unknown } + const items = Array.isArray(body.items) ? (body.items as CatalogItem[]) : [] + return items + .map((item) => toCatalogApp(item, listUrl)) + .filter((app): app is CatalogApp => app !== null) + .sort((a, b) => a.order - b.order) +} diff --git a/src/preload/api.ts b/src/preload/api.ts index f6bac68e4..068a03416 100644 --- a/src/preload/api.ts +++ b/src/preload/api.ts @@ -103,6 +103,7 @@ export function buildElectronApi(): ElectronApi { ipcRenderer.invoke('assets:download', installationId, assetId, fileName), showApps: (rect) => ipcRenderer.send('comfy-apps:show', rect), hideApps: () => ipcRenderer.send('comfy-apps:hide'), + listCatalogApps: () => ipcRenderer.invoke('comfy-apps:catalog'), onAppsLoadFailed: (callback) => { const handler = (_event: IpcRendererEvent, info: unknown) => callback(info as Parameters[0]) diff --git a/src/renderer/panel.html b/src/renderer/panel.html index 9a80e88a8..e1bf9958d 100644 --- a/src/renderer/panel.html +++ b/src/renderer/panel.html @@ -5,7 +5,7 @@ Comfy Desktop — Panel