From 203952848e491e443457b3ddd616cd2592a26f92 Mon Sep 17 00:00:00 2001 From: PabloWiedemann Date: Tue, 10 Nov 2026 16:13:10 -0800 Subject: [PATCH 1/6] feat(apps): open outputs in one Desktop dialog from apps and Generated Files Apps call comfyDesktopApps.showOutput with their outputs. Desktop checks the request, takes a still of the app as the backdrop, and shows the outputs in a dialog in the panel. Download and Open workflow go back to the app, which runs its own buttons. Generated Files opens its files in the same dialog instead of a full-page view. --- locales/en.json | 16 +- locales/zh.json | 28 +- src/main/apps/appsView.ts | 45 ++- src/main/apps/outputs.test.ts | 60 ++++ src/main/apps/outputs.ts | 58 +++ src/main/apps/wiring.test.ts | 2 +- src/preload/api.ts | 7 + src/preload/appsPreload.ts | 12 +- src/renderer/panel.html | 2 +- src/renderer/src/panel/AppsHost.vue | 33 +- src/renderer/src/panel/AppsView.test.ts | 100 +++++- src/renderer/src/panel/AppsView.vue | 99 +++++- src/renderer/src/panel/AssetDetailView.vue | 305 ---------------- src/renderer/src/panel/OutputDetailDialog.vue | 330 ++++++++++++++++++ src/renderer/src/panel/PanelApp.test.ts | 3 +- src/renderer/src/types/ipc.ts | 2 + src/types/ipc.ts | 22 ++ 17 files changed, 761 insertions(+), 363 deletions(-) create mode 100644 src/main/apps/outputs.test.ts create mode 100644 src/main/apps/outputs.ts delete mode 100644 src/renderer/src/panel/AssetDetailView.vue create mode 100644 src/renderer/src/panel/OutputDetailDialog.vue diff --git a/locales/en.json b/locales/en.json index 77bc07453..c9179076f 100644 --- a/locales/en.json +++ b/locales/en.json @@ -68,16 +68,16 @@ "file": "File" }, "detail": { - "type": "Type", - "dimensions": "Dimensions", - "duration": "Duration", - "created": "Created", "tags": "Tags", "tagsHint": "Tags are edited in ComfyUI.", - "togglePanel": "Toggle details panel", - "previous": "Previous asset", - "next": "Next asset", - "position": "{build} · {index} / {total}" + "createdAt": "Created {date}", + "fit": "Fit", + "zoom": "Zoom", + "generationInfo": "Generation info", + "workflow": "Workflow", + "available": "Available", + "notSaved": "Not saved", + "openWorkflow": "Open workflow" }, "noMatches": "No matching assets", "noMatchesHint": "Try another type or search.", diff --git a/locales/zh.json b/locales/zh.json index 63965298b..60d161fde 100644 --- a/locales/zh.json +++ b/locales/zh.json @@ -68,16 +68,16 @@ "file": "文件" }, "detail": { - "type": "类型", - "dimensions": "尺寸", - "duration": "时长", - "created": "创建时间", "tags": "标签", "tagsHint": "标签在 ComfyUI 中编辑。", - "togglePanel": "切换详情面板", - "previous": "上一个资产", - "next": "下一个资产", - "position": "{build} · {index} / {total}" + "createdAt": "创建于 {date}", + "fit": "适应", + "zoom": "缩放", + "generationInfo": "生成信息", + "workflow": "工作流", + "available": "可用", + "notSaved": "未保存", + "openWorkflow": "打开工作流" }, "noMatches": "没有匹配的资产", "noMatchesHint": "试试其他类型或搜索词。", @@ -829,12 +829,12 @@ }, "announcement": { "comfyApi": { - "title": "Comfy API \u73b0\u5df2\u63a8\u51fa", - "lead": "\u5c06\u4f60\u7684 ComfyUI \u5de5\u4f5c\u6d41\u90e8\u7f72\u4e3a\u751f\u4ea7\u73af\u5883 API\u3002\u5c06\u5de5\u4f5c\u6d41\u4e0e\u5176\u81ea\u5b9a\u4e49\u8282\u70b9\u548c\u6a21\u578b\u6253\u5305\uff0c\u90e8\u7f72\u4e3a\u5e94\u7528\u548c\u5de5\u5177\u53ef\u4ee5\u8c03\u7528\u7684\u63a5\u53e3\u3002\u4f60\u4f7f\u7528 ComfyUI \u7684\u65b9\u5f0f\u4e0d\u4f1a\u6709\u4efb\u4f55\u53d8\u5316\u3002", - "primaryCta": "\u4e86\u89e3 Comfy API", - "imageAlt": "Comfy API \u516c\u544a", - "unmute": "\u53d6\u6d88\u9759\u97f3", - "mute": "\u9759\u97f3" + "title": "Comfy API 现已推出", + "lead": "将你的 ComfyUI 工作流部署为生产环境 API。将工作流与其自定义节点和模型打包,部署为应用和工具可以调用的接口。你使用 ComfyUI 的方式不会有任何变化。", + "primaryCta": "了解 Comfy API", + "imageAlt": "Comfy API 公告", + "unmute": "取消静音", + "mute": "静音" } }, "tray": { diff --git a/src/main/apps/appsView.ts b/src/main/apps/appsView.ts index e3259bf40..e15fc6a08 100644 --- a/src/main/apps/appsView.ts +++ b/src/main/apps/appsView.ts @@ -41,6 +41,7 @@ import { syncLocalSocket } from './localComfy' import { listCatalogApps } from './catalog' +import { outputAction, outputRequest } from './outputs' import { localBuilds, openInComfy } from './openInComfy' const APPS_URL = appsUrl(process.env, app.isPackaged) @@ -54,6 +55,9 @@ 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' +export const APPS_OUTPUT_CHANNEL = 'comfy-apps:output' +export const APPS_OUTPUT_ACTION_CHANNEL = 'comfy-apps:output-action' +const BACKDROP_QUALITY = 80 const appOpen = new Map() @@ -200,6 +204,32 @@ function fromAppsPage(event: IpcMainInvokeEvent): boolean { ) } +function keyForAppsPage(sender: WebContents): number | null { + for (const [key, view] of views) if (view.webContents === sender) return key + return null +} + +async function showOutput(page: WebContents, request: unknown): Promise { + const outputs = outputRequest(request) + if (!outputs) throw new Error('These outputs cannot be shown.') + const key = keyForAppsPage(page) + const panel = key === null ? undefined : comfyWindows.get(key)?.panelView?.webContents + if (!panel || panel.isDestroyed()) return + const backdrop = await page + .capturePage() + .then((image) => image.toJPEG(BACKDROP_QUALITY)) + .catch(() => null) + panel.send(APPS_OUTPUT_CHANNEL, { ...outputs, backdrop }) +} + +function relayOutputAction(event: IpcMainEvent, input: unknown): void { + const found = entryForPanel(event.sender) + const action = outputAction(input) + if (!found || !action) return + const page = views.get(found[0])?.webContents + if (page && !page.isDestroyed()) page.send(APPS_OUTPUT_ACTION_CHANNEL, action) +} + function authState(): AppsAuthState { const status = getCloudSession().status() return status.signedIn ? { signedIn: true, email: status.email } : { signedIn: false } @@ -461,16 +491,23 @@ async function uploadImage(bytes: unknown, name: unknown): Promise<{ name: strin return { name: body.name } } -function handleFromApps( +function handleFromAppsPage( channel: string, - fn: (...args: A) => Promise | R + fn: (page: WebContents, ...args: A) => Promise | R ): void { ipcMain.handle(channel, async (event, ...args) => { if (!fromAppsPage(event)) throw new Error('Not allowed.') - return fn(...(args as A)) + return fn(event.sender, ...(args as A)) }) } +function handleFromApps( + channel: string, + fn: (...args: A) => Promise | R +): void { + handleFromAppsPage(channel, (_page, ...args: A) => fn(...args)) +} + function appsPages(): WebContents[] { return [...views.values()] .map((v) => v.webContents) @@ -481,6 +518,7 @@ export function registerAppsIpc(): void { ipcMain.on('comfy-apps:show', showApps) ipcMain.on('comfy-apps:hide', hideApps) ipcMain.handle(APPS_CATALOG_CHANNEL, () => listCatalogApps(APPS_URL)) + ipcMain.on('comfy-apps:output-action', relayOutputAction) initLocalComfy(appsPages) handleFromApps('comfy-apps:get-auth-state', authState) @@ -506,4 +544,5 @@ export function registerAppsIpc(): void { handleFromApps('comfy-apps:local-fetch', localFetch) handleFromApps('comfy-apps:local-download', localDownload) handleFromApps('comfy-apps:open-in-comfy', openInComfy) + handleFromAppsPage('comfy-apps:show-output', showOutput) } diff --git a/src/main/apps/outputs.test.ts b/src/main/apps/outputs.test.ts new file mode 100644 index 000000000..741deed6e --- /dev/null +++ b/src/main/apps/outputs.test.ts @@ -0,0 +1,60 @@ +// @vitest-environment node +import { describe, expect, it } from 'vitest' + +import { MAX_OUTPUTS, outputAction, outputRequest } from './outputs' + +const picture = (extra: Record = {}) => ({ + name: 'picture-1.png', + mimeType: 'image/png', + bytes: new Uint8Array([1, 2, 3]), + ...extra +}) + +describe('outputRequest', () => { + it('keeps the outputs and the one to show first', () => { + const request = outputRequest({ + items: [ + picture({ tags: ['This computer', 7, ' '], workflow: true, createdAt: 1_700_000_000_000 }), + picture({ name: 'clip.mp4', mimeType: 'video/mp4' }) + ], + index: 1 + }) + expect(request?.index).toBe(1) + expect(request?.items[0]).toMatchObject({ + name: 'picture-1.png', + tags: ['This computer'], + workflow: true, + createdAt: '2023-11-14T22:13:20.000Z' + }) + expect(request?.items[1]).toMatchObject({ workflow: false, createdAt: null, tags: [] }) + }) + + it('refuses outputs it cannot show', () => { + expect(outputRequest(null)).toBeNull() + expect(outputRequest({ items: [], index: 0 })).toBeNull() + expect(outputRequest({ items: [picture()], index: 1 })).toBeNull() + expect(outputRequest({ items: [picture()], index: -1 })).toBeNull() + expect(outputRequest({ items: [picture({ mimeType: 'text/html' })], index: 0 })).toBeNull() + expect(outputRequest({ items: [picture({ bytes: 'abc' })], index: 0 })).toBeNull() + expect(outputRequest({ items: [picture({ name: ' ' })], index: 0 })).toBeNull() + expect( + outputRequest({ items: Array.from({ length: MAX_OUTPUTS + 1 }, () => picture()), index: 0 }) + ).toBeNull() + }) +}) + +describe('outputAction', () => { + it('passes on a download or an open-workflow for one output', () => { + expect(outputAction({ action: 'download', index: 2 })).toEqual({ action: 'download', index: 2 }) + expect(outputAction({ action: 'open-workflow', index: 0 })).toEqual({ + action: 'open-workflow', + index: 0 + }) + }) + + it('drops anything else', () => { + expect(outputAction({ action: 'delete', index: 0 })).toBeNull() + expect(outputAction({ action: 'download', index: 1.5 })).toBeNull() + expect(outputAction('download')).toBeNull() + }) +}) diff --git a/src/main/apps/outputs.ts b/src/main/apps/outputs.ts new file mode 100644 index 000000000..b256470cf --- /dev/null +++ b/src/main/apps/outputs.ts @@ -0,0 +1,58 @@ +import type { AppOutputAction, AppOutputItem } from '../../types/ipc' + +export const MAX_OUTPUTS = 40 +export const MAX_OUTPUTS_BYTES = 500_000_000 +const MAX_TAGS = 8 +const MEDIA_TYPE = /^(image|video|audio)\/[\w.+-]{1,60}$/ + +function text(value: unknown, max: number): string | null { + return typeof value === 'string' && value.trim() !== '' ? value.trim().slice(0, max) : null +} + +function createdAt(value: unknown): string | null { + return typeof value === 'number' && Number.isFinite(value) && value > 0 + ? new Date(value).toISOString() + : null +} + +function outputItem(value: unknown): AppOutputItem | null { + if (!value || typeof value !== 'object') return null + const item = value as Record + const name = text(item['name'], 200) + const mimeType = item['mimeType'] + const bytes = item['bytes'] + if (!name || typeof mimeType !== 'string' || !MEDIA_TYPE.test(mimeType)) return null + if (!(bytes instanceof Uint8Array)) return null + const tags = Array.isArray(item['tags']) + ? item['tags'].map((tag) => text(tag, 40)).filter((tag): tag is string => tag !== null) + : [] + return { + name, + mimeType, + bytes: bytes as Uint8Array, + tags: tags.slice(0, MAX_TAGS), + workflow: item['workflow'] === true, + createdAt: createdAt(item['createdAt']) + } +} + +export function outputRequest(input: unknown): { items: AppOutputItem[]; index: number } | null { + if (!input || typeof input !== 'object') return null + const { items, index } = input as { items?: unknown; index?: unknown } + if (!Array.isArray(items) || items.length === 0 || items.length > MAX_OUTPUTS) return null + const parsed = items.map(outputItem) + if (parsed.some((item) => item === null)) return null + const outputs = parsed as AppOutputItem[] + const total = outputs.reduce((sum, item) => sum + item.bytes.byteLength, 0) + if (total > MAX_OUTPUTS_BYTES) return null + if (typeof index !== 'number' || !Number.isInteger(index) || index < 0) return null + return index < outputs.length ? { items: outputs, index } : null +} + +export function outputAction(input: unknown): AppOutputAction | null { + if (!input || typeof input !== 'object') return null + const { action, index } = input as { action?: unknown; index?: unknown } + if (action !== 'download' && action !== 'open-workflow') return null + if (typeof index !== 'number' || !Number.isInteger(index) || index < 0) return null + return { action, index } +} diff --git a/src/main/apps/wiring.test.ts b/src/main/apps/wiring.test.ts index a81fad95b..8237576e4 100644 --- a/src/main/apps/wiring.test.ts +++ b/src/main/apps/wiring.test.ts @@ -15,7 +15,7 @@ const exposed = all( /^ {2}(\w+):/gm ) const invoked = all(preload, /ipcRenderer\.invoke\('([\w:-]+)'/g) -const handled = all(main, /handleFromApps\('([\w:-]+)'/g) +const handled = all(main, /handleFromApps(?:Page)?\('([\w:-]+)'/g) describe('Apps bridge wiring', () => { it('getInfo names exactly the calls the page gets', () => { diff --git a/src/preload/api.ts b/src/preload/api.ts index 068a03416..daef0ea08 100644 --- a/src/preload/api.ts +++ b/src/preload/api.ts @@ -116,6 +116,13 @@ export function buildElectronApi(): ElectronApi { ipcRenderer.on('comfy-apps:app-open', handler) return () => ipcRenderer.removeListener('comfy-apps:app-open', handler) }, + onAppsOutput: (callback) => { + const handler = (_event: IpcRendererEvent, outputs: unknown) => + callback(outputs as Parameters[0]) + ipcRenderer.on('comfy-apps:output', handler) + return () => ipcRenderer.removeListener('comfy-apps:output', handler) + }, + appsOutputAction: (action) => ipcRenderer.send('comfy-apps:output-action', action), getBuildStorageSnapshot: () => ipcRenderer.invoke('comfy-window:build-storage-snapshot'), resolveStartupRestoreReveal: (result) => ipcRenderer.send('comfy-window:startup-restore-reveal', { result }), diff --git a/src/preload/appsPreload.ts b/src/preload/appsPreload.ts index fa281bede..11ee200b9 100644 --- a/src/preload/appsPreload.ts +++ b/src/preload/appsPreload.ts @@ -25,7 +25,9 @@ const CALLS = [ 'onLocalEvent', 'localDownload', 'cancelRun', - 'openInComfy' + 'openInComfy', + 'showOutput', + 'onOutputAction' ] contextBridge.exposeInMainWorld('comfyDesktopApps', { @@ -61,6 +63,14 @@ contextBridge.exposeInMainWorld('comfyDesktopApps', { ipcRenderer.invoke('comfy-apps:local-fetch', req), localDownload: (req: { url: string; folder: string; name: string }) => ipcRenderer.invoke('comfy-apps:local-download', req), + showOutput: (request: unknown) => ipcRenderer.invoke('comfy-apps:show-output', request), + onOutputAction: (callback: (action: unknown) => void) => { + const listener = (_e: IpcRendererEvent, msg: unknown) => callback(msg) + ipcRenderer.on('comfy-apps:output-action', listener) + return () => { + ipcRenderer.removeListener('comfy-apps:output-action', listener) + } + }, onLocalEvent: (callback: (event: unknown) => void) => { const listener = (_e: IpcRendererEvent, msg: unknown) => callback(msg) ipcRenderer.on('comfy-apps:local-event', listener) diff --git a/src/renderer/panel.html b/src/renderer/panel.html index e1bf9958d..5b61b88b7 100644 --- a/src/renderer/panel.html +++ b/src/renderer/panel.html @@ -5,7 +5,7 @@ Comfy Desktop — Panel