From c24afa2e2f90c3c936b6753006ffcb1ea0eff3df Mon Sep 17 00:00:00 2001 From: PabloWiedemann Date: Tue, 10 Nov 2026 08:24:49 -0800 Subject: [PATCH 01/12] feat(ui): add Home and Apps to the sidebar with a Generated Files gallery - the sidebar gets Home and Apps rows; Home says Coming soon - the Apps page has two tabs: All apps (Coming soon) and Generated Files - Generated Files lists the output assets of Comfy Cloud and of each running local build through /api/assets, in a masonry or grid layout with a type filter, search, sort, and empty states for signed out, no assets, no matches and a failed load - the view setup is remembered per user; the Builds page title matches the Apps page title --- locales/en.json | 45 ++ locales/zh.json | 45 ++ src/main/lib/assets.test.ts | 170 +++++++ src/main/lib/assets.ts | 164 +++++++ src/main/lib/ipc/index.ts | 2 + src/preload/api.ts | 1 + src/renderer/panel.html | 2 +- src/renderer/src/panel/AppSidebar.test.ts | 25 +- src/renderer/src/panel/AppSidebar.vue | 17 +- src/renderer/src/panel/AppsView.test.ts | 280 +++++++++++ src/renderer/src/panel/AppsView.vue | 513 +++++++++++++++++++++ src/renderer/src/panel/PanelApp.vue | 43 +- src/renderer/src/panel/dashboardSection.ts | 11 + src/renderer/src/types/ipc.ts | 2 + src/renderer/src/views/ChooserView.vue | 2 +- src/types/ipc.ts | 14 + 16 files changed, 1318 insertions(+), 18 deletions(-) create mode 100644 src/main/lib/assets.test.ts create mode 100644 src/main/lib/assets.ts create mode 100644 src/renderer/src/panel/AppsView.test.ts create mode 100644 src/renderer/src/panel/AppsView.vue create mode 100644 src/renderer/src/panel/dashboardSection.ts diff --git a/locales/en.json b/locales/en.json index c910b8e41..5ea93efdf 100644 --- a/locales/en.json +++ b/locales/en.json @@ -19,12 +19,57 @@ "builds": "Builds", "navigation": "Navigation", "home": "Home", + "apps": "Apps", + "comingSoon": "Coming soon", "tools": "Tools", "collapse": "Collapse sidebar", "expand": "Expand sidebar", "signInTitle": "Log in to Comfy", "signInBody": "Sync your work and run it on Comfy Cloud." }, + "assets": { + "kindLabel": "Asset type", + "kind": { + "all": "All", + "image": "Images", + "video": "Videos", + "3d": "3D", + "audio": "Audio" + }, + "refresh": "Refresh assets", + "search": "Search by name...", + "viewOptions": "View options", + "layoutLabel": "Layout", + "layout": { + "masonry": "Masonry", + "grid": "Grid" + }, + "sortLabel": "Sort by", + "sort": { + "newest": "Newest first", + "oldest": "Oldest first" + }, + "showLabel": "Show", + "showName": "File name", + "showDetails": "File details", + "emptyTitle": "No assets yet", + "emptyBody": "Open an app to make assets.", + "loadFailed": "Couldn't load assets", + "noMatches": "No matching assets", + "noMatchesHint": "Try another type or search.", + "filter": "Filter", + "signedOutTitle": "Log in to see your assets", + "signedOutBody": "Assets that you make in Comfy Cloud show here.", + "signIn": "Log in to Comfy Cloud", + "browseApps": "Browse apps" + }, + "apps": { + "tabsLabel": "Apps view", + "tabs": { + "all": "All apps", + "files": "Generated Files" + } + }, "installType": { "standalone": "Standalone", "cloud": "Cloud", diff --git a/locales/zh.json b/locales/zh.json index f6246e123..0efa4e807 100644 --- a/locales/zh.json +++ b/locales/zh.json @@ -19,12 +19,57 @@ "builds": "构建", "navigation": "导航", "home": "主页", + "apps": "应用", + "comingSoon": "即将推出", "tools": "工具", "collapse": "收起侧边栏", "expand": "展开侧边栏", "signInTitle": "登录 Comfy", "signInBody": "同步你的作品,并在 Comfy Cloud 上运行。" }, + "assets": { + "kindLabel": "资产类型", + "kind": { + "all": "全部", + "image": "图片", + "video": "视频", + "3d": "3D", + "audio": "音频" + }, + "refresh": "刷新资产", + "search": "按名称搜索...", + "viewOptions": "视图选项", + "layoutLabel": "布局", + "layout": { + "masonry": "瀑布流", + "grid": "网格" + }, + "sortLabel": "排序方式", + "sort": { + "newest": "最新优先", + "oldest": "最早优先" + }, + "showLabel": "显示", + "showName": "文件名", + "showDetails": "文件详情", + "emptyTitle": "暂无资产", + "emptyBody": "打开一个应用来生成资产。", + "loadFailed": "无法加载资产", + "noMatches": "没有匹配的资产", + "noMatchesHint": "试试其他类型或搜索词。", + "filter": "筛选", + "signedOutTitle": "登录以查看你的资产", + "signedOutBody": "你在 Comfy Cloud 中生成的资产会显示在这里。", + "signIn": "登录 Comfy Cloud", + "browseApps": "浏览应用" + }, + "apps": { + "tabsLabel": "应用视图", + "tabs": { + "all": "所有应用", + "files": "生成的文件" + } + }, "installType": { "standalone": "独立版", "cloud": "云端", diff --git a/src/main/lib/assets.test.ts b/src/main/lib/assets.test.ts new file mode 100644 index 000000000..ce4951a41 --- /dev/null +++ b/src/main/lib/assets.test.ts @@ -0,0 +1,170 @@ +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' + +const getInstallation = vi.fn() +const getAccessToken = vi.fn() +const runningSessions = new Map() + +vi.mock('electron', () => ({ + ipcMain: { handle: vi.fn() } +})) +vi.mock('../installations', () => ({ get: (id: string) => getInstallation(id) })) +vi.mock('../devplatform/session', () => ({ + getCloudSession: () => ({ getAccessToken }) +})) +vi.mock('./ipc/shared', () => ({ + _runningSessions: runningSessions, + sourceMap: { + cloud: { category: 'cloud' }, + standalone: { category: 'local' }, + remote: { category: 'remote' } + } +})) + +const { assetKind, listAssets, signedStorageUrl } = await import('./assets') + +const fetchMock = vi.fn() + +function jsonResponse(body: unknown): Response { + return new Response(JSON.stringify(body), { + status: 200, + headers: { 'Content-Type': 'application/json' } + }) +} + +beforeEach(() => { + vi.stubGlobal('fetch', fetchMock) + runningSessions.clear() +}) + +afterEach(() => { + vi.unstubAllGlobals() + vi.clearAllMocks() +}) + +describe('assetKind', () => { + it.each([ + ['clip.bin', 'video/mp4', 'video'], + ['still.png', undefined, 'image'], + ['narration.WAV', undefined, 'audio'], + ['mesh.glb', undefined, '3d'], + ['notes.txt', undefined, null] + ])('classifies %s (%s) as %s', (name, mimeType, kind) => { + expect(assetKind(name, mimeType)).toBe(kind) + }) +}) + +describe('signedStorageUrl', () => { + it.each([ + ['https://storage.googleapis.com/bucket/a.png?sig=1', true], + ['https://evil.example.com/a.png', false], + ['http://storage.googleapis.com/a.png', false], + [null, false] + ])('accepts only https Google storage links: %s', (location, accepted) => { + expect(signedStorageUrl(location) !== null).toBe(accepted) + }) +}) + +describe('listAssets', () => { + it('lists a running local build with previews served by that build', async () => { + getInstallation.mockResolvedValue({ id: 'local-1', sourceId: 'standalone' }) + runningSessions.set('local-1', { port: 8188 }) + fetchMock.mockResolvedValue( + jsonResponse({ + assets: [ + { + id: 'a1', + name: 'still.png', + size: 2048, + mime_type: 'image/png', + tags: ['output'], + created_at: '2026-11-09T10:00:00Z', + preview_url: '/api/view?type=output&filename=still.png' + } + ] + }) + ) + + const assets = await listAssets('local-1') + + expect(fetchMock.mock.calls[0]![0]).toBe( + 'http://127.0.0.1:8188/api/assets?tags_any=output&sort=created_at&order=desc&limit=100' + ) + expect(assets).toEqual([ + { + id: 'a1', + name: 'still.png', + kind: 'image', + sizeBytes: 2048, + createdAt: '2026-11-09T10:00:00Z', + mimeType: 'image/png', + tags: ['output'], + previewUrl: 'http://127.0.0.1:8188/api/view?type=output&filename=still.png' + } + ]) + }) + + it('skips remote builds instead of asking this machine', async () => { + getInstallation.mockResolvedValue({ id: 'remote-1', sourceId: 'remote' }) + runningSessions.set('remote-1', { port: 8188 }) + + expect(await listAssets('remote-1')).toEqual([]) + expect(fetchMock).not.toHaveBeenCalled() + }) + + it('serves local previews only from the build itself', async () => { + getInstallation.mockResolvedValue({ id: 'local-1', sourceId: 'standalone' }) + runningSessions.set('local-1', { port: 8188 }) + fetchMock.mockResolvedValue( + jsonResponse({ + assets: [{ id: 'a1', name: 'still.png', preview_url: 'http://127.0.0.1:9999/evil.png' }] + }) + ) + + const [summary] = await listAssets('local-1') + + expect(summary!.previewUrl).toBe( + 'http://127.0.0.1:8188/api/assets/a1/content?disposition=inline' + ) + }) + + it('returns nothing for a local build that is not running', async () => { + getInstallation.mockResolvedValue({ id: 'local-1', sourceId: 'standalone' }) + + expect(await listAssets('local-1')).toEqual([]) + expect(fetchMock).not.toHaveBeenCalled() + }) + + it('lists the signed-in cloud workspace and resolves signed media links for playable kinds', async () => { + getInstallation.mockResolvedValue({ id: 'cloud-1', sourceId: 'cloud' }) + getAccessToken.mockResolvedValue('token') + fetchMock + .mockResolvedValueOnce( + jsonResponse({ + assets: [ + { id: 'v1', name: 'clip.mp4', created_at: '2026-11-09T10:00:00Z' }, + { id: 's1', name: 'audio/voice.wav', created_at: '2026-11-09T09:00:00Z' }, + { id: 'm1', name: 'mesh.glb', created_at: '2026-11-09T08:00:00Z' } + ] + }) + ) + .mockImplementation( + async (url: string) => + new Response(null, { + status: 302, + headers: { + Location: `https://storage.googleapis.com/bucket/${url.split('/')[5]}?sig=1` + } + }) + ) + + const assets = await listAssets('cloud-1') + + expect(fetchMock.mock.calls[0]![1].headers.Authorization).toBe('Bearer token') + expect(assets.map((a) => [a.name, a.kind, a.previewUrl])).toEqual([ + ['clip.mp4', 'video', 'https://storage.googleapis.com/bucket/v1?sig=1'], + ['voice.wav', 'audio', 'https://storage.googleapis.com/bucket/s1?sig=1'], + ['mesh.glb', '3d', null] + ]) + expect(fetchMock).toHaveBeenCalledTimes(3) + }) +}) diff --git a/src/main/lib/assets.ts b/src/main/lib/assets.ts new file mode 100644 index 000000000..2319ce061 --- /dev/null +++ b/src/main/lib/assets.ts @@ -0,0 +1,164 @@ +import { ipcMain } from 'electron' +import { CLOUD_CONFIG } from '../cloud/config' +import { getCloudSession } from '../devplatform/session' +import * as installations from '../installations' +import { _runningSessions, sourceMap } from './ipc/shared' +import { runPool } from '../sources/standalone/templateDownloadCore' +import type { AssetKind, AssetSummary } from '../../types/ipc' + +const ASSETS_LIST_CHANNEL = 'assets:list' + +const LIST_QUERY = 'tags_any=output&sort=created_at&order=desc&limit=100' +const REQUEST_TIMEOUT_MS = 20_000 +const SIGNED_URL_CONCURRENCY = 6 +const SIGNED_STORAGE_HOST = 'storage.googleapis.com' + +const KIND_BY_EXTENSION: Record = Object.fromEntries([ + ...['png', 'jpg', 'jpeg', 'gif', 'webp', 'bmp', 'avif', 'tif', 'tiff', 'svg'].map( + (ext) => [ext, 'image'] as const + ), + ...['mp4', 'm4v', 'webm', 'mov', 'avi', 'mkv'].map((ext) => [ext, 'video'] as const), + ...['mp3', 'wav', 'ogg', 'flac', 'opus', 'm4a'].map((ext) => [ext, 'audio'] as const), + ...['obj', 'fbx', 'gltf', 'glb', 'stl', 'usdz', 'ply', 'spz', 'splat', 'ksplat'].map( + (ext) => [ext, '3d'] as const + ) +]) + +interface AssetRow { + id: string + name: string + size?: number + mime_type?: string + created_at?: string + preview_url?: string + tags?: unknown +} + +type AssetSource = { kind: 'cloud'; accessToken: string } | { kind: 'local'; origin: string } +type ContentDisposition = 'inline' | 'attachment' + +function isAssetRow(value: unknown): value is AssetRow { + if (!value || typeof value !== 'object') return false + const row = value as Partial + return typeof row.id === 'string' && typeof row.name === 'string' +} + +export function assetKind(name: string, mimeType?: string): AssetKind | null { + const mimeKind = mimeType?.split('/')[0] + if (mimeKind === 'image' || mimeKind === 'video' || mimeKind === 'audio') return mimeKind + if (mimeType?.startsWith('model/')) return '3d' + const extension = name.slice(name.lastIndexOf('.') + 1).toLowerCase() + return KIND_BY_EXTENSION[extension] ?? null +} + +function toSummary(row: AssetRow, previewUrl: string | null): AssetSummary { + return { + id: row.id, + name: row.name.slice(row.name.lastIndexOf('/') + 1), + kind: assetKind(row.name, row.mime_type), + sizeBytes: row.size ? row.size : null, + createdAt: row.created_at ?? null, + mimeType: row.mime_type ?? null, + tags: Array.isArray(row.tags) + ? row.tags.filter((tag): tag is string => typeof tag === 'string') + : [], + previewUrl + } +} + +async function fetchAssetRows(url: string, headers: Record): Promise { + const res = await fetch(url, { + headers: { Accept: 'application/json', ...headers }, + signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS) + }) + if (!res.ok) throw new Error(`List assets failed: HTTP ${res.status}`) + const body: unknown = await res.json().catch(() => null) + const rows = body && typeof body === 'object' ? (body as { assets?: unknown }).assets : undefined + if (!Array.isArray(rows)) throw new Error('List assets returned an invalid page') + return rows.filter(isAssetRow) +} + +export function signedStorageUrl(location: string | null): string | null { + if (!location) return null + try { + const url = new URL(location) + return url.protocol === 'https:' && url.hostname.toLowerCase() === SIGNED_STORAGE_HOST + ? url.toString() + : null + } catch { + return null + } +} + +function contentPath(assetId: string, disposition: ContentDisposition): string { + return `/api/assets/${encodeURIComponent(assetId)}/content?disposition=${disposition}` +} + +async function resolveCloudContentUrl( + assetId: string, + accessToken: string, + disposition: ContentDisposition +): Promise { + try { + const res = await fetch(`${CLOUD_CONFIG.issuer}${contentPath(assetId, disposition)}`, { + headers: { Authorization: `Bearer ${accessToken}` }, + redirect: 'manual', + signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS) + }) + return signedStorageUrl(res.headers.get('location')) + } catch { + return null + } +} + +async function resolveSource(installationId: string): Promise { + const inst = await installations.get(installationId) + if (!inst) return null + const category = sourceMap[inst.sourceId]?.category + if (category === 'cloud') { + const accessToken = await getCloudSession().getAccessToken() + return accessToken ? { kind: 'cloud', accessToken } : null + } + if (category !== 'local') return null + const port = _runningSessions.get(installationId)?.port + return port ? { kind: 'local', origin: `http://127.0.0.1:${port}` } : null +} + +async function listCloudAssets(accessToken: string): Promise { + const rows = await fetchAssetRows( + `${CLOUD_CONFIG.apiBase}/assets?${LIST_QUERY}&include_public=false`, + { Authorization: `Bearer ${accessToken}` } + ) + const summaries = rows.map((row) => toSummary(row, null)) + await runPool(summaries, SIGNED_URL_CONCURRENCY, async (summary) => { + if (summary.kind === null || summary.kind === '3d') return + summary.previewUrl = await resolveCloudContentUrl(summary.id, accessToken, 'inline') + }) + return summaries +} + +function localPreviewUrl(row: AssetRow, origin: string): string { + const fallback = new URL(contentPath(row.id, 'inline'), origin) + if (!row.preview_url) return fallback.toString() + const preview = new URL(row.preview_url, origin) + return (preview.origin === origin ? preview : fallback).toString() +} + +async function listLocalAssets(origin: string): Promise { + const rows = await fetchAssetRows(`${origin}/api/assets?${LIST_QUERY}`, {}) + return rows.map((row) => toSummary(row, localPreviewUrl(row, origin))) +} + +export async function listAssets(installationId: string): Promise { + const source = await resolveSource(installationId) + if (!source) return [] + return source.kind === 'cloud' + ? listCloudAssets(source.accessToken) + : listLocalAssets(source.origin) +} + +export function registerAssetsHandlers(): void { + ipcMain.handle(ASSETS_LIST_CHANNEL, (_event, installationId: unknown) => + typeof installationId === 'string' ? listAssets(installationId) : [] + ) +} diff --git a/src/main/lib/ipc/index.ts b/src/main/lib/ipc/index.ts index 70f5f2476..38a5f239f 100644 --- a/src/main/lib/ipc/index.ts +++ b/src/main/lib/ipc/index.ts @@ -35,6 +35,7 @@ import { registerLogsHandlers } from './registerLogsHandlers' import { registerCrashHandlers } from './registerCrashHandlers' import { registerTelemetryHandlers } from './registerTelemetryHandlers' import { registerDevPlatformHandlers } from './registerDevPlatformHandlers' +import { registerAssetsHandlers } from '../assets' import { registerEmbeddedSessionHandlers } from './registerEmbeddedSessionHandlers' import { reconcileAdoptedSettings } from '../desktopAdopt' import { @@ -278,6 +279,7 @@ export function register(callbacks: RegisterCallbacks = {}): Promise { registerCrashHandlers() registerTelemetryHandlers() registerDevPlatformHandlers() + registerAssetsHandlers() registerEmbeddedSessionHandlers() return startupRecovery.then(() => undefined) } diff --git a/src/preload/api.ts b/src/preload/api.ts index 5ac3d4253..7a81a24c4 100644 --- a/src/preload/api.ts +++ b/src/preload/api.ts @@ -98,6 +98,7 @@ export function buildElectronApi(): ElectronApi { closeAnnouncement: () => ipcRenderer.send('comfy-window:close-announcement'), signalOverlayReady: () => ipcRenderer.send('comfy-window:overlay-ready'), navigatePanel: (page) => ipcRenderer.send('comfy-window:navigate-panel', page), + listAssets: (installationId) => ipcRenderer.invoke('assets:list', installationId), getBuildStorageSnapshot: () => ipcRenderer.invoke('comfy-window:build-storage-snapshot'), resolveStartupRestoreReveal: (result) => ipcRenderer.send('comfy-window:startup-restore-reveal', { result }), diff --git a/src/renderer/panel.html b/src/renderer/panel.html index f20a5f3b0..9a80e88a8 100644 --- a/src/renderer/panel.html +++ b/src/renderer/panel.html @@ -5,7 +5,7 @@ Comfy Desktop — Panel