From 1fdf7366478758fa7d8e9aad87fa3677ea9ea415 Mon Sep 17 00:00:00 2001 From: PabloWiedemann Date: Mon, 16 Nov 2026 12:16:49 -0800 Subject: [PATCH 1/6] feat(apps): show where an app result is saved, and open it from there Each item an app page sends to window.comfyDesktopOutputs.showOutput may now say where it is saved, with the shapes the website pages already send: - savedOn: 'cloud' shows "Saved in Comfy Cloud assets" and View in Assets. View in Assets closes the app and opens the Assets page on Comfy Cloud with the newest Cloud file of that name open. It does this for this visit only: the saved Comfy Cloud | This computer choice (comfy.desktop.assets.place) is kept, and the file is opened once. The page sends no Cloud asset id, so the file is matched by name. When no Cloud file has that name, the Assets page says so in a short note instead of opening nothing. - savedOn: 'computer' with folder (an absolute path, display only) shows "Saved in" with Show in folder, which goes back to the page as a new show-in-folder output action. - savedOn: 'computer' with comfyFile ({ filename, subfolder, type: 'output' }) lets Desktop find the real file ComfyUI saved. Main joins it to the output folder of the build the page runs on, resolves links, and uses it only when the file is inside that build's folder and inside the output folders Assets may show, and has exactly the bytes the page sent. The dialog then shows that folder, and Show in folder reveals the file from main (checked again on click) instead of going to the page. A page-sent folder is never shown for an item with a comfyFile. Main drops a folder that is not absolute or has hidden characters, and a comfyFile whose filename has a separator, . or .., or hidden characters, or whose subfolder is absolute or has .., . or empty parts. Only the newest showOutput request from a page is shown, so a slow file lookup cannot replace a newer one. The "Saved in" section and Show in folder button are the ones the Assets folders view added to the output dialog. The output action listener moved to registerAppsOutputsHandlers next to showOutput. This rebuilds #2023 and #2050 on main's Apps page. Left out from #2050: the byte scan of the whole output folder for results with no comfyFile, and the per-preview turn on output actions. --- locales/en.json | 5 +- locales/zh.json | 5 +- src/main/apps/appPageView.test.ts | 29 ++++ src/main/apps/appPageView.ts | 21 ++- src/main/apps/outputFiles.test.ts | 85 +++++++++++ src/main/apps/outputFiles.ts | 39 +++++ src/main/apps/outputRequest.test.ts | 83 ++++++++++- src/main/apps/outputRequest.ts | 79 +++++++++- src/main/lib/ipc/registerAppsHandlers.ts | 13 +- .../ipc/registerAppsOutputsHandlers.test.ts | 136 +++++++++++++++++- .../lib/ipc/registerAppsOutputsHandlers.ts | 37 ++++- src/main/lib/outputFolders.test.ts | 78 ++++++++++ src/main/lib/outputFolders.ts | 32 +++++ src/renderer/src/panel/AppPageHost.test.ts | 55 +++++++ src/renderer/src/panel/AppPageHost.vue | 14 +- src/renderer/src/panel/AppsView.test.ts | 11 ++ src/renderer/src/panel/AppsView.vue | 12 +- src/renderer/src/panel/AssetsView.test.ts | 77 ++++++++++ src/renderer/src/panel/AssetsView.vue | 59 +++++++- src/renderer/src/panel/OutputDetailDialog.vue | 30 +++- src/renderer/src/panel/PanelApp.test.ts | 33 ++++- src/renderer/src/panel/PanelApp.vue | 10 ++ src/types/comfyDesktopBridge.ts | 43 +++++- src/types/ipc.ts | 4 +- 24 files changed, 939 insertions(+), 51 deletions(-) create mode 100644 src/main/apps/outputFiles.test.ts create mode 100644 src/main/apps/outputFiles.ts diff --git a/locales/en.json b/locales/en.json index a4300ce03..7bb1620dc 100644 --- a/locales/en.json +++ b/locales/en.json @@ -98,6 +98,8 @@ "showInFinder": "Show in Finder", "showInExplorer": "Show in File Explorer", "showInFolder": "Show in folder", + "viewInAssets": "View in Assets", + "notFoundInCloud": "Couldn't find {name} in your Comfy Cloud assets. It may have a different name here.", "copy": "Copy", "copyFailed": "Couldn't copy asset", "delete": "Delete", @@ -121,7 +123,8 @@ "zoom": "Zoom", "zoomLevel": "Zoom: {level}", "openWorkflow": "Open workflow", - "savedIn": "Saved in" + "savedIn": "Saved in", + "cloudAssets": "Comfy Cloud assets" }, "kindSingular": { "image": "Image", diff --git a/locales/zh.json b/locales/zh.json index e3aba74eb..880c00577 100644 --- a/locales/zh.json +++ b/locales/zh.json @@ -98,6 +98,8 @@ "showInFinder": "在 Finder 中显示", "showInExplorer": "在文件资源管理器中显示", "showInFolder": "在文件夹中显示", + "viewInAssets": "在资产中查看", + "notFoundInCloud": "在你的 Comfy Cloud 资产中找不到 {name}。它在这里的名称可能不同。", "copy": "复制", "copyFailed": "无法复制资产", "delete": "删除", @@ -121,7 +123,8 @@ "zoom": "缩放", "zoomLevel": "缩放:{level}", "openWorkflow": "打开工作流", - "savedIn": "保存位置" + "savedIn": "保存位置", + "cloudAssets": "Comfy Cloud 资产" }, "kindSingular": { "image": "图片", diff --git a/src/main/apps/appPageView.test.ts b/src/main/apps/appPageView.test.ts index 736b19656..ef23aab40 100644 --- a/src/main/apps/appPageView.test.ts +++ b/src/main/apps/appPageView.test.ts @@ -73,6 +73,7 @@ import { loadedAppPage, sendAppOutputAction, showAppOutputs, + shownOutputFile, showAppPage } from './appPageView' import { trackFromAppsPage } from '../lib/ipc/registerAppsTelemetryHandlers' @@ -1090,6 +1091,34 @@ describe('outputs an app page shows', () => { expect(sentToPage()).toEqual([]) }) + it('names the file Desktop found for a shown output, only while that page is loaded', () => { + expect(shownOutputFile(panelContents(), 0)).toBeNull() + + showAppOutputs(pageContents(), loadedAppPage(pageContents())!, OUTPUTS, [ + null, + '/out/cutout-2.png' + ]) + + expect(shownOutputFile(panelContents(), 0)).toBeNull() + expect(shownOutputFile(panelContents(), 1)).toBe('/out/cutout-2.png') + expect(shownOutputFile(panelContents(), 2)).toBeNull() + expect(shownOutputFile(new FakeContents() as unknown as WebContents, 1)).toBeNull() + + finishLoading() + + expect(shownOutputFile(panelContents(), 1)).toBeNull() + }) + + it('sends Show in folder back to the page like any other action', () => { + shownFromPage() + + sendAppOutputAction(panelContents(), { action: 'show-in-folder', index: 1 }) + + expect(sentToPage()).toEqual([ + [APP_OUTPUT_ACTION_CHANNEL, { action: 'show-in-folder', index: 1 }] + ]) + }) + it('takes actions only from the panel of the window the page is in', () => { shownFromPage() diff --git a/src/main/apps/appPageView.ts b/src/main/apps/appPageView.ts index 059e33d1d..368b7744c 100644 --- a/src/main/apps/appPageView.ts +++ b/src/main/apps/appPageView.ts @@ -39,6 +39,7 @@ export interface LoadedAppPage { interface ShownOutputs { page: LoadedAppPage count: number + files: readonly (string | null)[] } interface HostedPage { @@ -437,13 +438,14 @@ function isStillLoaded(hosted: HostedPage, page: LoadedAppPage): boolean { export function showAppOutputs( contents: WebContents, sentFrom: LoadedAppPage, - outputs: AppOutputs + outputs: AppOutputs, + files: readonly (string | null)[] = [] ): boolean { for (const [windowKey, hosted] of hostedByWindow) { if (hosted.view.webContents !== contents) continue const panel = panelOf(windowKey) if (!panel || !isOnScreen(hosted) || !isStillLoaded(hosted, sentFrom)) return false - hosted.outputs = { page: sentFrom, count: outputs.items.length } + hosted.outputs = { page: sentFrom, count: outputs.items.length, files } if (comfyWindows.get(windowKey)?.window.isFocused()) panel.focus() panel.send(APP_OUTPUTS_CHANNEL, sentFrom.appId, outputs) return true @@ -451,12 +453,21 @@ export function showAppOutputs( return false } -export function sendAppOutputAction(panel: WebContents, action: AppOutputAction): void { +function shownOutputsOf(panel: WebContents): { hosted: HostedPage; shown: ShownOutputs } | null { const host = hostOf(panel) const hosted = host && hostedFor(host) const shown = hosted?.outputs - if (!hosted || !shown || action.index >= shown.count || !isStillLoaded(hosted, shown.page)) return - hosted.view.webContents.send(APP_OUTPUT_ACTION_CHANNEL, action) + return hosted && shown && isStillLoaded(hosted, shown.page) ? { hosted, shown } : null +} + +export function shownOutputFile(panel: WebContents, index: number): string | null { + return shownOutputsOf(panel)?.shown.files[index] ?? null +} + +export function sendAppOutputAction(panel: WebContents, action: AppOutputAction): void { + const found = shownOutputsOf(panel) + if (!found || action.index >= found.shown.count) return + found.hosted.view.webContents.send(APP_OUTPUT_ACTION_CHANNEL, action) } export function _resetForTest(): void { diff --git a/src/main/apps/outputFiles.test.ts b/src/main/apps/outputFiles.test.ts new file mode 100644 index 000000000..6d747c3df --- /dev/null +++ b/src/main/apps/outputFiles.test.ts @@ -0,0 +1,85 @@ +import path from 'path' +import { describe, expect, it, vi } from 'vitest' + +vi.mock('../installations', () => ({ get: vi.fn() })) +vi.mock('../lib/outputFolders', () => ({ comfyOutputPath: vi.fn() })) +vi.mock('./localComfy', () => ({ pageBuildId: vi.fn() })) + +import { locateOutputFiles } from './outputFiles' +import type { FindOutputFile } from './outputFiles' +import type { RequestedOutput } from './outputRequest' + +const FOUND = path.join(path.sep, 'outputs', 'apps', 'cutout_00001_.png') + +function output(extra: Partial = {}): RequestedOutput { + return { + name: 'cutout.png', + mimeType: 'image/png', + bytes: new Uint8Array([1]), + tags: [], + workflow: false, + ...extra + } +} + +const cutoutFile = { filename: 'cutout_00001_.png', subfolder: 'apps' } + +describe('locateOutputFiles', () => { + it('shows the folder of a ComfyUI file Desktop found, and never sends the reference on', async () => { + const find = vi.fn(async () => FOUND) + + const located = await locateOutputFiles( + { items: [output({ savedOn: 'computer', comfyFile: cutoutFile })], index: 0 }, + find + ) + + expect(find).toHaveBeenCalledExactlyOnceWith(cutoutFile, new Uint8Array([1])) + expect(located.outputs.items[0]).toEqual( + output({ savedOn: 'computer', folder: path.dirname(FOUND) }) + ) + expect(located.files).toEqual([FOUND]) + }) + + it('shows no folder for a ComfyUI file Desktop did not find, even one the page sent', async () => { + const located = await locateOutputFiles( + { + items: [ + output({ savedOn: 'computer', comfyFile: cutoutFile, folder: '/Users/me/out' }), + output({ savedOn: 'computer', comfyFile: cutoutFile }) + ], + index: 1 + }, + vi.fn().mockResolvedValueOnce(null).mockRejectedValueOnce(new Error('gone')) + ) + + expect(located.outputs).toEqual({ + items: [output({ savedOn: 'computer' }), output({ savedOn: 'computer' })], + index: 1 + }) + expect(located.files).toEqual([null, null]) + }) + + it('keeps the folder a page saved an output in, and looks for nothing without a ComfyUI file', async () => { + const find = vi.fn() + + const located = await locateOutputFiles( + { + items: [ + output({ savedOn: 'computer', folder: '/Users/me/out' }), + output({ savedOn: 'cloud' }), + output() + ], + index: 0 + }, + find + ) + + expect(find).not.toHaveBeenCalled() + expect(located.outputs.items).toEqual([ + output({ savedOn: 'computer', folder: '/Users/me/out' }), + output({ savedOn: 'cloud' }), + output() + ]) + expect(located.files).toEqual([null, null, null]) + }) +}) diff --git a/src/main/apps/outputFiles.ts b/src/main/apps/outputFiles.ts new file mode 100644 index 000000000..2c780a88e --- /dev/null +++ b/src/main/apps/outputFiles.ts @@ -0,0 +1,39 @@ +import path from 'path' +import type { WebContents } from 'electron' + +import type { AppOutput, AppOutputs } from '../../types/ipc' +import * as installations from '../installations' +import { comfyOutputPath } from '../lib/outputFolders' +import { pageBuildId } from './localComfy' +import type { ComfyOutputFile, OutputRequest } from './outputRequest' + +export type FindOutputFile = (file: ComfyOutputFile, bytes: Uint8Array) => Promise + +export interface LocatedOutputs { + outputs: AppOutputs + files: (string | null)[] +} + +export async function locateOutputFiles( + request: OutputRequest, + find: FindOutputFile +): Promise { + const files = await Promise.all( + request.items.map((item) => + item.comfyFile ? find(item.comfyFile, item.bytes).catch(() => null) : null + ) + ) + const items = request.items.map(({ comfyFile, folder, ...output }, i): AppOutput => { + const file = files[i] + if (file) return { ...output, folder: path.dirname(file) } + return folder && !comfyFile ? { ...output, folder } : output + }) + return { outputs: { items, index: request.index }, files } +} + +export async function findInPageBuild(page: WebContents): Promise { + const buildId = pageBuildId(page) + const build = buildId ? await installations.get(buildId) : null + if (!build) return async () => null + return (file, bytes) => comfyOutputPath(build, file, bytes) +} diff --git a/src/main/apps/outputRequest.test.ts b/src/main/apps/outputRequest.test.ts index 7632e9cb6..9d96a0411 100644 --- a/src/main/apps/outputRequest.test.ts +++ b/src/main/apps/outputRequest.test.ts @@ -35,7 +35,7 @@ describe('readOutputRequest', () => { it('keeps what the Apps pages send today and drops the fields Desktop does not show', () => { const request = readOutputRequest({ - items: [picture({ tags: [], workflow: false, savedOn: 'computer', folder: '/tmp' })], + items: [picture({ tags: [], workflow: false, savedOn: 'computer', folder: '/tmp', size: 3 })], index: 0 }) @@ -44,10 +44,83 @@ describe('readOutputRequest', () => { mimeType: 'image/png', bytes: new Uint8Array([1, 2, 3]), tags: [], - workflow: false + workflow: false, + savedOn: 'computer', + folder: '/tmp' }) }) + it('keeps where each output is saved, with a folder and a ComfyUI file only for this computer', () => { + const comfyFile = { filename: 'cutout_00001_.png', subfolder: 'apps\\cutout', type: 'output' } + const request = readOutputRequest({ + items: [ + picture({ savedOn: 'cloud', folder: '/Users/me/out', comfyFile }), + picture({ savedOn: 'computer', folder: 'C:\\Users\\me\\out' }), + picture({ savedOn: 'computer', comfyFile }), + picture({ savedOn: 'computer' }), + picture({ savedOn: 'phone', folder: '/Users/me/out' }) + ], + index: 0 + }) + + expect( + request?.items.map(({ savedOn, folder, comfyFile }) => ({ savedOn, folder, comfyFile })) + ).toEqual([ + { savedOn: 'cloud', folder: undefined, comfyFile: undefined }, + { savedOn: 'computer', folder: 'C:\\Users\\me\\out', comfyFile: undefined }, + { + savedOn: 'computer', + folder: undefined, + comfyFile: { filename: 'cutout_00001_.png', subfolder: 'apps/cutout' } + }, + { savedOn: 'computer', folder: undefined, comfyFile: undefined }, + { savedOn: undefined, folder: undefined, comfyFile: undefined } + ]) + }) + + it('drops a folder that is not an absolute path or has hidden characters', () => { + const folders = ['out', './out', '~/out', '/Users/me/\u202eout', '/Users/me/\nout', 7] + const request = readOutputRequest({ + items: folders.map((folder) => picture({ savedOn: 'computer', folder })), + index: 0 + }) + + expect(request?.items.map((item) => item.folder)).toEqual(folders.map(() => undefined)) + }) + + it('drops a ComfyUI file that could name something outside the output folder', () => { + const file = (extra: Record) => ({ + filename: 'cutout.png', + subfolder: '', + type: 'output', + ...extra + }) + const refused = [ + file({ type: 'temp' }), + file({ type: undefined }), + file({ filename: 'apps/cutout.png' }), + file({ filename: '..\\cutout.png' }), + file({ filename: '..' }), + file({ filename: '' }), + file({ filename: ' cutout.png' }), + file({ filename: 'cut\u202eout.png' }), + file({ filename: 'n'.repeat(256) }), + file({ subfolder: '/etc' }), + file({ subfolder: 'C:\\Windows' }), + file({ subfolder: 'apps/../..' }), + file({ subfolder: 'apps//cutout' }), + file({ subfolder: './apps' }), + file({ subfolder: 7 }), + 'cutout.png' + ] + const request = readOutputRequest({ + items: refused.map((comfyFile) => picture({ savedOn: 'computer', comfyFile })), + index: 0 + }) + + expect(request?.items.map((item) => item.comfyFile)).toEqual(refused.map(() => undefined)) + }) + it('cuts long names and tags, and keeps at most eight tags', () => { const request = readOutputRequest({ items: [ @@ -105,7 +178,11 @@ describe('readOutputRequest', () => { }) describe('readOutputAction', () => { - it('passes on a download or an open-workflow for one output', () => { + it('passes on a download, an open-workflow or a show-in-folder for one output', () => { + expect(readOutputAction({ action: 'show-in-folder', index: 1 })).toEqual({ + action: 'show-in-folder', + index: 1 + }) expect(readOutputAction({ action: 'download', index: 2 })).toEqual({ action: 'download', index: 2 diff --git a/src/main/apps/outputRequest.ts b/src/main/apps/outputRequest.ts index 01a42b5b1..ff5a800a3 100644 --- a/src/main/apps/outputRequest.ts +++ b/src/main/apps/outputRequest.ts @@ -1,10 +1,31 @@ import type { AppOutput, AppOutputAction, AppOutputs } from '../../types/ipc' +export interface ComfyOutputFile { + filename: string + subfolder: string +} + +export interface RequestedOutput extends AppOutput { + comfyFile?: ComfyOutputFile +} + +export interface OutputRequest extends Omit { + items: RequestedOutput[] +} + export const MAX_OUTPUTS = 40 export const MAX_OUTPUTS_BYTES = 100_000_000 const MAX_NAME_LENGTH = 200 const MAX_TAGS = 8 const MAX_TAG_LENGTH = 40 +const MAX_FOLDER_LENGTH = 1024 +const MAX_FILENAME_LENGTH = 255 +const ABSOLUTE_LOCAL_PATH = /^(\/|[A-Za-z]:[\\/])/ +const PATH_SEPARATOR = /[\\/]/ +const BIDI_CONTROL = /[\u202a-\u202e\u2066-\u2069]/ +const FIRST_PRINTABLE_CODE = 32 +const DELETE_CODE = 127 +const ACTIONS: readonly unknown[] = ['download', 'open-workflow', 'show-in-folder'] const SHOWN_MEDIA_TYPE = /^(image\/(png|jpeg|webp|gif|avif)|video\/(mp4|webm|quicktime)|audio\/(mpeg|mp4|wav|x-wav|ogg|webm|flac|aac))$/ @@ -12,6 +33,10 @@ function isRecord(value: unknown): value is Record { return typeof value === 'object' && value !== null && !Array.isArray(value) } +function isAction(value: unknown): value is AppOutputAction['action'] { + return ACTIONS.includes(value) +} + function isIndex(value: unknown): value is number { return typeof value === 'number' && Number.isInteger(value) && value >= 0 } @@ -28,7 +53,49 @@ function readTags(value: unknown): string[] { .filter((tag): tag is string => tag !== null) } -function readOutput(value: unknown): AppOutput | null { +function hasHiddenCharacters(value: string): boolean { + return ( + BIDI_CONTROL.test(value) || + Array.from(value).some((char) => { + const code = char.charCodeAt(0) + return code < FIRST_PRINTABLE_CODE || code === DELETE_CODE + }) + ) +} + +function readFolder(value: unknown): string | null { + if (typeof value !== 'string' || value.length > MAX_FOLDER_LENGTH) return null + if (hasHiddenCharacters(value)) return null + return ABSOLUTE_LOCAL_PATH.test(value) ? value : null +} + +function isPathPart(value: string): boolean { + return value !== '' && value !== '.' && value !== '..' && value.trim() === value +} + +function readComfyFile(value: unknown): ComfyOutputFile | null { + if (!isRecord(value)) return null + const { filename, subfolder = '', type } = value + if (type !== 'output' || typeof filename !== 'string' || typeof subfolder !== 'string') { + return null + } + if (filename.length > MAX_FILENAME_LENGTH || PATH_SEPARATOR.test(filename)) return null + if (!isPathPart(filename) || hasHiddenCharacters(filename + subfolder)) return null + if (subfolder.length > MAX_FOLDER_LENGTH || ABSOLUTE_LOCAL_PATH.test(subfolder)) return null + const parts = subfolder === '' ? [] : subfolder.split(PATH_SEPARATOR) + return parts.every(isPathPart) ? { filename, subfolder: parts.join('/') } : null +} + +function readSavedPlace(value: Record): Partial { + const savedOn = value['savedOn'] + if (savedOn === 'cloud') return { savedOn } + if (savedOn !== 'computer') return {} + const folder = readFolder(value['folder']) + const comfyFile = readComfyFile(value['comfyFile']) + return { savedOn, ...(folder ? { folder } : {}), ...(comfyFile ? { comfyFile } : {}) } +} + +function readOutput(value: unknown): RequestedOutput | null { if (!isRecord(value)) return null const name = trimmed(value['name'], MAX_NAME_LENGTH) const { mimeType, bytes } = value @@ -39,18 +106,19 @@ function readOutput(value: unknown): AppOutput | null { mimeType, bytes: bytes as Uint8Array, tags: readTags(value['tags']), - workflow: value['workflow'] === true + workflow: value['workflow'] === true, + ...readSavedPlace(value) } } -export function readOutputRequest(raw: unknown): AppOutputs | null { +export function readOutputRequest(raw: unknown): OutputRequest | null { if (!isRecord(raw)) return null const { items, index } = raw if (!Array.isArray(items) || items.length === 0 || items.length > MAX_OUTPUTS) return null if (!isIndex(index) || index >= items.length) return null const outputs = Array.from(items, readOutput) if (outputs.some((output) => output === null)) return null - const shown = outputs as AppOutput[] + const shown = outputs as RequestedOutput[] const sentBytes = shown.reduce((sum, output) => sum + output.bytes.buffer.byteLength, 0) return sentBytes > MAX_OUTPUTS_BYTES ? null : { items: shown, index } } @@ -58,6 +126,5 @@ export function readOutputRequest(raw: unknown): AppOutputs | null { export function readOutputAction(raw: unknown): AppOutputAction | null { if (!isRecord(raw)) return null const { action, index } = raw - if (action !== 'download' && action !== 'open-workflow') return null - return isIndex(index) ? { action, index } : null + return isAction(action) && isIndex(index) ? { action, index } : null } diff --git a/src/main/lib/ipc/registerAppsHandlers.ts b/src/main/lib/ipc/registerAppsHandlers.ts index 013cefdc4..3e7168cb6 100644 --- a/src/main/lib/ipc/registerAppsHandlers.ts +++ b/src/main/lib/ipc/registerAppsHandlers.ts @@ -1,14 +1,8 @@ import { ipcMain } from 'electron' -import { - captureAppPage, - hideAppPage, - sendAppOutputAction, - showAppPage -} from '../../apps/appPageView' +import { captureAppPage, hideAppPage, showAppPage } from '../../apps/appPageView' import { listApps } from '../../apps/appsCatalog' import { areAppsEnabled } from '../../apps/appsConfig' -import { readOutputAction } from '../../apps/outputRequest' import { isPanelSender } from '../../host/registry' export function registerAppsHandlers(): void { @@ -26,9 +20,4 @@ export function registerAppsHandlers(): void { ipcMain.handle('apps:capture-page', (event) => captureAppPage(event.sender)) ipcMain.on('apps:hide-page', (event) => hideAppPage(event.sender)) - - ipcMain.on('apps:output-action', (event, raw: unknown) => { - const action = readOutputAction(raw) - if (action) sendAppOutputAction(event.sender, action) - }) } diff --git a/src/main/lib/ipc/registerAppsOutputsHandlers.test.ts b/src/main/lib/ipc/registerAppsOutputsHandlers.test.ts index 4df358035..1209cc05e 100644 --- a/src/main/lib/ipc/registerAppsOutputsHandlers.test.ts +++ b/src/main/lib/ipc/registerAppsOutputsHandlers.test.ts @@ -1,6 +1,8 @@ import { beforeEach, describe, expect, it, vi } from 'vitest' type Handler = (event: unknown, request: unknown) => Promise +type Listener = (event: unknown, raw: unknown) => void +type FindFile = (file: unknown, bytes: Uint8Array) => Promise interface LoadedPage { appId: string document: number @@ -8,25 +10,44 @@ interface LoadedPage { const mocks = vi.hoisted(() => ({ handlers: new Map(), + listeners: new Map(), + findFile: vi.fn(async () => null), + shownFile: null as string | null, + sendAppOutputAction: vi.fn(), + shownOutputFile: vi.fn((_panel: unknown, _index: number) => mocks.shownFile), + revealOutputFile: vi.fn(async (_file: string) => true), isAppsPage: true, appsEnabled: true, page: { appId: 'remove-background', document: 1 } as LoadedPage | null, - showAppOutputs: vi.fn((_contents: unknown, _sentFrom: unknown, _outputs: unknown) => true) + showAppOutputs: vi.fn( + (_contents: unknown, _sentFrom: unknown, _outputs: unknown, _files: unknown) => true + ) })) vi.mock('electron', () => ({ ipcMain: { - handle: (channel: string, handler: Handler) => mocks.handlers.set(channel, handler) + handle: (channel: string, handler: Handler) => mocks.handlers.set(channel, handler), + on: (channel: string, listener: Listener) => mocks.listeners.set(channel, listener) } })) vi.mock('../../apps/appsConfig', () => ({ areAppsEnabled: async () => mocks.appsEnabled })) vi.mock('../../apps/appsPages', () => ({ isAppsPageSender: () => mocks.isAppsPage })) vi.mock('../../apps/appPageView', () => ({ loadedAppPage: () => mocks.page, - showAppOutputs: mocks.showAppOutputs + showAppOutputs: mocks.showAppOutputs, + sendAppOutputAction: mocks.sendAppOutputAction, + shownOutputFile: mocks.shownOutputFile +})) +vi.mock('../../apps/localComfy', () => ({ pageBuildId: () => 'apps-build' })) +vi.mock('../../installations', () => ({ get: async (id: string) => ({ id }) })) +vi.mock('../outputFolders', () => ({ + comfyOutputPath: (_build: unknown, file: unknown, bytes: Uint8Array) => + mocks.findFile(file, bytes), + revealOutputFile: mocks.revealOutputFile })) import { + APPS_OUTPUT_ACTION_CHANNEL, APPS_OUTPUTS_SHOW_CHANNEL, registerAppsOutputsHandlers } from './registerAppsOutputsHandlers' @@ -49,6 +70,9 @@ function showOutput(request: unknown = REQUEST): Promise { beforeEach(() => { vi.clearAllMocks() mocks.handlers.clear() + mocks.listeners.clear() + mocks.shownFile = null + mocks.findFile.mockResolvedValue(null) mocks.isAppsPage = true mocks.appsEnabled = true mocks.page = { appId: 'remove-background', document: 1 } @@ -78,8 +102,57 @@ describe('showOutput from the hosted Apps page', () => { } ], index: 0 - } + }, + [null] + ) + }) + + it('shows where Desktop found the ComfyUI file the page named, and keeps the path for Show in folder', async () => { + mocks.findFile.mockResolvedValue('/outputs/apps/cutout_00001_.png') + + await showOutput({ + items: [ + { + ...REQUEST.items[0], + savedOn: 'computer', + comfyFile: { filename: 'cutout_00001_.png', subfolder: 'apps', type: 'output' } + } + ], + index: 0 + }) + + expect(mocks.findFile).toHaveBeenCalledExactlyOnceWith( + { filename: 'cutout_00001_.png', subfolder: 'apps' }, + new Uint8Array([1]) ) + const [, , outputs, files] = mocks.showAppOutputs.mock.calls[0]! + expect(outputs).toMatchObject({ items: [{ savedOn: 'computer', folder: '/outputs/apps' }] }) + expect(files).toEqual(['/outputs/apps/cutout_00001_.png']) + }) + + it('shows nothing from a request that a newer one replaced while Desktop looked for its files', async () => { + let finishFirst: (file: string | null) => void = () => {} + mocks.findFile.mockImplementationOnce( + () => new Promise((resolve) => (finishFirst = resolve)) + ) + const withFile = { + items: [ + { + ...REQUEST.items[0], + savedOn: 'computer', + comfyFile: { filename: 'a.png', type: 'output' } + } + ], + index: 0 + } + + const first = showOutput(withFile) + await vi.waitFor(() => expect(mocks.findFile).toHaveBeenCalledTimes(1)) + expect(await showOutput()).toBe(true) + finishFirst('/outputs/a.png') + + expect(await first).toBe(false) + expect(mocks.showAppOutputs).toHaveBeenCalledTimes(1) }) it('says so when Desktop does not show them', async () => { @@ -110,3 +183,58 @@ describe('showOutput from the hosted Apps page', () => { expect(mocks.showAppOutputs).not.toHaveBeenCalled() }) }) + +describe('an output action from the panel', () => { + const PANEL_EVENT = { sender: {} } + + function takeAction(raw: unknown): void { + const listener = mocks.listeners.get(APPS_OUTPUT_ACTION_CHANNEL) + if (!listener) throw new Error('No listener for output actions') + listener(PANEL_EVENT, raw) + } + + it('listens on the channel the panel sends on', () => { + expect(APPS_OUTPUT_ACTION_CHANNEL).toBe('apps:output-action') + }) + + it('shows a file Desktop found in its folder itself, and does not send it to the page', () => { + mocks.shownFile = '/outputs/apps/cutout_00001_.png' + + takeAction({ action: 'show-in-folder', index: 0 }) + + expect(mocks.shownOutputFile).toHaveBeenCalledWith(PANEL_EVENT.sender, 0) + expect(mocks.revealOutputFile).toHaveBeenCalledExactlyOnceWith( + '/outputs/apps/cutout_00001_.png' + ) + expect(mocks.sendAppOutputAction).not.toHaveBeenCalled() + }) + + it('sends Show in folder to the page when Desktop found no file for that output', () => { + takeAction({ action: 'show-in-folder', index: 0 }) + + expect(mocks.revealOutputFile).not.toHaveBeenCalled() + expect(mocks.sendAppOutputAction).toHaveBeenCalledExactlyOnceWith(PANEL_EVENT.sender, { + action: 'show-in-folder', + index: 0 + }) + }) + + it('sends Download to the page even when Desktop found the file', () => { + mocks.shownFile = '/outputs/apps/cutout_00001_.png' + + takeAction({ action: 'download', index: 0 }) + + expect(mocks.revealOutputFile).not.toHaveBeenCalled() + expect(mocks.sendAppOutputAction).toHaveBeenCalledExactlyOnceWith(PANEL_EVENT.sender, { + action: 'download', + index: 0 + }) + }) + + it('drops an action it cannot read', () => { + takeAction({ action: 'delete', index: 0 }) + + expect(mocks.revealOutputFile).not.toHaveBeenCalled() + expect(mocks.sendAppOutputAction).not.toHaveBeenCalled() + }) +}) diff --git a/src/main/lib/ipc/registerAppsOutputsHandlers.ts b/src/main/lib/ipc/registerAppsOutputsHandlers.ts index 9edf5f5d8..26e05d9b7 100644 --- a/src/main/lib/ipc/registerAppsOutputsHandlers.ts +++ b/src/main/lib/ipc/registerAppsOutputsHandlers.ts @@ -1,17 +1,33 @@ import { ipcMain } from 'electron' -import type { IpcMainInvokeEvent } from 'electron' +import type { IpcMainEvent, IpcMainInvokeEvent, WebContents } from 'electron' -import { loadedAppPage, showAppOutputs } from '../../apps/appPageView' +import { + loadedAppPage, + sendAppOutputAction, + showAppOutputs, + shownOutputFile +} from '../../apps/appPageView' import { areAppsEnabled } from '../../apps/appsConfig' import { isAppsPageSender } from '../../apps/appsPages' -import { readOutputRequest } from '../../apps/outputRequest' +import { findInPageBuild, locateOutputFiles } from '../../apps/outputFiles' +import { readOutputAction, readOutputRequest } from '../../apps/outputRequest' +import { revealOutputFile } from '../outputFolders' export const APPS_OUTPUTS_SHOW_CHANNEL = 'apps-outputs:show' +export const APPS_OUTPUT_ACTION_CHANNEL = 'apps:output-action' + +const latestRequest = new WeakMap() async function isFromAppsPage(event: IpcMainInvokeEvent): Promise { return isAppsPageSender(event.sender, event.senderFrame) && (await areAppsEnabled()) } +function takeTurn(page: WebContents): () => boolean { + const turn = (latestRequest.get(page) ?? 0) + 1 + latestRequest.set(page, turn) + return () => latestRequest.get(page) === turn +} + export async function showOutputFromAppsPage( event: IpcMainInvokeEvent, request: unknown @@ -20,9 +36,22 @@ export async function showOutputFromAppsPage( if (sentFrom === null || !(await isFromAppsPage(event))) return false const outputs = readOutputRequest(request) if (!outputs) throw new Error('Desktop cannot show these outputs.') - return showAppOutputs(event.sender, sentFrom, outputs) + const isLatest = takeTurn(event.sender) + const located = await locateOutputFiles(outputs, await findInPageBuild(event.sender)) + if (!isLatest()) return false + return showAppOutputs(event.sender, sentFrom, located.outputs, located.files) +} + +export function takeOutputAction(event: IpcMainEvent, raw: unknown): void { + const action = readOutputAction(raw) + if (!action) return + const file = + action.action === 'show-in-folder' ? shownOutputFile(event.sender, action.index) : null + if (file) void revealOutputFile(file).catch(() => false) + else sendAppOutputAction(event.sender, action) } export function registerAppsOutputsHandlers(): void { ipcMain.handle(APPS_OUTPUTS_SHOW_CHANNEL, showOutputFromAppsPage) + ipcMain.on(APPS_OUTPUT_ACTION_CHANNEL, takeOutputAction) } diff --git a/src/main/lib/outputFolders.test.ts b/src/main/lib/outputFolders.test.ts index fa9dd1c4c..a5a2d1550 100644 --- a/src/main/lib/outputFolders.test.ts +++ b/src/main/lib/outputFolders.test.ts @@ -84,6 +84,7 @@ import type { InstallationRecord } from '../installations' import { MAX_LOCAL_ASSETS, THUMBNAIL_WAIT_MS, + comfyOutputPath, copyOutputImage, hasOutputFolder, revealOutputFile, @@ -333,6 +334,83 @@ describe('outputFilePath', () => { }) }) +describe('comfyOutputPath', () => { + const CUTOUT = Buffer.from('cutout bytes') + const appsBuild = (): InstallationRecord => + install('Apps', { useSharedOutput: false, outputDir: ownDir }) + const cutout = { filename: 'cutout_00001_.png', subfolder: 'apps/remove-background' } + + it("finds the file ComfyUI named in the build's own output folder, or in the shared one", async () => { + const own = path.join(ownDir, 'apps', 'remove-background', 'cutout_00001_.png') + const shared = path.join(sharedDir, 'cutout_00001_.png') + write(own, CUTOUT) + write(shared, CUTOUT) + + expect(await comfyOutputPath(appsBuild(), cutout, new Uint8Array(CUTOUT))).toBe(own) + expect( + await comfyOutputPath( + install('Test Instance'), + { filename: 'cutout_00001_.png', subfolder: '' }, + new Uint8Array(CUTOUT) + ) + ).toBe(shared) + }) + + it('finds nothing for a missing file, or a file without exactly the bytes the page shows', async () => { + write(path.join(ownDir, 'apps', 'remove-background', 'cutout_00001_.png'), CUTOUT) + + expect( + await comfyOutputPath( + appsBuild(), + { ...cutout, filename: 'gone.png' }, + new Uint8Array(CUTOUT) + ) + ).toBeNull() + expect( + await comfyOutputPath(appsBuild(), cutout, new Uint8Array(Buffer.from('cutout bytez'))), + 'same size, other bytes' + ).toBeNull() + expect( + await comfyOutputPath(appsBuild(), cutout, new Uint8Array(Buffer.from('cutout'))), + 'other size' + ).toBeNull() + }) + + it("refuses links out of the build's output folder, even into another build's", async () => { + write(path.join(outsideDir, 'secret.png'), CUTOUT) + write(path.join(sharedDir, 'shared.png'), CUTOUT) + fs.symlinkSync(path.join(outsideDir, 'secret.png'), path.join(ownDir, 'secret.png')) + fs.symlinkSync(path.join(sharedDir, 'shared.png'), path.join(ownDir, 'shared.png')) + const bytes = new Uint8Array(CUTOUT) + + expect( + await comfyOutputPath(appsBuild(), { filename: 'secret.png', subfolder: '' }, bytes) + ).toBeNull() + expect( + await comfyOutputPath(appsBuild(), { filename: 'shared.png', subfolder: '' }, bytes) + ).toBeNull() + expect( + await comfyOutputPath( + appsBuild(), + { filename: 'shared.png', subfolder: '../shared-output' }, + bytes + ) + ).toBeNull() + }) + + it('finds nothing for Cloud or a build that manages its own paths', async () => { + write(path.join(sharedDir, 'cutout_00001_.png'), CUTOUT) + const file = { filename: 'cutout_00001_.png', subfolder: '' } + + expect( + await comfyOutputPath(install('Cloud', { sourceId: 'cloud' }), file, new Uint8Array(CUTOUT)) + ).toBeNull() + expect( + await comfyOutputPath(install('Old', { sourceId: 'desktop' }), file, new Uint8Array(CUTOUT)) + ).toBeNull() + }) +}) + describe('serveOutputFile', () => { it('serves the file itself when the OS thumbnail is slow, then the thumbnail once it is made', async () => { write(path.join(sharedDir, 'slow.png')) diff --git a/src/main/lib/outputFolders.ts b/src/main/lib/outputFolders.ts index 5598a5444..844ab2390 100644 --- a/src/main/lib/outputFolders.ts +++ b/src/main/lib/outputFolders.ts @@ -1,3 +1,4 @@ +import fs from 'fs' import fsp from 'fs/promises' import path from 'path' import { pathToFileURL } from 'url' @@ -5,6 +6,7 @@ import { ipcMain, nativeImage, net, protocol, shell } from 'electron' import * as installations from '../installations' import type { InstallationRecord } from '../installations' import * as settings from '../settings' +import type { ComfyOutputFile } from '../apps/outputRequest' import { assetKind } from './assets' import { copyImageToClipboard } from './clipboardImage' import { mediaFactsFromFile } from './mediaFacts' @@ -31,6 +33,8 @@ const STATS_AT_ONCE = 32 const ROOTS_FRESH_MS = 5000 const MAX_LINUX_THUMBNAIL_SOURCE_BYTES = 40 * 1024 * 1024 const SERVED_KINDS = new Set(['image', 'video', 'audio']) +const READ_WITHOUT_FOLLOWING = + fs.constants.O_RDONLY | (fs.constants.O_NOFOLLOW ?? 0) | (fs.constants.O_NONBLOCK ?? 0) const thumbnails = new Map() const thumbnailsInFlight = new Map>() @@ -104,6 +108,34 @@ export async function outputFilePath(target: string): Promise { return stat?.isFile() ? file : null } +async function hasSameBytes(file: string, bytes: Uint8Array): Promise { + const stat = await fsp.stat(file).catch(() => null) + if (!stat?.isFile() || stat.size !== bytes.byteLength) return false + const handle = await fsp.open(file, READ_WITHOUT_FOLLOWING).catch(() => null) + if (!handle) return false + try { + const content = await handle.readFile() + return Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength).equals(content) + } catch { + return false + } finally { + await handle.close().catch(() => {}) + } +} + +export async function comfyOutputPath( + inst: InstallationRecord, + file: ComfyOutputFile, + bytes: Uint8Array +): Promise { + const dir = outputDirFor(inst, sharedOutputDir()) + const root = dir ? await realDir(dir) : null + if (!root) return null + const real = await allowedPath(path.join(root, file.subfolder, file.filename)) + if (!real || !isInsideRoot(real, root)) return null + return (await hasSameBytes(real, bytes)) ? real : null +} + export async function revealOutputFile(target: string): Promise { const file = await outputFilePath(target) if (!file) return false diff --git a/src/renderer/src/panel/AppPageHost.test.ts b/src/renderer/src/panel/AppPageHost.test.ts index f42d43dae..00fa24dcc 100644 --- a/src/renderer/src/panel/AppPageHost.test.ts +++ b/src/renderer/src/panel/AppPageHost.test.ts @@ -369,6 +369,61 @@ describe('AppPageHost outputs', () => { expect(outputDialog()).toBeNull() }) + it('says where a result on this computer is saved, and sends Show in folder to the page', async () => { + await mountHost() + const [first, second] = TWO_CUTOUTS.items + await showOutputs('remove-background', { + items: [first!, { ...second!, savedOn: 'computer', folder: '/Users/me/ComfyUI/output/apps' }], + index: 1 + }) + + expect(inOutputDialog('output-detail-saved-in')?.textContent).toContain('apps') + expect(inOutputDialog('output-detail-saved-in')?.textContent).toContain( + '/Users/me/ComfyUI/output' + ) + expect(inOutputDialog('output-detail-view-in-assets')).toBeNull() + + inOutputDialog('output-detail-show-in-folder')!.click() + await flushPromises() + + expect(sendAppOutputAction).toHaveBeenCalledExactlyOnceWith({ + action: 'show-in-folder', + index: 1 + }) + expect(outputDialog()).not.toBeNull() + }) + + it('shows no saved place for a result on this computer whose folder Desktop does not know', async () => { + await mountHost() + const [first, second] = TWO_CUTOUTS.items + await showOutputs('remove-background', { + items: [first!, { ...second!, savedOn: 'computer' }], + index: 1 + }) + + expect(inOutputDialog('output-detail-saved-in')).toBeNull() + expect(inOutputDialog('output-detail-show-in-folder')).toBeNull() + }) + + it('says a Cloud result is saved in Comfy Cloud assets, and View in Assets asks for it by name', async () => { + const wrapper = await mountHost() + const [first, second] = TWO_CUTOUTS.items + await showOutputs('remove-background', { + items: [first!, { ...second!, savedOn: 'cloud' }], + index: 1 + }) + + expect(inOutputDialog('output-detail-saved-in')?.textContent).toContain('Comfy Cloud assets') + expect(inOutputDialog('output-detail-show-in-folder')).toBeNull() + + inOutputDialog('output-detail-view-in-assets')!.click() + await flushPromises() + + expect(wrapper.emitted('view-in-assets')).toEqual([['cutout-2.png']]) + expect(sendAppOutputAction).not.toHaveBeenCalled() + expect(outputDialog()).toBeNull() + }) + it('brings the app back with the keyboard once the dialog closes, and lets go of the files', async () => { const revoke = vi.spyOn(URL, 'revokeObjectURL') await mountHost() diff --git a/src/renderer/src/panel/AppPageHost.vue b/src/renderer/src/panel/AppPageHost.vue index 42eb0917d..1de40478a 100644 --- a/src/renderer/src/panel/AppPageHost.vue +++ b/src/renderer/src/panel/AppPageHost.vue @@ -21,7 +21,7 @@ const { appId, title } = defineProps<{ title: string }>() -const emit = defineEmits<{ close: [] }>() +const emit = defineEmits<{ close: []; 'view-in-assets': [name: string] }>() const { t } = useI18n() @@ -114,7 +114,9 @@ function showOutputs(shown: AppOutputs): void { tags: output.tags, previewUrl: URL.createObjectURL(new Blob([output.bytes], { type: output.mimeType })), thumbnailUrl: null, - workflow: output.workflow + workflow: output.workflow, + savedIn: output.savedOn === 'computer' ? (output.folder ?? null) : null, + inCloud: output.savedOn === 'cloud' })) outputIndex.value = shown.index outputsShown.value += 1 @@ -131,6 +133,12 @@ function sendOutputAction(action: AppOutputAction['action'], index: number): voi if (action === 'open-workflow') closeOutputs() } +function viewInAssets(index: number): void { + const name = outputs.value?.[index]?.name + releaseOutputs() + if (name) emit('view-in-assets', name) +} + function retry(): void { status.value = 'loading' retrying = true @@ -254,6 +262,8 @@ onBeforeUnmount(() => { @close="closeOutputs" @download="sendOutputAction('download', $event)" @open-workflow="sendOutputAction('open-workflow', $event)" + @show-in-folder="sendOutputAction('show-in-folder', $event)" + @view-in-assets="viewInAssets" /> diff --git a/src/renderer/src/panel/AppsView.test.ts b/src/renderer/src/panel/AppsView.test.ts index c24cd244e..90c5ac4e7 100644 --- a/src/renderer/src/panel/AppsView.test.ts +++ b/src/renderer/src/panel/AppsView.test.ts @@ -4,6 +4,7 @@ import { flushPromises, mount } from '@vue/test-utils' import '../assets/main.css' import AppsView from './AppsView.vue' +import AppPageHost from './AppPageHost.vue' import type { AppCard, AppPagePlacement, AppPageStatus } from '../types/ipc' const FOUR_COLUMN_PAGE_WIDTH = 1172 @@ -233,6 +234,16 @@ describe('AppsView', () => { expect(hideAppPage).toHaveBeenCalled() }) + it("passes on the Cloud file an app's output dialog asks to see in Assets", async () => { + const wrapper = await mountApps() + await wrapper.get('[data-testid="app-card-remove-background"]').trigger('click') + await flushPromises() + + wrapper.findComponent(AppPageHost).vm.$emit('view-in-assets', 'cutout.png') + + expect(wrapper.emitted('view-in-assets')).toEqual([['cutout.png']]) + }) + it('returns to the cards when Apps is picked in the sidebar again', async () => { const wrapper = await mountApps() await wrapper.get('[data-testid="app-card-genjutsu"]').trigger('click') diff --git a/src/renderer/src/panel/AppsView.vue b/src/renderer/src/panel/AppsView.vue index adf7996a3..ee265addd 100644 --- a/src/renderer/src/panel/AppsView.vue +++ b/src/renderer/src/panel/AppsView.vue @@ -17,7 +17,10 @@ const { revisit = 0 } = defineProps<{ revisit?: number }>() const startWith = defineModel('startWith', { default: null }) -const emit = defineEmits<{ 'app-open-change': [open: boolean] }>() +const emit = defineEmits<{ + 'app-open-change': [open: boolean] + 'view-in-assets': [name: string] +}>() const { t } = useI18n() @@ -222,7 +225,12 @@ onBeforeUnmount(() => {
- +
diff --git a/src/renderer/src/panel/AssetsView.test.ts b/src/renderer/src/panel/AssetsView.test.ts index e16d55316..e2f3bf33d 100644 --- a/src/renderer/src/panel/AssetsView.test.ts +++ b/src/renderer/src/panel/AssetsView.test.ts @@ -848,6 +848,83 @@ describe('AssetsView', () => { } }) + describe('a file an app asks to see', () => { + async function mountWithFocus(files: AssetSummary[]) { + window.localStorage.setItem('comfy.desktop.assets.place', 'computer') + getAuthStatus.mockResolvedValue({ signedIn: true }) + listAssets.mockResolvedValue(files) + const installationStore = useInstallationStore() + installationStore.installations = [cloudBuild('cloud')] + installationStore.loading = false + const wrapper = mount(AssetsView, { attachTo: page, props: { focusName: 'cutout.png' } }) + await flushPromises() + return wrapper + } + + it('opens on Comfy Cloud with the newest file of that name open, once, and keeps the saved place', async () => { + const wrapper = await mountWithFocus([ + asset('old', 'cutout.png', 'image', { createdAt: '2026-11-01T00:00:00Z' }), + asset('new', 'cutout.png', 'image', { createdAt: '2026-11-02T00:00:00Z' }), + asset('other', 'other.png', 'image', { createdAt: '2026-11-03T00:00:00Z' }) + ]) + + expect(wrapper.emitted('focus-used')).toHaveLength(1) + expect(listAssets).toHaveBeenCalledWith('cloud') + expect(listOutputFolders).not.toHaveBeenCalled() + expect(viewerTitle()).toBe('cutout.png') + expect( + viewer()?.querySelector('[aria-current="true"]')?.getAttribute('data-testid'), + 'the newer of the two cutouts, after the newest file overall' + ).toBe('output-detail-thumb-1') + expect(window.localStorage.getItem('comfy.desktop.assets.place')).toBe('computer') + }) + + it('says so on Comfy Cloud when the file is not there, and drops the note once the user picks a place', async () => { + const wrapper = await mountWithFocus([asset('other', 'other.png', 'image')]) + + expect(wrapper.emitted('focus-used')).toHaveLength(1) + expect(assetNames(wrapper)).toEqual(['other.png']) + expect(viewer()).toBeNull() + expect(text(wrapper, 'assets-not-found')).toBe( + "Couldn't find cutout.png in your Comfy Cloud assets. It may have a different name here." + ) + + await choose(wrapper, 'computer') + await choose(wrapper, 'cloud') + + expect(wrapper.find('[data-testid="assets-not-found"]').exists()).toBe(false) + }) + + it('shows no note when the file opened', async () => { + await mountWithFocus([asset('new', 'cutout.png', 'image')]) + expect(viewerTitle()).toBe('cutout.png') + expect(document.querySelector('[data-testid="assets-not-found"]')).toBeNull() + }) + + it('shows the load error instead of a note when the Cloud list fails', async () => { + listAssets.mockRejectedValue(new Error('offline')) + window.localStorage.setItem('comfy.desktop.assets.place', 'computer') + getAuthStatus.mockResolvedValue({ signedIn: true }) + const installationStore = useInstallationStore() + installationStore.installations = [cloudBuild('cloud')] + installationStore.loading = false + const wrapper = mount(AssetsView, { attachTo: page, props: { focusName: 'cutout.png' } }) + await flushPromises() + + expect(wrapper.get('[data-testid="assets-empty"] h2').text()).toBe("Couldn't load assets") + expect(wrapper.find('[data-testid="assets-not-found"]').exists()).toBe(false) + }) + + it('remembers a place the user picks after that', async () => { + const wrapper = await mountWithFocus([]) + + await choose(wrapper, 'computer') + await choose(wrapper, 'cloud') + + expect(window.localStorage.getItem('comfy.desktop.assets.place')).toBe('cloud') + }) + }) + it('lists the Cloud build of the workspace the user moves to', async () => { listAssets.mockResolvedValue([asset('t1', 'team.png', 'image')]) const wrapper = await mountCloud([ diff --git a/src/renderer/src/panel/AssetsView.vue b/src/renderer/src/panel/AssetsView.vue index 89d7ee822..bdd2f20fb 100644 --- a/src/renderer/src/panel/AssetsView.vue +++ b/src/renderer/src/panel/AssetsView.vue @@ -103,7 +103,12 @@ const PLACEHOLDER_TINT = { file: 'bg-[linear-gradient(168deg,rgb(200_211_222/0.09),rgb(255_255_255/0.02))] text-[rgb(160_166_175)]' } as const -const { installationId = '' } = defineProps<{ installationId?: string }>() +const { installationId = '', focusName = null } = defineProps<{ + installationId?: string + focusName?: string | null +}>() + +const emit = defineEmits<{ 'focus-used': [] }>() const { t } = useI18n() const modal = useModal() @@ -126,8 +131,10 @@ const sortOrder = useLocalStorage('comfy.desktop.assets.sort', 'newes const showName = useLocalStorage('comfy.desktop.assets.showName', true) const showDetails = useLocalStorage('comfy.desktop.assets.showDetails', true) const savedPlace = useLocalStorage('comfy.desktop.assets.place', 'computer') -const pickedPlace = ref(null) +const pickedPlace = ref(focusName ? 'cloud' : null) const cloudChosenHere = ref(false) +const pendingFocus = ref(null) +const notFoundName = ref(null) let windowFolderOpened = false const trail = ref([]) const outputFolders = ref(null) @@ -168,6 +175,10 @@ const cloudBuild = computed( ) ?? null ) +const cloudListable = computed( + () => buildsKnown.value && authStore.isSignedIn && cloudBuild.value !== null +) + const currentFolder = computed(() => place.value === 'computer' ? (trail.value.at(-1) ?? null) : null ) @@ -180,6 +191,7 @@ const placeOptions = computed(() => [ function choosePlace(next: Place): void { pickedPlace.value = next + notFoundName.value = null savedPlace.value = next cloudChosenHere.value = next === 'cloud' } @@ -427,11 +439,13 @@ async function loadAssets(userAsked = false): Promise { outputFolders.value = loaded.folders subfolders.value = loaded.subfolders truncated.value = loaded.truncated + openPendingFocus() } catch { if (current !== requestId) return assets.value = [] subfolders.value = [] failed.value = true + openPendingFocus() } finally { if (current === requestId) loading.value = false } @@ -471,6 +485,39 @@ function refresh(): void { const detailKey = ref(null) +function newestNamed(name: string): GalleryAsset | null { + return visibleAssets.value + .filter((asset) => asset.name === name) + .reduce( + (newest, asset) => (newest && createdMs(newest) >= createdMs(asset) ? newest : asset), + null + ) +} + +function openPendingFocus(): void { + const name = pendingFocus.value + if (!name || (place.value === 'cloud' && !cloudListable.value)) return + pendingFocus.value = null + if (place.value !== 'cloud' || failed.value) return + const asset = newestNamed(name) + if (asset) openDetail(asset) + else notFoundName.value = name +} + +watch( + () => focusName, + (name) => { + if (!name) return + emit('focus-used') + const cloudShown = place.value === 'cloud' && !loading.value + pendingFocus.value = name + cloudChosenHere.value = true + pickedPlace.value = 'cloud' + if (cloudShown) openPendingFocus() + }, + { immediate: true } +) + const detailIndex = computed({ get: () => { if (detailKey.value === null) return null @@ -873,6 +920,14 @@ function extensionOf(name: string): string { />
+

+ {{ t('assets.notFoundInCloud', { name: notFoundName }) }} +

    () const { t, locale } = useI18n() @@ -291,11 +294,22 @@ useEventListener(window, 'keydown', (event: KeyboardEvent) => {
-
+
{{ t('assets.detail.savedIn') }}
-
+ + {{ t('assets.detail.cloudAssets') }} + +
{{ savedFolder.name }} {{ savedFolder.parent @@ -339,6 +353,18 @@ useEventListener(window, 'keydown', (event: KeyboardEvent) => {
diff --git a/src/renderer/src/panel/PanelApp.test.ts b/src/renderer/src/panel/PanelApp.test.ts index 4f0d51894..918e60419 100644 --- a/src/renderer/src/panel/PanelApp.test.ts +++ b/src/renderer/src/panel/PanelApp.test.ts @@ -63,7 +63,12 @@ vi.mock('../views/ChooserView.vue', () => ({ } })) vi.mock('./AssetsView.vue', () => ({ - default: { name: 'AssetsView', template: '
' } + default: { + name: 'AssetsView', + props: ['focusName'], + emits: ['focus-used'], + template: '
' + } })) vi.mock('./BuildDetailsView.vue', () => ({ default: { @@ -149,6 +154,7 @@ vi.mock('../views/MigrateConfirmTakeover.vue', () => ({ import { mount, flushPromises } from '@vue/test-utils' import { createPinia, setActivePinia } from 'pinia' import PanelApp from './PanelApp.vue' +import AppsView from './AppsView.vue' import { en } from '../lib/i18nMessages' import { __resetLauncherPrefsForTest } from '../composables/useLauncherPrefs' import { useOverlay } from '../composables/useOverlay' @@ -1598,6 +1604,31 @@ describe('PanelApp', () => { ]) }) + it('opens Assets on the Cloud file an app asks to see, and passes the file on only once', async () => { + window.history.replaceState({}, '', '/?panel=chooser&firstUseCompleted=true') + vi.mocked(window.api.getAppsEnabled).mockResolvedValue(true) + const wrapper = mountPanel() + await flushPromises() + await wrapper.get('[data-testid="app-sidebar-apps"]').trigger('click') + await flushPromises() + + wrapper.findComponent(AppsView).vm.$emit('view-in-assets', 'cutout.png') + await flushPromises() + + expect(wrapper.find('[data-testid="apps-view"]').exists()).toBe(false) + expect(wrapper.get('[data-testid="app-sidebar-assets"]').attributes('aria-current')).toBe( + 'page' + ) + expect(wrapper.get('[data-testid="assets-view"]').attributes('data-focus-name')).toBe( + 'cutout.png' + ) + + wrapper.findComponent({ name: 'AssetsView' }).vm.$emit('focus-used') + await flushPromises() + + expect(wrapper.get('[data-testid="assets-view"]').attributes('data-focus-name')).toBeUndefined() + }) + it('does not record a sidebar page open for See all apps on Home', async () => { window.history.replaceState({}, '', '/?panel=chooser&firstUseCompleted=true') vi.mocked(window.api.getAppsEnabled).mockResolvedValue(true) diff --git a/src/renderer/src/panel/PanelApp.vue b/src/renderer/src/panel/PanelApp.vue index 19aba253c..c8cff699f 100644 --- a/src/renderer/src/panel/PanelApp.vue +++ b/src/renderer/src/panel/PanelApp.vue @@ -210,6 +210,7 @@ async function showHome(): Promise { const appsVisits = ref(0) const appIsOpen = ref(false) +const assetsFocusName = ref(null) const appPickedOnHome = ref(null) function openAppFromHome(app: AppCard): void { @@ -227,8 +228,14 @@ function handleSidebarClick(page: DashboardPage): void { handleSidebarNavigate(page) } +function viewInAssets(name: string): void { + handleSidebarNavigate('assets') + assetsFocusName.value = name +} + function handleSidebarNavigate(page: DashboardPage): void { closeBuildDetails() + assetsFocusName.value = null if (page === 'apps') appsVisits.value += 1 if (page === 'home' || page === 'apps' || page === 'chooser' || page === 'assets') dashboardHomePage.value = page @@ -528,10 +535,13 @@ onUnmounted(() => { v-model:start-with="appPickedOnHome" :revisit="appsVisits" @app-open-change="appIsOpen = $event" + @view-in-assets="viewInAssets" /> ): void } +/** + * A file ComfyUI saved in its output folder, named as a run's history names + * it. `filename` has no folder in it, and `subfolder` is relative, with no + * `.` or `..` parts. Only `type: 'output'` is kept. + */ +export interface ComfyDesktopOutputFile { + filename: string + subfolder?: string + type: 'output' +} + /** * One output a hosted page asks Desktop to show. `mimeType` is one of * `image/png`, `image/jpeg`, `image/webp`, `image/gif`, `image/avif`, @@ -337,6 +348,11 @@ export interface ComfyDesktopHostedTelemetryBridge { * `audio/aac`. `name` is at most 200 characters. Desktop keeps the first 8 * `tags`, each cut to 40 characters, and offers Open workflow only when * `workflow` is true. + * + * `savedOn` says where the output is saved. For `cloud`, Desktop shows + * "Saved in Comfy Cloud assets" and View in Assets, which opens Desktop's + * Assets page on Comfy Cloud with the newest file of that `name` open. For + * `computer`, Desktop shows the folder it is saved in and Show in folder. */ export interface ComfyDesktopOutput { name: string @@ -344,6 +360,20 @@ export interface ComfyDesktopOutput { bytes: Uint8Array tags?: string[] workflow?: boolean + savedOn?: 'cloud' | 'computer' + /** + * For `computer` without `comfyFile`: the absolute path of the folder the + * page saved the output in. Desktop only shows it, and Show in folder comes + * back to the page on `onOutputAction`. + */ + folder?: string + /** + * For `computer`: the file ComfyUI saved for this output. Desktop looks for + * it in the output folder of the build the page runs on, and uses it only + * when it has exactly the output's `bytes`. Desktop then shows its folder + * and shows the file in its folder itself; otherwise it shows no folder. + */ + comfyFile?: ComfyDesktopOutputFile } /** At most 40 outputs and 100 MB of bytes in all, and the index of the one to show first. */ @@ -354,10 +384,12 @@ export interface ComfyDesktopShowOutputRequest { /** * What the person picked in Desktop's output dialog for the output at `index` - * of the page's last `showOutput` request: download it, or open its workflow. + * of the page's last `showOutput` request: download it, open its workflow, or + * show it in its `folder`. Desktop does not send `show-in-folder` for an + * output whose `comfyFile` it found, because it shows that file itself. */ export interface ComfyDesktopOutputAction { - action: 'download' | 'open-workflow' + action: 'download' | 'open-workflow' | 'show-in-folder' index: number } @@ -365,12 +397,13 @@ export interface ComfyDesktopOutputAction { * Desktop's output dialog, for a Comfy page hosted in Desktop's Apps view. * Desktop exposes it to that page as `window.comfyDesktopOutputs`. Desktop * shows the outputs over the Apps view and does not save or open anything - * itself: Download and Open workflow come back to the page on + * itself: Download, Open workflow and Show in folder come back to the page on * `onOutputAction`, only while the page that showed the outputs is still the - * app's loaded page. + * app's loaded page. Desktop itself only shows a found `comfyFile` in its + * folder, and opens the Assets page for View in Assets. */ export interface ComfyDesktopHostedOutputsBridge { - /** Resolves true once Desktop shows the outputs, and false when the app is not on screen. Rejects a request Desktop cannot show. */ + /** Resolves true once Desktop shows the outputs, and false when the app is not on screen or a newer request from the page replaced this one. Rejects a request Desktop cannot show. */ showOutput(request: ComfyDesktopShowOutputRequest): Promise onOutputAction(callback: (action: ComfyDesktopOutputAction) => void): () => void } diff --git a/src/types/ipc.ts b/src/types/ipc.ts index 86f87730e..cc35f966b 100644 --- a/src/types/ipc.ts +++ b/src/types/ipc.ts @@ -157,6 +157,8 @@ export interface AppOutput { bytes: Uint8Array tags: string[] workflow: boolean + savedOn?: 'cloud' | 'computer' + folder?: string } export interface AppOutputs { @@ -165,7 +167,7 @@ export interface AppOutputs { } export interface AppOutputAction { - action: 'download' | 'open-workflow' + action: 'download' | 'open-workflow' | 'show-in-folder' index: number } From d93432f8411403c2e1d7c6f3cd29134de4cea9d2 Mon Sep 17 00:00:00 2001 From: PabloWiedemann Date: Mon, 16 Nov 2026 13:51:05 -0800 Subject: [PATCH 2/6] refactor(apps): leave the ComfyUI file path check to the output folder lookup The lookup already resolves the path, refuses anything outside the build's output folder and needs the exact bytes, so the request only checks the shape of comfyFile. Read the output action inline as before. --- src/main/apps/outputRequest.test.ts | 17 +++-------------- src/main/apps/outputRequest.ts | 26 ++++++-------------------- 2 files changed, 9 insertions(+), 34 deletions(-) diff --git a/src/main/apps/outputRequest.test.ts b/src/main/apps/outputRequest.test.ts index 9d96a0411..addbdd0ee 100644 --- a/src/main/apps/outputRequest.test.ts +++ b/src/main/apps/outputRequest.test.ts @@ -51,7 +51,7 @@ describe('readOutputRequest', () => { }) it('keeps where each output is saved, with a folder and a ComfyUI file only for this computer', () => { - const comfyFile = { filename: 'cutout_00001_.png', subfolder: 'apps\\cutout', type: 'output' } + const comfyFile = { filename: 'cutout_00001_.png', subfolder: 'apps/cutout', type: 'output' } const request = readOutputRequest({ items: [ picture({ savedOn: 'cloud', folder: '/Users/me/out', comfyFile }), @@ -88,7 +88,7 @@ describe('readOutputRequest', () => { expect(request?.items.map((item) => item.folder)).toEqual(folders.map(() => undefined)) }) - it('drops a ComfyUI file that could name something outside the output folder', () => { + it('drops a ComfyUI file that is not a ComfyUI output', () => { const file = (extra: Record) => ({ filename: 'cutout.png', subfolder: '', @@ -98,18 +98,7 @@ describe('readOutputRequest', () => { const refused = [ file({ type: 'temp' }), file({ type: undefined }), - file({ filename: 'apps/cutout.png' }), - file({ filename: '..\\cutout.png' }), - file({ filename: '..' }), - file({ filename: '' }), - file({ filename: ' cutout.png' }), - file({ filename: 'cut\u202eout.png' }), - file({ filename: 'n'.repeat(256) }), - file({ subfolder: '/etc' }), - file({ subfolder: 'C:\\Windows' }), - file({ subfolder: 'apps/../..' }), - file({ subfolder: 'apps//cutout' }), - file({ subfolder: './apps' }), + file({ filename: 7 }), file({ subfolder: 7 }), 'cutout.png' ] diff --git a/src/main/apps/outputRequest.ts b/src/main/apps/outputRequest.ts index ff5a800a3..f31ff8b39 100644 --- a/src/main/apps/outputRequest.ts +++ b/src/main/apps/outputRequest.ts @@ -19,13 +19,10 @@ const MAX_NAME_LENGTH = 200 const MAX_TAGS = 8 const MAX_TAG_LENGTH = 40 const MAX_FOLDER_LENGTH = 1024 -const MAX_FILENAME_LENGTH = 255 const ABSOLUTE_LOCAL_PATH = /^(\/|[A-Za-z]:[\\/])/ -const PATH_SEPARATOR = /[\\/]/ const BIDI_CONTROL = /[\u202a-\u202e\u2066-\u2069]/ const FIRST_PRINTABLE_CODE = 32 const DELETE_CODE = 127 -const ACTIONS: readonly unknown[] = ['download', 'open-workflow', 'show-in-folder'] const SHOWN_MEDIA_TYPE = /^(image\/(png|jpeg|webp|gif|avif)|video\/(mp4|webm|quicktime)|audio\/(mpeg|mp4|wav|x-wav|ogg|webm|flac|aac))$/ @@ -33,10 +30,6 @@ function isRecord(value: unknown): value is Record { return typeof value === 'object' && value !== null && !Array.isArray(value) } -function isAction(value: unknown): value is AppOutputAction['action'] { - return ACTIONS.includes(value) -} - function isIndex(value: unknown): value is number { return typeof value === 'number' && Number.isInteger(value) && value >= 0 } @@ -69,21 +62,12 @@ function readFolder(value: unknown): string | null { return ABSOLUTE_LOCAL_PATH.test(value) ? value : null } -function isPathPart(value: string): boolean { - return value !== '' && value !== '.' && value !== '..' && value.trim() === value -} - function readComfyFile(value: unknown): ComfyOutputFile | null { if (!isRecord(value)) return null const { filename, subfolder = '', type } = value - if (type !== 'output' || typeof filename !== 'string' || typeof subfolder !== 'string') { - return null - } - if (filename.length > MAX_FILENAME_LENGTH || PATH_SEPARATOR.test(filename)) return null - if (!isPathPart(filename) || hasHiddenCharacters(filename + subfolder)) return null - if (subfolder.length > MAX_FOLDER_LENGTH || ABSOLUTE_LOCAL_PATH.test(subfolder)) return null - const parts = subfolder === '' ? [] : subfolder.split(PATH_SEPARATOR) - return parts.every(isPathPart) ? { filename, subfolder: parts.join('/') } : null + return type === 'output' && typeof filename === 'string' && typeof subfolder === 'string' + ? { filename, subfolder } + : null } function readSavedPlace(value: Record): Partial { @@ -126,5 +110,7 @@ export function readOutputRequest(raw: unknown): OutputRequest | null { export function readOutputAction(raw: unknown): AppOutputAction | null { if (!isRecord(raw)) return null const { action, index } = raw - return isAction(action) && isIndex(index) ? { action, index } : null + if (action !== 'download' && action !== 'open-workflow' && action !== 'show-in-folder') + return null + return isIndex(index) ? { action, index } : null } From d27d01f4be663decd319e608f7de61108a52ab95 Mon Sep 17 00:00:00 2001 From: PabloWiedemann Date: Mon, 16 Nov 2026 14:16:37 -0800 Subject: [PATCH 3/6] fix(apps): cap the length of a ComfyUI file path, and test the containment --- src/main/apps/outputRequest.test.ts | 4 +++- src/main/apps/outputRequest.ts | 10 +++++----- src/main/lib/outputFolders.test.ts | 23 +++++++++++++++++++++++ 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/src/main/apps/outputRequest.test.ts b/src/main/apps/outputRequest.test.ts index 57e4446d0..b34472ba5 100644 --- a/src/main/apps/outputRequest.test.ts +++ b/src/main/apps/outputRequest.test.ts @@ -88,7 +88,7 @@ describe('readOutputRequest', () => { expect(request?.items.map((item) => item.folder)).toEqual(folders.map(() => undefined)) }) - it('drops a ComfyUI file that is not a ComfyUI output', () => { + it('drops a ComfyUI file that is not a ComfyUI output, or has a very long path', () => { const file = (extra: Record) => ({ filename: 'cutout.png', subfolder: '', @@ -100,6 +100,8 @@ describe('readOutputRequest', () => { file({ type: undefined }), file({ filename: 7 }), file({ subfolder: 7 }), + file({ filename: 'n'.repeat(1025) }), + file({ subfolder: 's'.repeat(1020) }), 'cutout.png' ] const request = readOutputRequest({ diff --git a/src/main/apps/outputRequest.ts b/src/main/apps/outputRequest.ts index cc9374eb8..86ac77182 100644 --- a/src/main/apps/outputRequest.ts +++ b/src/main/apps/outputRequest.ts @@ -18,7 +18,7 @@ export const MAX_OUTPUTS_BYTES = 100_000_000 const MAX_NAME_LENGTH = 200 const MAX_TAGS = 8 const MAX_TAG_LENGTH = 40 -const MAX_FOLDER_LENGTH = 1024 +const MAX_PATH_LENGTH = 1024 const ABSOLUTE_LOCAL_PATH = /^(\/|[A-Za-z]:[\\/])/ const BIDI_CONTROL = /[\u202a-\u202e\u2066-\u2069]/ const FIRST_PRINTABLE_CODE = 32 @@ -58,7 +58,7 @@ function readTags(value: unknown): string[] { } function readFolder(value: unknown): string | null { - if (typeof value !== 'string' || value.length > MAX_FOLDER_LENGTH) return null + if (typeof value !== 'string' || value.length > MAX_PATH_LENGTH) return null if (hasHiddenCharacters(value)) return null return ABSOLUTE_LOCAL_PATH.test(value) ? value : null } @@ -66,9 +66,9 @@ function readFolder(value: unknown): string | null { function readComfyFile(value: unknown): ComfyOutputFile | null { if (!isRecord(value)) return null const { filename, subfolder = '', type } = value - return type === 'output' && typeof filename === 'string' && typeof subfolder === 'string' - ? { filename, subfolder } - : null + if (type !== 'output' || typeof filename !== 'string' || typeof subfolder !== 'string') + return null + return filename.length + subfolder.length > MAX_PATH_LENGTH ? null : { filename, subfolder } } function readSavedPlace(value: Record): Partial { diff --git a/src/main/lib/outputFolders.test.ts b/src/main/lib/outputFolders.test.ts index fd9cc09b7..ee084d01b 100644 --- a/src/main/lib/outputFolders.test.ts +++ b/src/main/lib/outputFolders.test.ts @@ -396,6 +396,29 @@ describe('comfyOutputPath', () => { ).toBeNull() }) + it("refuses a subfolder that climbs out of the build's output folder, and an absolute filename", async () => { + const secret = path.join(outsideDir, 'secret.png') + write(secret, CUTOUT) + const bytes = new Uint8Array(CUTOUT) + + expect( + await comfyOutputPath(appsBuild(), { filename: 'secret.png', subfolder: '../outside' }, bytes) + ).toBeNull() + expect( + await comfyOutputPath( + appsBuild(), + { filename: 'secret.png', subfolder: 'apps/../../outside' }, + bytes + ) + ).toBeNull() + expect( + await comfyOutputPath(appsBuild(), { filename: secret, subfolder: '' }, bytes) + ).toBeNull() + expect( + await comfyOutputPath(appsBuild(), { filename: '/etc/passwd', subfolder: '' }, bytes) + ).toBeNull() + }) + it('finds nothing for Cloud or a build that manages its own paths', async () => { write(path.join(sharedDir, 'cutout_00001_.png'), CUTOUT) const file = { filename: 'cutout_00001_.png', subfolder: '' } From a4684de55e0168055e033d68248dc58c2af22c40 Mon Sep 17 00:00:00 2001 From: PabloWiedemann Date: Mon, 16 Nov 2026 14:16:41 -0800 Subject: [PATCH 4/6] fix(assets): drop a View in Assets target that Comfy Cloud cannot list When the user is signed out or the workspace has no Comfy Cloud build, the page shows that empty state and no longer opens the file later. --- src/renderer/src/panel/AssetsView.test.ts | 29 +++++++++++++++++++++++ src/renderer/src/panel/AssetsView.vue | 27 ++++++++++++++++----- 2 files changed, 50 insertions(+), 6 deletions(-) diff --git a/src/renderer/src/panel/AssetsView.test.ts b/src/renderer/src/panel/AssetsView.test.ts index aa8d4cb75..22a43fbeb 100644 --- a/src/renderer/src/panel/AssetsView.test.ts +++ b/src/renderer/src/panel/AssetsView.test.ts @@ -896,6 +896,35 @@ describe('AssetsView', () => { expect(wrapper.find('[data-testid="assets-not-found"]').exists()).toBe(false) }) + it('lets go of the file when Comfy Cloud cannot list it, and says why', async () => { + getAuthStatus.mockResolvedValue({ signedIn: false }) + listAssets.mockResolvedValue([asset('new', 'cutout.png', 'image')]) + const installationStore = useInstallationStore() + installationStore.installations = [cloudBuild('cloud')] + installationStore.loading = false + const signedOut = mount(AssetsView, { attachTo: page, props: { focusName: 'cutout.png' } }) + await flushPromises() + + expect(signedOut.get('[data-testid="assets-empty"] h2').text()).toBe( + 'Log in to see your assets' + ) + await signInWith([asset('new', 'cutout.png', 'image')]) + expect(assetNames(signedOut)).toEqual(['cutout.png']) + expect(viewer(), 'the file is not opened later').toBeNull() + signedOut.unmount() + + installationStore.installations = [localBuild('lab')] + const noCloudBuild = mount(AssetsView, { attachTo: page, props: { focusName: 'cutout.png' } }) + await flushPromises() + expect(noCloudBuild.get('[data-testid="assets-empty"] h2').text()).toBe( + 'This workspace has no Comfy Cloud build yet' + ) + installationStore.installations = [cloudBuild('cloud')] + await flushPromises() + expect(assetNames(noCloudBuild)).toEqual(['cutout.png']) + expect(viewer(), 'the file is not opened later').toBeNull() + }) + it('remembers a place the user picks after that', async () => { const wrapper = await mountWithFocus([]) diff --git a/src/renderer/src/panel/AssetsView.vue b/src/renderer/src/panel/AssetsView.vue index be37f1341..0f09173e6 100644 --- a/src/renderer/src/panel/AssetsView.vue +++ b/src/renderer/src/panel/AssetsView.vue @@ -174,6 +174,12 @@ const cloudBuild = computed( const cloudListable = computed( () => buildsKnown.value && authStore.isSignedIn && cloudBuild.value !== null ) +const cloudSettled = computed( + () => + buildsKnown.value && + authStore.statusLoaded && + (!authStore.isSignedIn || authStore.workspacesLoaded) +) const currentFolder = computed(() => place.value === 'computer' ? (trail.value.at(-1) ?? null) : null @@ -418,6 +424,7 @@ async function loadPlace(userAsked: boolean): Promise { async function loadAssets(userAsked = false): Promise { const current = ++requestId + const settled = cloudSettled.value failed.value = false loading.value = true try { @@ -426,13 +433,13 @@ async function loadAssets(userAsked = false): Promise { assets.value = loaded.assets outputFolders.value = loaded.folders subfolders.value = loaded.subfolders - openPendingFocus() + openPendingFocus(settled) } catch { if (current !== requestId) return assets.value = [] subfolders.value = [] failed.value = true - openPendingFocus() + openPendingFocus(settled) } finally { if (current === requestId) loading.value = false } @@ -480,16 +487,24 @@ function newestNamed(name: string): GalleryAsset | null { ) } -function openPendingFocus(): void { +function openPendingFocus(settled: boolean): void { const name = pendingFocus.value - if (!name || (place.value === 'cloud' && !cloudListable.value)) return + if (!name || (place.value === 'cloud' && !cloudListable.value && !settled)) return pendingFocus.value = null - if (place.value !== 'cloud' || failed.value) return + if (place.value !== 'cloud' || failed.value || !cloudListable.value) return const asset = newestNamed(name) if (asset) openDetail(asset) else notFoundName.value = name } +watch( + cloudSettled, + (settled) => { + if (settled && !loading.value) openPendingFocus(true) + }, + { flush: 'post' } +) + watch( () => focusName, (name) => { @@ -498,7 +513,7 @@ watch( const cloudShown = place.value === 'cloud' && !loading.value pendingFocus.value = name pickedPlace.value = 'cloud' - if (cloudShown) openPendingFocus() + if (cloudShown) openPendingFocus(cloudSettled.value) }, { immediate: true } ) From 6ec45b0f7cf56d4b2e89052c131e15e36a3f4b18 Mon Sep 17 00:00:00 2001 From: PabloWiedemann Date: Mon, 16 Nov 2026 15:31:34 -0800 Subject: [PATCH 5/6] fix(apps): read no more than the output's size when comparing a ComfyUI file --- src/main/lib/outputFolders.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/lib/outputFolders.ts b/src/main/lib/outputFolders.ts index 40ee44917..b008b0c4a 100644 --- a/src/main/lib/outputFolders.ts +++ b/src/main/lib/outputFolders.ts @@ -114,8 +114,10 @@ async function hasSameBytes(file: string, bytes: Uint8Array): Promise { const handle = await fsp.open(file, READ_WITHOUT_FOLLOWING).catch(() => null) if (!handle) return false try { - const content = await handle.readFile() - return Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength).equals(content) + const content = Buffer.alloc(bytes.byteLength + 1) + const { bytesRead } = await handle.read(content, 0, content.length, 0) + const expected = Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength) + return bytesRead === bytes.byteLength && expected.equals(content.subarray(0, bytesRead)) } catch { return false } finally { From db50f81a537ab051a614c4a9a32b767242c18f22 Mon Sep 17 00:00:00 2001 From: PabloWiedemann Date: Mon, 16 Nov 2026 15:31:38 -0800 Subject: [PATCH 6/6] fix(apps): look for at most four ComfyUI files at once, and find none when the build cannot be read --- src/main/apps/outputFiles.test.ts | 36 +++++++++++++++++++++++++++++-- src/main/apps/outputFiles.ts | 14 ++++++------ 2 files changed, 42 insertions(+), 8 deletions(-) diff --git a/src/main/apps/outputFiles.test.ts b/src/main/apps/outputFiles.test.ts index 6d747c3df..6bb88c1c8 100644 --- a/src/main/apps/outputFiles.test.ts +++ b/src/main/apps/outputFiles.test.ts @@ -3,9 +3,11 @@ import { describe, expect, it, vi } from 'vitest' vi.mock('../installations', () => ({ get: vi.fn() })) vi.mock('../lib/outputFolders', () => ({ comfyOutputPath: vi.fn() })) -vi.mock('./localComfy', () => ({ pageBuildId: vi.fn() })) +vi.mock('./localComfy', () => ({ pageBuildId: vi.fn(() => 'apps-build') })) -import { locateOutputFiles } from './outputFiles' +import type { WebContents } from 'electron' +import * as installations from '../installations' +import { findInPageBuild, locateOutputFiles } from './outputFiles' import type { FindOutputFile } from './outputFiles' import type { RequestedOutput } from './outputRequest' @@ -82,4 +84,34 @@ describe('locateOutputFiles', () => { ]) expect(located.files).toEqual([null, null, null]) }) + + it('looks for at most four files at once', async () => { + let looking = 0 + let most = 0 + const find = vi.fn(async () => { + looking += 1 + most = Math.max(most, looking) + await new Promise((resolve) => setTimeout(resolve, 1)) + looking -= 1 + return null + }) + const items = Array.from({ length: 10 }, () => + output({ savedOn: 'computer', comfyFile: cutoutFile }) + ) + + await locateOutputFiles({ items, index: 0 }, find) + + expect(find).toHaveBeenCalledTimes(10) + expect(most).toBe(4) + }) +}) + +describe('findInPageBuild', () => { + it('finds nothing when the build cannot be read', async () => { + vi.mocked(installations.get).mockRejectedValueOnce(new Error('unreadable')) + + const find = await findInPageBuild({} as WebContents) + + expect(await find(cutoutFile, new Uint8Array([1]))).toBeNull() + }) }) diff --git a/src/main/apps/outputFiles.ts b/src/main/apps/outputFiles.ts index 2c780a88e..4706a0869 100644 --- a/src/main/apps/outputFiles.ts +++ b/src/main/apps/outputFiles.ts @@ -4,9 +4,12 @@ import type { WebContents } from 'electron' import type { AppOutput, AppOutputs } from '../../types/ipc' import * as installations from '../installations' import { comfyOutputPath } from '../lib/outputFolders' +import { runPool } from '../sources/standalone/templateDownloadCore' import { pageBuildId } from './localComfy' import type { ComfyOutputFile, OutputRequest } from './outputRequest' +const FILES_AT_ONCE = 4 + export type FindOutputFile = (file: ComfyOutputFile, bytes: Uint8Array) => Promise export interface LocatedOutputs { @@ -18,11 +21,10 @@ export async function locateOutputFiles( request: OutputRequest, find: FindOutputFile ): Promise { - const files = await Promise.all( - request.items.map((item) => - item.comfyFile ? find(item.comfyFile, item.bytes).catch(() => null) : null - ) - ) + const files: (string | null)[] = request.items.map(() => null) + await runPool(request.items, FILES_AT_ONCE, async (item, i) => { + if (item.comfyFile) files[i] = await find(item.comfyFile, item.bytes).catch(() => null) + }) const items = request.items.map(({ comfyFile, folder, ...output }, i): AppOutput => { const file = files[i] if (file) return { ...output, folder: path.dirname(file) } @@ -33,7 +35,7 @@ export async function locateOutputFiles( export async function findInPageBuild(page: WebContents): Promise { const buildId = pageBuildId(page) - const build = buildId ? await installations.get(buildId) : null + const build = buildId ? await installations.get(buildId).catch(() => null) : null if (!build) return async () => null return (file, bytes) => comfyOutputPath(build, file, bytes) }