From da9d6e4bf5a8eb4af67031b95153fbda49df0c24 Mon Sep 17 00:00:00 2001 From: PabloWiedemann Date: Mon, 16 Nov 2026 11:58:45 -0800 Subject: [PATCH 1/5] feat(assets): browse Comfy Cloud or the output folders on this computer The Assets page gets a Comfy Cloud | This computer switch in place of the build picker. The choice is remembered, and the page opens on This computer until the user picks Comfy Cloud. In a build's window the page opens on Comfy Cloud for a Cloud build, and inside the build's output folder for a local build, without changing the saved choice. - This computer shows one card per output folder: the real folder name, a short path, and the builds that save there (two names, then a +N button that lists the rest on hover or focus). A folder opens to its subfolders and its files, with a path back to This computer and Open folder. - Every folder and subfolder has a menu with Show in Finder (Explorer on Windows, Show in folder on Linux). - The type tabs, search and view options show where they act: on Comfy Cloud and inside a folder. A folder's files use the same gallery, menus and viewer as before. - The viewer says where a local file is saved and can show it in its folder. - Comfy Cloud lists the Cloud build of the dashboard workspace and still moves the session to that workspace first. A workspace with no Cloud build says so. Main lists the output folders with the names and ids of the builds that save to each one, and one folder at a time (its subfolders and its newest 500 media files), only inside the output folders. It replaces the recursive per-build listing, and the renderer no longer gets hasOutputFolder with each installation. --- locales/en.json | 34 +- locales/zh.json | 34 +- .../lib/ipc/installationsForRenderer.test.ts | 78 --- .../lib/ipc/registerInstallationHandlers.ts | 2 - src/main/lib/outputFolders.test.ts | 109 +-- src/main/lib/outputFolders.ts | 87 ++- src/preload/api.ts | 4 +- src/renderer/src/composables/usePlatform.ts | 11 + src/renderer/src/panel/AssetsView.test.ts | 640 ++++++++++++------ src/renderer/src/panel/AssetsView.vue | 486 +++++++------ src/renderer/src/panel/FolderActionsMenu.vue | 53 ++ src/renderer/src/panel/LocalFolders.vue | 266 ++++++++ src/renderer/src/panel/OutputDetailDialog.vue | 36 +- src/renderer/src/preview/fakeBridge.ts | 3 +- src/renderer/src/preview/fixtures.ts | 11 + src/renderer/src/preview/scenarios.ts | 13 +- src/renderer/src/types/ipc.ts | 3 + src/types/ipc.ts | 21 +- 18 files changed, 1251 insertions(+), 640 deletions(-) delete mode 100644 src/main/lib/ipc/installationsForRenderer.test.ts create mode 100644 src/renderer/src/panel/FolderActionsMenu.vue create mode 100644 src/renderer/src/panel/LocalFolders.vue diff --git a/locales/en.json b/locales/en.json index 33d8b9069..fd076b3c9 100644 --- a/locales/en.json +++ b/locales/en.json @@ -63,20 +63,9 @@ }, "assets": { "kindLabel": "Asset type", - "buildPickerLabel": "Build", - "browseAssetsOf": "Browse the assets of", + "placeLabel": "Where files are saved", + "cloud": "Comfy Cloud", "thisComputer": "This computer", - "outputFolder": "Output folder", - "buildStatus": "{where} · {state}", - "buildWhere": { - "local": "Local", - "cloud": "Cloud" - }, - "buildState": { - "running": "Running", - "starting": "Starting", - "stopped": "Stopped" - }, "kind": { "all": "All", "image": "Images", @@ -121,6 +110,8 @@ "signedOutTitle": "Log in to see your assets", "signedOutBody": "Assets that you make in Comfy Cloud show here.", "signIn": "Log in to Comfy Cloud", + "noCloudBuildTitle": "This workspace has no Comfy Cloud build yet", + "noCloudBuildBody": "Add Comfy Cloud to this workspace to see its assets here.", "inspect": "Inspect {name}", "detail": { "tags": "Tags", @@ -128,7 +119,8 @@ "createdAt": "Created {date}", "fit": "Fit", "zoom": "Zoom", - "zoomLevel": "Zoom: {level}" + "zoomLevel": "Zoom: {level}", + "savedIn": "Saved in" }, "kindSingular": { "image": "Image", @@ -136,6 +128,20 @@ "audio": "Audio", "3d": "3D", "file": "File" + }, + "local": { + "folderActions": "Folder actions", + "noBuilds": "No build saves here yet", + "savedBy": "Saved here by", + "moreBuilds": "and 1 more | and {count} more", + "openFolder": "Open folder", + "path": "Folder path", + "noFoldersTitle": "No output folders yet", + "noFoldersBody": "Files appear here after you run a workflow with ComfyUI on this computer.", + "emptyFolder": "No images, videos, audio or 3D files here.", + "folderFailed": "Couldn't open this folder. It may have been moved or deleted.", + "backToComputer": "Back to This computer", + "truncated": "Showing the newest file. Open the folder to see all of them. | Showing the newest {count} files. Open the folder to see all of them." } }, "home": { diff --git a/locales/zh.json b/locales/zh.json index ebe69c26f..8c605a76c 100644 --- a/locales/zh.json +++ b/locales/zh.json @@ -63,20 +63,9 @@ }, "assets": { "kindLabel": "资产类型", - "buildPickerLabel": "构建", - "browseAssetsOf": "浏览以下构建的资产", + "placeLabel": "文件保存位置", + "cloud": "Comfy Cloud", "thisComputer": "这台电脑", - "outputFolder": "输出文件夹", - "buildStatus": "{where} · {state}", - "buildWhere": { - "local": "本地", - "cloud": "云端" - }, - "buildState": { - "running": "运行中", - "starting": "启动中", - "stopped": "已停止" - }, "kind": { "all": "全部", "image": "图片", @@ -121,6 +110,8 @@ "signedOutTitle": "登录以查看你的资产", "signedOutBody": "你在 Comfy Cloud 中生成的资产会显示在这里。", "signIn": "登录 Comfy Cloud", + "noCloudBuildTitle": "此工作区还没有 Comfy Cloud 构建", + "noCloudBuildBody": "将 Comfy Cloud 添加到此工作区后,这里会显示它的资产。", "inspect": "查看 {name}", "detail": { "tags": "标签", @@ -128,7 +119,8 @@ "createdAt": "创建于 {date}", "fit": "适应", "zoom": "缩放", - "zoomLevel": "缩放:{level}" + "zoomLevel": "缩放:{level}", + "savedIn": "保存位置" }, "kindSingular": { "image": "图片", @@ -136,6 +128,20 @@ "audio": "音频", "3d": "3D", "file": "文件" + }, + "local": { + "folderActions": "文件夹操作", + "noBuilds": "还没有构建保存到这里", + "savedBy": "保存到这里的构建", + "moreBuilds": "还有 {count} 个", + "openFolder": "打开文件夹", + "path": "文件夹路径", + "noFoldersTitle": "还没有输出文件夹", + "noFoldersBody": "在这台电脑上用 ComfyUI 运行工作流后,文件会显示在这里。", + "emptyFolder": "这里没有图片、视频、音频或 3D 文件。", + "folderFailed": "无法打开此文件夹。它可能已被移动或删除。", + "backToComputer": "返回这台电脑", + "truncated": "仅显示最新的 {count} 个文件。打开文件夹可查看全部。" } }, "home": { diff --git a/src/main/lib/ipc/installationsForRenderer.test.ts b/src/main/lib/ipc/installationsForRenderer.test.ts deleted file mode 100644 index 76e64cfab..000000000 --- a/src/main/lib/ipc/installationsForRenderer.test.ts +++ /dev/null @@ -1,78 +0,0 @@ -import { describe, expect, it, vi } from 'vitest' -import { EventEmitter } from 'events' -import os from 'os' -import type { InstallationRecord } from '../../installations' - -vi.mock('electron', () => ({ - app: { - isPackaged: false, - getPath: () => os.tmpdir(), - getVersion: () => '0.0.0-test', - getLocale: () => 'en' - }, - ipcMain: { handle: vi.fn(), on: vi.fn(), off: vi.fn() }, - dialog: {}, - shell: {}, - session: {}, - WebContentsView: class {}, - BrowserWindow: { getAllWindows: () => [] }, - nativeTheme: { on: vi.fn(), shouldUseDarkColors: false } -})) - -vi.mock('../i18n', () => ({ - t: (key: string) => key, - init: vi.fn(), - getMessages: () => ({}), - getLocale: () => 'en', - getAvailableLocales: () => [] -})) - -vi.mock('../../settings', () => ({ - get: vi.fn(() => undefined), - set: vi.fn(async () => {}), - getAll: vi.fn(() => ({})), - getMirrorConfig: vi.fn(() => ({ pypiMirror: undefined, useChineseMirrors: false })), - defaults: { modelsDirs: ['/unused'], inputDir: '/unused', outputDir: '/unused' } -})) - -vi.mock('../../installations', () => ({ - installationEvents: new EventEmitter(), - CLOUD_SOURCE_ID: 'cloud', - list: vi.fn(async () => []), - get: vi.fn(async () => null), - update: vi.fn(async () => null), - remove: vi.fn(async () => {}) -})) - -import { enrichInstallationsForRenderer } from './registerInstallationHandlers' - -function installation(id: string, sourceId: string): InstallationRecord { - return { - id, - name: id, - sourceId, - installPath: `/installs/${id}`, - status: 'installed', - createdAt: '2026-11-01T00:00:00Z' - } -} - -describe('enrichInstallationsForRenderer', () => { - it('tells the page which builds save to an output folder Desktop can list', () => { - const { enriched } = enrichInstallationsForRenderer([ - installation('standalone', 'standalone'), - installation('from-a-build', 'comfybuilder'), - installation('old-desktop', 'desktop'), - installation('cloud', 'cloud'), - installation('server', 'remote') - ]) - - expect(Object.fromEntries(enriched.map((inst) => [inst.id, inst.hasOutputFolder]))).toEqual({ - standalone: true, - 'from-a-build': true, - 'old-desktop': false, - cloud: false, - server: false - }) - }) -}) diff --git a/src/main/lib/ipc/registerInstallationHandlers.ts b/src/main/lib/ipc/registerInstallationHandlers.ts index 95b2ccbe5..0ebf5642d 100644 --- a/src/main/lib/ipc/registerInstallationHandlers.ts +++ b/src/main/lib/ipc/registerInstallationHandlers.ts @@ -38,7 +38,6 @@ import * as releaseCache from '../release-cache' import { runStartupReleaseChecks } from '../release-cache-startup' import { _broadcastToRenderer } from './shared' import { hasGitDir } from '../git' -import { hasOutputFolder } from '../outputFolders' import { parseUrl } from '../util' import { restoreSnapshotIntoInstallation } from '../standaloneMigration' import * as mainTelemetry from '../telemetry' @@ -130,7 +129,6 @@ export function enrichInstallationsForRenderer(allInstalls: InstallationRecord[] sourceLabel: source.label, sourceCategory: source.category, hasConsole: source.hasConsole !== false, - hasOutputFolder: hasOutputFolder(inst), ...(buildVersion ? { distributionVersion: buildVersion } : {}), ...(listPreview != null ? { listPreview } : {}), ...(statusTag ? { statusTag } : {}) diff --git a/src/main/lib/outputFolders.test.ts b/src/main/lib/outputFolders.test.ts index 60341690f..fa9dd1c4c 100644 --- a/src/main/lib/outputFolders.test.ts +++ b/src/main/lib/outputFolders.test.ts @@ -82,14 +82,13 @@ vi.mock('./assets', () => ({ import type { InstallationRecord } from '../installations' import { - MAX_FOLDER_DEPTH, MAX_LOCAL_ASSETS, THUMBNAIL_WAIT_MS, copyOutputImage, hasOutputFolder, revealOutputFile, trashOutputFile, - listLocalAssets, + listOutputFolder, listOutputFolders, outputDirOverride, outputFilePath, @@ -179,37 +178,48 @@ describe('hasOutputFolder', () => { }) describe('listOutputFolders', () => { - it('lists each real output folder once, leaving out Cloud and builds that manage their own paths', async () => { + it('lists each real output folder once with the builds that save there, leaving out Cloud and builds that manage their own paths', async () => { expect(await listOutputFolders()).toEqual([ - sharedDir, - ownDir, - path.join(installDir, 'ComfyUI', 'output') + { + path: sharedDir, + builds: ['Test Instance', 'My Local 1'], + buildIds: ['Test Instance', 'My Local 1'] + }, + { path: ownDir, builds: ['Apps'], buildIds: ['Apps'] }, + { path: path.join(installDir, 'ComfyUI', 'output'), builds: ['Bare'], buildIds: ['Bare'] } ]) }) - it('leaves out folders that do not exist yet', async () => { + it('leaves out folders that do not exist yet, and keeps the shared folder when no build saves there', async () => { installs.mockResolvedValue([ install('Gone', { useSharedOutput: false, outputDir: path.join(root, 'missing') }) ]) - expect(await listOutputFolders()).toEqual([sharedDir]) + expect(await listOutputFolders()).toEqual([{ path: sharedDir, builds: [], buildIds: [] }]) }) }) -describe('listLocalAssets', () => { - it("lists the media in the picked build's output folder and its subfolders, newest first", async () => { +describe('listOutputFolder', () => { + it('lists the subfolders by name and the media files newest first, leaving out hidden and other files', async () => { write(path.join(sharedDir, 'old.png'), 'x', new Date('2026-10-01T00:00:00Z')) - write(path.join(sharedDir, 'video', 'new.mp4'), 'xx', new Date('2026-11-05T00:00:00Z')) + write(path.join(sharedDir, 'new.mp4'), 'xx', new Date('2026-11-05T00:00:00Z')) write(path.join(sharedDir, 'mesh.glb'), 'x', new Date('2026-11-02T00:00:00Z')) - write(path.join(ownDir, 'voice.wav'), 'xxx', new Date('2026-11-03T00:00:00Z')) + write(path.join(sharedDir, 'video', 'inside.mp4')) + write(path.join(sharedDir, 'Apps', 'inside.png')) write(path.join(sharedDir, 'notes.txt')) write(path.join(sharedDir, '.hidden.png')) write(path.join(sharedDir, '.cache', 'inside-hidden.png')) + await listOutputFolders() - const assets = await listLocalAssets('Test Instance') + const listing = await listOutputFolder(sharedDir) - expect(assets.map((a) => a.name)).toEqual(['new.mp4', 'mesh.glb', 'old.png']) - const newVideo = path.join(sharedDir, 'video', 'new.mp4') - expect(assets[0]).toEqual({ + expect(listing!.folders).toEqual([ + { name: 'Apps', path: path.join(sharedDir, 'Apps') }, + { name: 'video', path: path.join(sharedDir, 'video') } + ]) + expect(listing!.truncated).toBe(false) + expect(listing!.files.map((a) => a.name)).toEqual(['new.mp4', 'mesh.glb', 'old.png']) + const newVideo = path.join(sharedDir, 'new.mp4') + expect(listing!.files[0]).toEqual({ id: newVideo, name: 'new.mp4', kind: 'video', @@ -224,19 +234,21 @@ describe('listLocalAssets', () => { durationSeconds: null }) const oldPicture = path.join(sharedDir, 'old.png') - expect(assets[2]!.thumbnailUrl, 'an image thumbnail link changes when the file does').toBe( - outputFileUrl(oldPicture, fs.statSync(oldPicture).mtimeMs) - ) - expect(assets[1]!.previewUrl, '3D files have no preview').toBeNull() + expect( + listing!.files[2]!.thumbnailUrl, + 'an image thumbnail link changes when the file does' + ).toBe(outputFileUrl(oldPicture, fs.statSync(oldPicture).mtimeMs)) + expect(listing!.files[1]!.previewUrl, '3D files have no preview').toBeNull() }) it('reports the size of each picture and video, and how long a video runs, before they load', async () => { write(path.join(sharedDir, 'portrait.png'), pngHeader(640, 960)) write(path.join(sharedDir, 'clip.webm'), fs.readFileSync(SAMPLE_VIDEO)) write(path.join(sharedDir, 'broken.png'), 'not a picture') + await listOutputFolders() const facts = Object.fromEntries( - (await listLocalAssets('Test Instance')).map((a) => [ + (await listOutputFolder(sharedDir))!.files.map((a) => [ a.name, [a.width, a.height, a.durationSeconds && Math.round(a.durationSeconds)] ]) @@ -249,25 +261,21 @@ describe('listLocalAssets', () => { }) }) - it('shows each build the files in its own output folder', async () => { - write(path.join(sharedDir, 'shared.png')) - write(path.join(ownDir, 'own.png')) - write(path.join(installDir, 'ComfyUI', 'output', 'install.png')) - const namesFor = async (id: string) => (await listLocalAssets(id)).map((a) => a.name) + it('lists a subfolder, and refuses folders outside the output folders', async () => { + write(path.join(ownDir, 'nested', 'still.png')) + write(path.join(outsideDir, 'secret.png')) + await listOutputFolders() - expect(await namesFor('Test Instance'), 'a build on the shared folder').toEqual(['shared.png']) - expect(await namesFor('My Local 1'), 'another build on the shared folder').toEqual([ - 'shared.png' - ]) - expect(await namesFor('Apps'), 'a build with its own folder').toEqual(['own.png']) - expect(await namesFor('Bare'), 'a build that saves inside its install').toEqual(['install.png']) - expect(await namesFor('Cloud'), 'Cloud has no folder on this computer').toEqual([]) - expect(await namesFor('Old Desktop'), 'a build that manages its own paths').toEqual([]) - expect(await namesFor('deleted'), 'a build that is gone').toEqual([]) + const nested = await listOutputFolder(path.join(ownDir, 'nested')) + expect(nested!.files.map((a) => a.name)).toEqual(['still.png']) + expect(await listOutputFolder(outsideDir), 'a folder outside').toBeNull() expect( - (await listLocalAssets()).map((a) => a.name), - 'no build: the shared output folder' - ).toEqual(['shared.png']) + await listOutputFolder(path.join(ownDir, '..', 'outside')), + 'a path that climbs out' + ).toBeNull() + expect(await listOutputFolder('nested'), 'a relative path').toBeNull() + expect(await listOutputFolder(path.join(ownDir, 'missing')), 'a folder that is gone').toBeNull() + expect(await listOutputFolder(42), 'not a path').toBeNull() }) it('opens a file it listed for a build added a moment ago', async () => { @@ -277,7 +285,8 @@ describe('listLocalAssets', () => { write(file) installs.mockResolvedValue([install('New', { useSharedOutput: false, outputDir: newDir })]) try { - const [listed] = await listLocalAssets('New') + await listOutputFolders() + const [listed] = (await listOutputFolder(newDir))!.files expect(listed!.id).toBe(file) expect(await outputFilePath(listed!.id)).toBe(file) @@ -286,26 +295,26 @@ describe('listLocalAssets', () => { } }) - it('keeps only the newest files when the folders are very large', async () => { + it('keeps only the newest files when a folder is very large, and says so', async () => { for (let i = 0; i <= MAX_LOCAL_ASSETS; i++) write(path.join(sharedDir, `f${i}.png`), '', new Date(Date.UTC(2026, 0, 1, 0, 0, i))) + await listOutputFolders() - const assets = await listLocalAssets('Test Instance') + const listing = await listOutputFolder(sharedDir) - expect(assets).toHaveLength(MAX_LOCAL_ASSETS) - expect(assets.map((a) => a.name)).not.toContain('f0.png') + expect(listing!.files).toHaveLength(MAX_LOCAL_ASSETS) + expect(listing!.files.map((a) => a.name)).not.toContain('f0.png') + expect(listing!.truncated).toBe(true) }) - it('does not follow links out of an output folder or walk without end', async () => { + it('does not follow links out of an output folder', async () => { write(path.join(outsideDir, 'secret.png')) fs.symlinkSync(outsideDir, path.join(sharedDir, 'escape')) - const deep = path.join( - sharedDir, - ...Array.from({ length: MAX_FOLDER_DEPTH + 1 }, (_, i) => `d${i}`) - ) - write(path.join(deep, 'too-deep.png')) + fs.symlinkSync(path.join(outsideDir, 'secret.png'), path.join(sharedDir, 'secret.png')) + await listOutputFolders() - expect(await listLocalAssets('Test Instance')).toEqual([]) + expect(await listOutputFolder(sharedDir)).toEqual({ folders: [], files: [], truncated: false }) + expect(await listOutputFolder(path.join(sharedDir, 'escape'))).toBeNull() }) }) diff --git a/src/main/lib/outputFolders.ts b/src/main/lib/outputFolders.ts index 1b0ead901..5598a5444 100644 --- a/src/main/lib/outputFolders.ts +++ b/src/main/lib/outputFolders.ts @@ -1,5 +1,4 @@ import fsp from 'fs/promises' -import type { Dirent } from 'fs' import path from 'path' import { pathToFileURL } from 'url' import { ipcMain, nativeImage, net, protocol, shell } from 'electron' @@ -12,13 +11,18 @@ import { mediaFactsFromFile } from './mediaFacts' import { runPool } from '../sources/standalone/templateDownloadCore' import { installOutputDir } from './models' import { sourceMap } from './ipc/shared' -import type { AssetSummary } from '../../types/ipc' +import type { + AssetSummary, + OutputFolder, + OutputFolderListing, + OutputSubfolder +} from '../../types/ipc' export const OUTPUT_FILES_SCHEME = 'comfy-output' -const LIST_LOCAL_CHANNEL = 'assets:list-local' +const LIST_FOLDERS_CHANNEL = 'assets:output-folders' +const LIST_FOLDER_CHANNEL = 'assets:output-folder' export const MAX_LOCAL_ASSETS = 500 -export const MAX_FOLDER_DEPTH = 6 const THUMBNAIL_SIZE = 480 const MAX_CACHED_THUMBNAILS = 400 const THUMBNAILS_AT_ONCE = 2 @@ -61,29 +65,23 @@ async function realDir(dir: string): Promise { return stat?.isDirectory() ? real : null } -interface OutputFolders { - all: string[] - shared: string | null - ofBuild: Map -} - -async function findOutputFolders(): Promise { +export async function listOutputFolders(): Promise { const sharedDir = sharedOutputDir() const shared = await realDir(sharedDir) - const ofBuild = new Map() + const byPath = new Map() + if (shared) byPath.set(shared, { path: shared, builds: [], buildIds: [] }) for (const inst of await installations.list()) { const dir = outputDirFor(inst, sharedDir) const real = dir ? await realDir(dir) : null - if (real) ofBuild.set(inst.id, real) + if (!real) continue + const folder = byPath.get(real) ?? { path: real, builds: [], buildIds: [] } + folder.builds.push(inst.name) + folder.buildIds.push(inst.id) + byPath.set(real, folder) } - const all = [...new Set([...(shared ? [shared] : []), ...ofBuild.values()])] - allowedRoots = all + allowedRoots = [...byPath.keys()] allowedRootsAt = Date.now() - return { all, shared, ofBuild } -} - -export async function listOutputFolders(): Promise { - return (await findOutputFolders()).all + return [...byPath.values()] } function isInsideRoot(target: string, root: string): boolean { @@ -93,7 +91,7 @@ function isInsideRoot(target: string, root: string): boolean { async function allowedPath(target: string): Promise { if (!path.isAbsolute(target)) return null - if (Date.now() - allowedRootsAt > ROOTS_FRESH_MS) await findOutputFolders() + if (Date.now() - allowedRootsAt > ROOTS_FRESH_MS) await listOutputFolders() const real = await fsp.realpath(target).catch(() => null) if (!real) return null return allowedRoots.some((root) => isInsideRoot(real, root)) ? real : null @@ -134,25 +132,6 @@ export function outputFileUrl(file: string, thumbnailOf?: number): string { return thumbnailOf === undefined ? url : `${url}?thumbnail=${Math.round(thumbnailOf)}` } -async function collectMediaFiles(root: string): Promise { - const files: string[] = [] - const walk = async (dir: string, depth: number): Promise => { - const dirents: Dirent[] = await fsp.readdir(dir, { withFileTypes: true }).catch(() => []) - const subfolders: string[] = [] - for (const dirent of dirents) { - if (dirent.name.startsWith('.')) continue - const full = path.join(dir, dirent.name) - if (dirent.isDirectory()) subfolders.push(full) - else if (dirent.isFile() && assetKind(dirent.name) !== null) files.push(full) - } - if (depth < MAX_FOLDER_DEPTH) { - for (const sub of subfolders) await walk(sub, depth + 1) - } - } - await walk(root, 0) - return files -} - function localSummary(file: string, sizeBytes: number, modifiedMs: number): AssetSummary { const kind = assetKind(file) return { @@ -175,10 +154,19 @@ async function addMediaFacts(asset: AssetSummary): Promise { Object.assign(asset, await mediaFactsFromFile(asset.id, asset.kind)) } -export async function listLocalAssets(installationId?: string): Promise { - const folders = await findOutputFolders() - const folder = installationId === undefined ? folders.shared : folders.ofBuild.get(installationId) - const files = folder ? await collectMediaFiles(folder) : [] +export async function listOutputFolder(target: unknown): Promise { + if (typeof target !== 'string') return null + const dir = await allowedPath(target) + const dirents = dir ? await fsp.readdir(dir, { withFileTypes: true }).catch(() => null) : null + if (!dir || !dirents) return null + const folders: OutputSubfolder[] = [] + const files: string[] = [] + for (const dirent of dirents) { + if (dirent.name.startsWith('.')) continue + const full = path.join(dir, dirent.name) + if (dirent.isDirectory()) folders.push({ name: dirent.name, path: full }) + else if (dirent.isFile() && assetKind(dirent.name) !== null) files.push(full) + } const found: AssetSummary[] = [] await runPool(files, STATS_AT_ONCE, async (file) => { const stat = await fsp.stat(file).catch(() => null) @@ -190,7 +178,11 @@ export async function listLocalAssets(installationId?: string): Promise b.createdAt!.localeCompare(a.createdAt!)) .slice(0, MAX_LOCAL_ASSETS) await runPool(newest, STATS_AT_ONCE, addMediaFacts) - return newest + return { + folders: folders.sort((a, b) => a.name.localeCompare(b.name)), + files: newest, + truncated: found.length > MAX_LOCAL_ASSETS + } } function linuxThumbnailSource(file: string, sizeBytes: number): Electron.NativeImage | null { @@ -319,7 +311,6 @@ export function registerOutputFilesScheme(): void { export function registerOutputFolderHandlers(): void { protocol.handle(OUTPUT_FILES_SCHEME, serveOutputFile) - ipcMain.handle(LIST_LOCAL_CHANNEL, (_event, installationId: unknown) => - listLocalAssets(typeof installationId === 'string' ? installationId : undefined) - ) + ipcMain.handle(LIST_FOLDERS_CHANNEL, () => listOutputFolders()) + ipcMain.handle(LIST_FOLDER_CHANNEL, (_event, target: unknown) => listOutputFolder(target)) } diff --git a/src/preload/api.ts b/src/preload/api.ts index 7e726b16a..7130d7a1a 100644 --- a/src/preload/api.ts +++ b/src/preload/api.ts @@ -95,8 +95,8 @@ export function buildElectronApi(): ElectronApi { signalOverlayReady: () => ipcRenderer.send('comfy-window:overlay-ready'), navigatePanel: (page) => ipcRenderer.send('comfy-window:navigate-panel', page), listAssets: (installationId) => ipcRenderer.invoke('assets:list', installationId), - listLocalAssets: (installationId?: string) => - ipcRenderer.invoke('assets:list-local', installationId), + listOutputFolders: () => ipcRenderer.invoke('assets:output-folders'), + listOutputFolder: (folderPath) => ipcRenderer.invoke('assets:output-folder', folderPath), downloadAsset: (source, assetId, fileName) => ipcRenderer.invoke('assets:download', source, assetId, fileName), revealAsset: (source, assetId) => ipcRenderer.invoke('assets:reveal', source, assetId), diff --git a/src/renderer/src/composables/usePlatform.ts b/src/renderer/src/composables/usePlatform.ts index 36e9f4834..431682161 100644 --- a/src/renderer/src/composables/usePlatform.ts +++ b/src/renderer/src/composables/usePlatform.ts @@ -7,6 +7,17 @@ export function normalizePlatform(platform: string | undefined | null): Renderer return 'unknown' } +export function revealInFolderKey(platform: string | undefined | null): string { + switch (normalizePlatform(platform)) { + case 'mac': + return 'assets.showInFinder' + case 'windows': + return 'assets.showInExplorer' + default: + return 'assets.showInFolder' + } +} + export function revealInFolderLabel(platform: string | undefined | null): string { switch (normalizePlatform(platform)) { case 'mac': diff --git a/src/renderer/src/panel/AssetsView.test.ts b/src/renderer/src/panel/AssetsView.test.ts index f29cbd080..e16d55316 100644 --- a/src/renderer/src/panel/AssetsView.test.ts +++ b/src/renderer/src/panel/AssetsView.test.ts @@ -8,13 +8,21 @@ import Tooltip from '../components/ui/Tooltip.vue' import { useAuthStore } from '../stores/authStore' import { useDashboardScopeStore } from '../stores/dashboardScopeStore' import { useInstallationStore } from '../stores/installationStore' -import { useSessionStore } from '../stores/sessionStore' -import type { AssetSummary, Installation, RunningInstance } from '../types/ipc' +import type { + AssetSummary, + Installation, + OutputFolder, + OutputFolderListing, + OutputSubfolder +} from '../types/ipc' const listAssets = vi.fn() -const listLocalAssets = vi.fn() +const listOutputFolders = vi.fn() +const listOutputFolder = vi.fn() const downloadAsset = vi.fn() const revealAsset = vi.fn() +const revealPath = vi.fn() +const openPath = vi.fn() const copyAsset = vi.fn() const trashAsset = vi.fn() const alert = vi.fn() @@ -27,6 +35,9 @@ const getSetting = vi.fn() const MASONRY_GAP = 14 const FOUR_COLUMN_PAGE_WIDTH = 1100 const TALL_PAGE_HEIGHT = 3000 +const OUTPUT = '/Users/me/ComfyUI-Shared/output' + +type Wrapper = Awaited> let page: HTMLElement @@ -69,23 +80,20 @@ function asset( } } -function cloudBuild(id: string, name = id): Installation { - return { id, name, sourceLabel: 'Comfy Cloud', sourceCategory: 'cloud' } +function listing( + files: AssetSummary[], + folders: OutputSubfolder[] = [], + truncated = false +): OutputFolderListing { + return { folders, files, truncated } } -function localBuild(id: string, name = id, extra: Partial = {}): Installation { - return { - id, - name, - sourceLabel: 'Standalone', - sourceCategory: 'local', - hasOutputFolder: true, - ...extra - } +function cloudBuild(id: string, name = id): Installation { + return { id, name, sourceLabel: 'Comfy Cloud', sourceCategory: 'cloud' } } -function oldDesktopBuild(id: string, name = id): Installation { - return localBuild(id, name, { sourceLabel: 'Desktop', hasOutputFolder: false }) +function localBuild(id: string, name = id): Installation { + return { id, name, sourceLabel: 'Standalone', sourceCategory: 'local' } } function teamBuild(build: Installation): Installation { @@ -99,37 +107,43 @@ function signedInToPersonalWithTeamDashboard(): void { ) } -async function mountAssets( - local: AssetSummary[] | Promise = [], - { - builds = [localBuild('lab')], - installationId - }: { builds?: Installation[]; installationId?: string } = {} -) { +function outputFolder(path: string, builds: string[] = []): OutputFolder { + return { path, builds, buildIds: builds.map((name) => name.toLowerCase()) } +} + +async function mountPage({ + builds = [localBuild('lab')], + folders = [outputFolder(OUTPUT, ['lab'])], + installationId +}: { builds?: Installation[]; folders?: OutputFolder[]; installationId?: string } = {}) { const installationStore = useInstallationStore() installationStore.installations = builds installationStore.loading = false - listLocalAssets.mockReturnValue(Promise.resolve(local)) + listOutputFolders.mockResolvedValue(folders) const wrapper = mount(AssetsView, { attachTo: page, props: { installationId } }) await flushPromises() return wrapper } -async function openBuildPicker(wrapper: Awaited>): Promise { - await wrapper.get('[data-testid="assets-build-picker"]').trigger('keydown', { key: 'Enter' }) - await flushPromises() +async function mountAssets(files: AssetSummary[] = [], options: { builds?: Installation[] } = {}) { + listOutputFolder.mockResolvedValue(listing(files)) + const wrapper = await mountPage(options) + await openFolder(wrapper, OUTPUT) + return wrapper } -function buildRows(): string[] { - return [ - ...document.querySelectorAll( - '[data-testid^="assets-build-"]:not([data-testid="assets-build-picker"])' - ) - ].map((row) => row.textContent?.replace(/\s+/g, ' ').trim() ?? '') +async function mountCloud(builds: Installation[] = [cloudBuild('cloud')]) { + window.localStorage.setItem('comfy.desktop.assets.place', 'cloud') + return mountPage({ builds }) +} + +async function openFolder(wrapper: Wrapper, path: string): Promise { + await wrapper.get(`[data-testid="local-folder-${path}"]`).trigger('click') + await flushPromises() } -async function pickBuild(id: string): Promise { - document.querySelector(`[data-testid="assets-build-${id}"]`)!.click() +async function choose(wrapper: Wrapper, place: 'cloud' | 'computer'): Promise { + await wrapper.get(`[data-testid="assets-place-${place}"]`).trigger('click') await flushPromises() } @@ -163,13 +177,29 @@ async function rightClick(element: Element): Promise { return event } -function assetNames(wrapper: Awaited>): string[] { +function assetNames(wrapper: Wrapper): string[] { return wrapper .get('[data-testid="assets-grid"]') .findAllComponents(Tooltip) .map((tip) => tip.props('text') as string) } +function shownText(element: Element | null | undefined): string { + return ((element as HTMLElement | null)?.innerText ?? '').replace(/\s+/g, ' ').trim() +} + +function text(wrapper: Wrapper, testId: string): string { + const element = [...wrapper.element.querySelectorAll('[data-testid]')].find( + (candidate) => candidate.getAttribute('data-testid') === testId + ) + expect(element, `${testId} is on the page`).toBeDefined() + return shownText(element) +} + +function signedInToPersonal(): void { + getAuthStatus.mockResolvedValue({ signedIn: true, workspaceId: 'me', workspaceType: 'personal' }) +} + function viewer(): HTMLElement | null { return document.querySelector('[data-testid="output-detail"]') } @@ -191,7 +221,8 @@ beforeEach(() => { document.body.append(page) vi.clearAllMocks() window.localStorage.clear() - listLocalAssets.mockResolvedValue([]) + listOutputFolders.mockResolvedValue([]) + listOutputFolder.mockResolvedValue(listing([])) listWorkspaces.mockResolvedValue([ { id: 'me', name: 'Personal Workspace', type: 'personal' }, { id: 'team-b', name: 'Team B', type: 'team' } @@ -204,9 +235,12 @@ beforeEach(() => { getSetting.mockResolvedValue(undefined) ;(window as unknown as { api: unknown }).api = { listAssets, - listLocalAssets, + listOutputFolders, + listOutputFolder, downloadAsset, revealAsset, + revealPath, + openPath, copyAsset, trashAsset, platform: 'darwin', @@ -338,128 +372,284 @@ describe('AssetsView', () => { expect(wrapper.get('[data-testid="asset-a"]').text()).not.toContain('a.svg') }) - it('shows the files of a local build without it running or a Cloud login', async () => { - const wrapper = await mountAssets([ - asset('/out/surfer.mp4', 'surfer.mp4', 'video'), - asset('/out/forest.png', 'forest.png', 'image') - ]) + it('opens on This computer with a card per output folder: its real name, a short path and the builds that save there', async () => { + const wrapper = await mountPage({ + folders: [ + outputFolder(OUTPUT, ['ComfyUI', 'Video Lab', 'Apps', 'Sketches']), + outputFolder('/Users/me/Installs/Bare/ComfyUI/output') + ] + }) - expect(listLocalAssets).toHaveBeenCalledExactlyOnceWith('lab') - expect(listAssets).not.toHaveBeenCalled() - expect(assetNames(wrapper)).toEqual(['surfer.mp4', 'forest.png']) + expect(listOutputFolders).toHaveBeenCalledOnce() + expect(listAssets, 'nothing is read from Comfy Cloud').not.toHaveBeenCalled() + expect(listOutputFolder, 'no folder is read before one is opened').not.toHaveBeenCalled() + expect(text(wrapper, `local-folder-heading-${OUTPUT}`)).toBe('ComfyUI, Video Lab +2') + expect(text(wrapper, `local-folder-${OUTPUT}`)).toBe('output /Users/…/ComfyUI-Shared') + expect( + wrapper.get(`[data-testid="local-folder-${OUTPUT}"]`).attributes('title'), + 'the full path on hover' + ).toBe(OUTPUT) + expect(text(wrapper, 'local-folder-heading-/Users/me/Installs/Bare/ComfyUI/output')).toBe( + 'No build saves here yet' + ) + expect(text(wrapper, 'local-folder-/Users/me/Installs/Bare/ComfyUI/output')).toBe( + 'output /Users/…/ComfyUI' + ) + expect( + wrapper.find('[data-testid="assets-kind-all"]').exists(), + 'the type tabs show only where they act' + ).toBe(false) + expect(wrapper.find('input').exists(), 'so does the search').toBe(false) }) - it('shows an image card from its small thumbnail', async () => { - const wrapper = await mountAssets([ - asset('/out/forest.png', 'forest.png', 'image', { - previewUrl: 'comfy-output://file/full', - thumbnailUrl: 'comfy-output://file/full?thumbnail=1' - }) + it('shortens Windows drive and network paths the same way', async () => { + const paths = ['C:\\Users\\me\\ComfyUI\\output', 'D:\\output', '\\\\nas\\share\\comfy\\output'] + const wrapper = await mountPage({ folders: paths.map((path) => outputFolder(path)) }) + + expect(paths.map((path) => text(wrapper, `local-folder-${path}`))).toEqual([ + 'output C:\\…\\ComfyUI', + 'output D:\\', + 'output \\\\nas\\share\\comfy' ]) + }) - expect(wrapper.get('img').attributes('src')).toBe('comfy-output://file/full?thumbnail=1') + it('names every build that saves to a folder when its +N button is focused', async () => { + const builds = Array.from({ length: 13 }, (_, i) => `Build ${i + 1}`) + const wrapper = await mountPage({ folders: [outputFolder(OUTPUT, builds)] }) + + const more = wrapper.get(`[data-testid="local-folder-more-${OUTPUT}"]`) + expect(more.text()).toBe('+11') + await more.trigger('focusin') + await flushPromises() + + const bubble = document.querySelector('.tooltip-bubble')?.textContent ?? '' + expect(bubble).toContain('Saved here by') + expect(bubble, 'up to ten names').toContain('Build 10') + expect(bubble).not.toContain('Build 11') + expect(bubble, 'then how many more').toContain('and 3 more') }) - it("opens on the window's build, lists every build with where it runs, and switches to the one picked", async () => { - useSessionStore().runningInstances.set('lab', { installationId: 'lab' } as RunningInstance) - listAssets.mockResolvedValue([asset('c1', 'cloud.png', 'image')]) - const wrapper = await mountAssets([asset('/out/mine.png', 'mine.png', 'image')], { - builds: [ - localBuild('mine', 'My Local 1'), - localBuild('lab', 'Video Lab'), - { - ...cloudBuild('cloud', 'Comfy Cloud'), - statusTag: { style: 'update', label: 'Update available' } - } - ], - installationId: 'mine' - }) + it('says when there is no output folder yet', async () => { + const wrapper = await mountPage({ folders: [] }) - useAuthStore().status = { signedIn: true } + expect(text(wrapper, 'local-no-folders')).toContain('No output folders yet') + }) + + it('walks into a folder and its subfolders, and back with the path', async () => { + listOutputFolder.mockImplementation(async (path: string) => + path === OUTPUT + ? listing( + [asset(`${OUTPUT}/top.png`, 'top.png', 'image')], + [{ name: 'video', path: `${OUTPUT}/video` }] + ) + : listing([asset(`${OUTPUT}/video/clip.mp4`, 'clip.mp4', 'video')]) + ) + const wrapper = await mountPage() + + await openFolder(wrapper, OUTPUT) + expect(listOutputFolder).toHaveBeenLastCalledWith(OUTPUT) + expect(shownText(wrapper.get('nav').element)).toBe('This computer output') + expect(assetNames(wrapper)).toEqual(['top.png']) + expect(wrapper.find('[data-testid="assets-kind-all"]').exists()).toBe(true) + + await wrapper.get('[data-testid="local-subfolder-video"]').trigger('click') await flushPromises() + expect(listOutputFolder).toHaveBeenLastCalledWith(`${OUTPUT}/video`) + expect(shownText(wrapper.get('nav').element)).toBe('This computer output video') + expect(assetNames(wrapper)).toEqual(['clip.mp4']) - expect(wrapper.get('[data-testid="assets-build-picker"]').text()).toBe('My Local 1') - expect( - listLocalAssets.mock.calls.flat(), - 'only the window build is read, and logging in does not read it again' - ).toEqual(['mine']) - expect(listAssets).not.toHaveBeenCalled() - expect(assetNames(wrapper)).toEqual(['mine.png']) + await wrapper.get('[data-testid="local-crumb-1"]').trigger('click') + await flushPromises() + expect(assetNames(wrapper)).toEqual(['top.png']) - await openBuildPicker(wrapper) - expect(document.body.textContent).toContain('Browse the assets of') - expect(buildRows()).toEqual([ - 'My Local 1 Local · Stopped', - 'Video Lab Local · Running', - 'Comfy Cloud Cloud · Running' - ]) + await wrapper.get('[data-testid="local-crumb-0"]').trigger('click') + await flushPromises() + expect(wrapper.find(`[data-testid="local-folder-${OUTPUT}"]`).exists()).toBe(true) + expect(wrapper.find('[data-testid="assets-grid"]').exists()).toBe(false) + }) - await pickBuild('cloud') + it('shows no empty message in a folder that holds only subfolders', async () => { + listOutputFolder.mockResolvedValue(listing([], [{ name: 'video', path: `${OUTPUT}/video` }])) + const wrapper = await mountPage() - expect(listAssets).toHaveBeenCalledExactlyOnceWith('cloud') - expect(wrapper.get('[data-testid="assets-build-picker"]').text()).toBe('Comfy Cloud') - expect(assetNames(wrapper), "only the picked build's files show").toEqual(['cloud.png']) + await openFolder(wrapper, OUTPUT) + + expect(wrapper.find('[data-testid="local-subfolder-video"]').exists()).toBe(true) + expect(wrapper.find('[data-testid="assets-empty"]').exists()).toBe(false) + }) + + it('says a folder has nothing to show', async () => { + const wrapper = await mountAssets([]) + + expect(text(wrapper, 'assets-empty')).toBe('No images, videos, audio or 3D files here.') + }) + + it('shows any folder or subfolder in Finder from its menu, and opens the folder it is in', async () => { + listOutputFolder.mockResolvedValue(listing([], [{ name: 'video', path: `${OUTPUT}/video` }])) + const wrapper = await mountPage() + + await wrapper + .get(`[data-testid="local-folder-menu-${OUTPUT}"]`) + .trigger('keydown', { key: 'Enter' }) + await flushPromises() + const reveal = document.querySelector('[data-testid="local-folder-reveal"]')! + expect(reveal.textContent?.trim()).toBe('Show in Finder') + reveal.click() + await flushPromises() + expect(revealPath).toHaveBeenCalledExactlyOnceWith(OUTPUT) + + await openFolder(wrapper, OUTPUT) + await wrapper + .get('[data-testid="local-subfolder-menu-video"]') + .trigger('keydown', { key: 'Enter' }) + await flushPromises() + document.querySelector('[data-testid="local-folder-reveal"]')!.click() + await flushPromises() + expect(revealPath).toHaveBeenLastCalledWith(`${OUTPUT}/video`) + + await wrapper.get('[data-testid="local-open-folder"]').trigger('click') + expect(openPath).toHaveBeenCalledExactlyOnceWith(OUTPUT) + }) + + it('says when a folder is cut to its newest files', async () => { + listOutputFolder.mockResolvedValue( + listing([asset(`${OUTPUT}/a.png`, 'a.png', 'image')], [], true) + ) + const wrapper = await mountPage() + + await openFolder(wrapper, OUTPUT) + + expect(text(wrapper, 'assets-truncated')).toBe( + 'Showing the newest file. Open the folder to see all of them.' + ) + }) + + it('says a folder could not be opened, with a way back to This computer', async () => { + listOutputFolder.mockResolvedValue(null) + const wrapper = await mountPage() + + await openFolder(wrapper, OUTPUT) + expect(wrapper.get('[data-testid="assets-empty"] h2').text()).toBe( + "Couldn't open this folder. It may have been moved or deleted." + ) + await wrapper.get('[data-testid="assets-empty-action"]').trigger('click') + await flushPromises() + + expect(wrapper.find(`[data-testid="local-folder-${OUTPUT}"]`).exists()).toBe(true) + }) + + it('says the output folders could not be read', async () => { + listOutputFolders.mockRejectedValue(new Error('disk')) + const wrapper = mount(AssetsView, { attachTo: page }) + await flushPromises() + + expect(text(wrapper, 'local-failed')).toBe("Couldn't load assets") }) - it('reopens on the last picked build in a window with no build of its own', async () => { - const builds = [localBuild('mine', 'My Local 1'), localBuild('lab', 'Video Lab')] - const first = await mountAssets([], { builds }) - await openBuildPicker(first) - await pickBuild('lab') + it('remembers the place the user chose', async () => { + const first = await mountPage({ builds: [cloudBuild('cloud')] }) + await choose(first, 'cloud') first.unmount() - listLocalAssets.mockClear() - const again = await mountAssets([], { builds }) + const again = await mountPage({ builds: [cloudBuild('cloud')] }) - expect(again.get('[data-testid="assets-build-picker"]').text()).toBe('Video Lab') - expect(listLocalAssets).toHaveBeenCalledExactlyOnceWith('lab') + expect(again.get('[data-testid="assets-place-cloud"]').attributes('data-state')).toBe('on') + expect(again.find('[data-testid="local-folders"]').exists()).toBe(false) }) - it('leaves out builds from other workspaces, and servers and builds whose files Desktop cannot list', async () => { - const wrapper = await mountAssets([], { - builds: [ - localBuild('mine', 'My Local 1'), - teamBuild(localBuild('team', 'Team build')), - { id: 'remote', name: 'Office server', sourceLabel: 'Remote', sourceCategory: 'remote' }, - oldDesktopBuild('old', 'Old Desktop') - ] + it("opens a Cloud build's window on Comfy Cloud without changing the saved place", async () => { + const wrapper = await mountPage({ + builds: [localBuild('lab'), cloudBuild('cloud')], + installationId: 'cloud' }) - await openBuildPicker(wrapper) - - expect(buildRows()).toEqual(['My Local 1 Local · Stopped']) + expect(wrapper.get('[data-testid="assets-place-cloud"]').attributes('data-state')).toBe('on') + expect(listOutputFolders, 'This computer is not read').not.toHaveBeenCalled() + expect(window.localStorage.getItem('comfy.desktop.assets.place')).not.toBe('cloud') }) - it('opens on a build it can list, not on a running build that keeps its files to itself', async () => { - useSessionStore().runningInstances.set('old', { installationId: 'old' } as RunningInstance) - const wrapper = await mountAssets([asset('/out/forest.png', 'forest.png', 'image')], { - builds: [oldDesktopBuild('old', 'Old Desktop'), localBuild('lab', 'Video Lab')] + it("opens a local build's window inside that build's output folder, and keeps the saved place", async () => { + window.localStorage.setItem('comfy.desktop.assets.place', 'cloud') + listOutputFolder.mockResolvedValue(listing([asset(`${OUTPUT}/mine.png`, 'mine.png', 'image')])) + const wrapper = await mountPage({ + builds: [localBuild('lab'), localBuild('other'), cloudBuild('cloud')], + folders: [outputFolder('/Users/me/Other/output', ['other']), outputFolder(OUTPUT, ['lab'])], + installationId: 'lab' }) - expect(wrapper.get('[data-testid="assets-build-picker"]').text()).toBe('Video Lab') - expect(listLocalAssets).toHaveBeenCalledExactlyOnceWith('lab') - expect(assetNames(wrapper)).toEqual(['forest.png']) + expect(wrapper.get('[data-testid="assets-place-computer"]').attributes('data-state')).toBe('on') + expect(listOutputFolder).toHaveBeenCalledExactlyOnceWith(OUTPUT) + expect(assetNames(wrapper)).toEqual(['mine.png']) + expect(window.localStorage.getItem('comfy.desktop.assets.place')).toBe('cloud') + }) + + it('waits for the builds before it reads anything in a build window', async () => { + const installationStore = useInstallationStore() + mount(AssetsView, { attachTo: page, props: { installationId: 'cloud' } }) + await flushPromises() + + expect(listOutputFolders).not.toHaveBeenCalled() + expect(listAssets).not.toHaveBeenCalled() + + installationStore.installations = [cloudBuild('cloud')] + installationStore.loading = false + await flushPromises() + + expect(listOutputFolders, 'the Cloud build window opens on Comfy Cloud').not.toHaveBeenCalled() + }) + + it('saves the place the user picks in a build window', async () => { + const wrapper = await mountPage({ builds: [cloudBuild('cloud')], installationId: 'cloud' }) + + await choose(wrapper, 'computer') + + expect(window.localStorage.getItem('comfy.desktop.assets.place')).toBe('computer') + expect(wrapper.find(`[data-testid="local-folder-${OUTPUT}"]`).exists()).toBe(true) + }) + + it('reloads only the place the user is on when Refresh is pressed', async () => { + const wrapper = await mountPage() + + await wrapper.get('[data-testid="assets-refresh"]').trigger('click') + await flushPromises() + + expect(listOutputFolders).toHaveBeenCalledTimes(2) + expect(listOutputFolder).not.toHaveBeenCalled() + expect(listAssets).not.toHaveBeenCalled() }) - it('waits for the builds before it reads any folder', async () => { + it('shows an image card from its small thumbnail', async () => { + const wrapper = await mountAssets([ + asset('/out/forest.png', 'forest.png', 'image', { + previewUrl: 'comfy-output://file/full', + thumbnailUrl: 'comfy-output://file/full?thumbnail=1' + }) + ]) + + expect(wrapper.get('img').attributes('src')).toBe('comfy-output://file/full?thumbnail=1') + }) + + it('waits for the builds before it lists Comfy Cloud', async () => { + window.localStorage.setItem('comfy.desktop.assets.place', 'cloud') + signedInToPersonal() const installationStore = useInstallationStore() - const wrapper = mount(AssetsView, { attachTo: page, props: { installationId: 'mine' } }) + const wrapper = mount(AssetsView, { attachTo: page }) await flushPromises() - expect(listLocalAssets, 'no folder is read before the builds are known').not.toHaveBeenCalled() - expect(wrapper.find('[data-testid="assets-build-picker"]').exists()).toBe(false) + expect(listAssets, 'Comfy Cloud is not read before the builds are known').not.toHaveBeenCalled() expect(wrapper.findAll('[data-testid="assets-skeleton"] > li')).toHaveLength(8) - installationStore.installations = [localBuild('lab'), localBuild('mine', 'My Local 1')] + listAssets.mockResolvedValue([asset('c', 'cloud.png', 'image')]) + installationStore.installations = [cloudBuild('cloud')] installationStore.loading = false await flushPromises() - expect(wrapper.get('[data-testid="assets-build-picker"]').text()).toBe('My Local 1') - expect(listLocalAssets).toHaveBeenCalledExactlyOnceWith('mine') + expect(listAssets).toHaveBeenCalledExactlyOnceWith('cloud') }) it('keeps an empty page in place while the builds refresh', async () => { - const wrapper = await mountAssets() + const wrapper = await mountCloud() + await signInWith([]) useInstallationStore().loading = true await flushPromises() @@ -468,6 +658,27 @@ describe('AssetsView', () => { expect(wrapper.find('[data-testid="assets-skeleton"]').exists()).toBe(false) }) + it('keeps the toolbar on one row: search turns into a button, then the type tabs into a menu', async () => { + page.style.width = '1400px' + const wrapper = await mountAssets([asset('b', 'forest.png', 'image')]) + const shown = (testId: string) => wrapper.find(`[data-testid="${testId}"]`).exists() + const toolbarRow = () => wrapper.get('[data-testid="assets-toolbar"] > div').element + + await vi.waitFor(() => expect(shown('assets-kind-all')).toBe(true)) + expect(shown('assets-search-toggle')).toBe(false) + expect(shown('assets-kind-menu')).toBe(false) + + page.style.width = '700px' + await vi.waitFor(() => expect(shown('assets-kind-menu')).toBe(true)) + expect(shown('assets-kind-all')).toBe(false) + expect(shown('assets-search-toggle')).toBe(true) + expect(toolbarRow().scrollWidth).toBeLessThanOrEqual(toolbarRow().clientWidth) + + page.style.width = '1400px' + await vi.waitFor(() => expect(shown('assets-kind-all')).toBe(true)) + expect(shown('assets-search-toggle')).toBe(false) + }) + it('filters by asset type and by name', async () => { const wrapper = await mountAssets([ asset('a', 'surfer.mp4', 'video'), @@ -498,41 +709,9 @@ describe('AssetsView', () => { ]) }) - it('shows the output folder as This computer when there is no local build', async () => { - const wrapper = await mountAssets([asset('/out/forest.png', 'forest.png', 'image')], { - builds: [cloudBuild('cloud', 'Comfy Cloud')] - }) - - expect(wrapper.get('[data-testid="assets-build-picker"]').text()).toBe('This computer') - expect( - listLocalAssets, - 'the shared output folder, not a build' - ).toHaveBeenCalledExactlyOnceWith() - expect(assetNames(wrapper)).toEqual(['forest.png']) - await openBuildPicker(wrapper) - expect(buildRows()).toEqual(['Comfy Cloud Cloud · Running', 'This computer Output folder']) - }) - - it('reopens on This computer, not the saved Comfy Cloud pick, after signing out', async () => { - const builds = [cloudBuild('cloud', 'Comfy Cloud')] - const first = await mountAssets([], { builds }) - useAuthStore().status = { signedIn: true } - await flushPromises() - await openBuildPicker(first) - await pickBuild('cloud') - first.unmount() - - useAuthStore().status = { signedIn: false } - const again = await mountAssets([asset('/out/forest.png', 'forest.png', 'image')], { builds }) - - expect(again.get('[data-testid="assets-build-picker"]').text()).toBe('This computer') - expect(assetNames(again)).toEqual(['forest.png']) - }) - - it('asks a signed-out user who picked Comfy Cloud to log in', async () => { - const wrapper = await mountAssets([], { builds: [cloudBuild('cloud')] }) - await openBuildPicker(wrapper) - await pickBuild('cloud') + it('asks a signed-out user on Comfy Cloud to log in', async () => { + const wrapper = await mountPage({ builds: [cloudBuild('cloud')] }) + await choose(wrapper, 'cloud') expect(listAssets).not.toHaveBeenCalled() expect(wrapper.get('[data-testid="assets-empty"] h2').text()).toBe('Log in to see your assets') @@ -547,9 +726,7 @@ describe('AssetsView', () => { it('ignores a cancelled log-in', async () => { signIn.mockRejectedValueOnce(new Error('cancelled')) - const wrapper = await mountAssets([], { builds: [cloudBuild('cloud')] }) - await openBuildPicker(wrapper) - await pickBuild('cloud') + const wrapper = await mountCloud() await wrapper.get('[data-testid="assets-empty-action"]').trigger('click') await flushPromises() @@ -560,7 +737,7 @@ describe('AssetsView', () => { }) it('tells a signed-in user with no assets where they come from', async () => { - const wrapper = await mountAssets() + const wrapper = await mountCloud() await signInWith([]) expect(wrapper.get('[data-testid="assets-empty"] h2').text()).toBe('No assets yet') @@ -568,8 +745,24 @@ describe('AssetsView', () => { expect(wrapper.find('[data-testid="assets-empty-action"]').exists()).toBe(false) }) + it('says the workspace has no Comfy Cloud build yet', async () => { + const wrapper = await mountCloud([localBuild('lab')]) + useAuthStore().status = { signedIn: true, workspaceId: 'me', workspaceType: 'personal' } + await flushPromises() + + expect(listAssets).not.toHaveBeenCalled() + expect(wrapper.get('[data-testid="assets-empty"] h2').text()).toBe( + 'This workspace has no Comfy Cloud build yet' + ) + expect(wrapper.get('[data-testid="assets-empty"] p').text()).toBe( + 'Add Comfy Cloud to this workspace to see its assets here.' + ) + }) + it('shows a skeleton card per slot while the first load is pending', async () => { - const wrapper = await mountAssets(new Promise(() => {})) + listOutputFolder.mockReturnValue(new Promise(() => {})) + const wrapper = await mountPage() + await openFolder(wrapper, OUTPUT) expect(wrapper.findAll('[data-testid="assets-skeleton"] > li')).toHaveLength(8) }) @@ -586,7 +779,7 @@ describe('AssetsView', () => { }) it('downloads a Cloud file through the Cloud build', async () => { - const wrapper = await mountAssets() + const wrapper = await mountCloud() await signInWith([asset('c', 'cloud.png', 'image')]) await wrapper.get('[data-testid="asset-download-c"]').trigger('click') @@ -623,14 +816,14 @@ describe('AssetsView', () => { }) }) - it('does not reload when another build changes but the picked build stays the same', async () => { + it('does not read the folder again when a build changes or the user logs in', async () => { await mountAssets([asset('a', 'forest.png', 'image')]) useInstallationStore().installations = [localBuild('lab'), localBuild('other', 'Video Lab')] - useSessionStore().runningInstances.set('lab', { installationId: 'lab' } as RunningInstance) + useAuthStore().status = { signedIn: true } await flushPromises() - expect(listLocalAssets).toHaveBeenCalledOnce() + expect(listOutputFolder).toHaveBeenCalledOnce() }) it('delays the first name tooltip, then shows the rest at once until the pointer leaves', async () => { @@ -638,60 +831,39 @@ describe('AssetsView', () => { asset('a', 'surfer.mp4', 'video'), asset('b', 'forest.png', 'image') ]) - const delays = () => wrapper.findAllComponents(Tooltip).map((tip) => tip.props('delayMs')) + const grid = wrapper.get('[data-testid="assets-grid"]') + const delays = () => grid.findAllComponents(Tooltip).map((tip) => tip.props('delayMs')) expect(delays()).toEqual([600, 600]) vi.useFakeTimers() try { - await wrapper.get('[data-testid="assets-grid"]').trigger('pointerenter') + await grid.trigger('pointerenter') await vi.advanceTimersByTimeAsync(600) expect(delays()).toEqual([0, 0]) - await wrapper.get('[data-testid="assets-grid"]').trigger('pointerleave') + await grid.trigger('pointerleave') expect(delays()).toEqual([600, 600]) } finally { vi.useRealTimers() } }) - it('stays on the build it opened on when another build starts', async () => { - const wrapper = await mountAssets([asset('a', 'forest.png', 'image')], { - builds: [ - localBuild('mine', 'My Local 1', { lastLaunchedAt: 1 }), - localBuild('lab', 'Video Lab', { lastLaunchedAt: 2 }) - ] - }) - expect(wrapper.get('[data-testid="assets-build-picker"]').text()).toBe('Video Lab') - - useSessionStore().runningInstances.set('mine', { installationId: 'mine' } as RunningInstance) - useInstallationStore().installations = [ - localBuild('mine', 'My Local 1', { lastLaunchedAt: 3 }), - localBuild('lab', 'Video Lab', { lastLaunchedAt: 2 }) - ] - await flushPromises() - - expect(wrapper.get('[data-testid="assets-build-picker"]').text()).toBe('Video Lab') - expect(listLocalAssets).toHaveBeenCalledExactlyOnceWith('lab') - }) - - it('switches to the builds of the workspace the user moves to', async () => { + it('lists the Cloud build of the workspace the user moves to', async () => { listAssets.mockResolvedValue([asset('t1', 'team.png', 'image')]) - const wrapper = await mountAssets([asset('a', 'forest.png', 'image')], { - builds: [localBuild('lab', 'Video Lab'), teamBuild(cloudBuild('team-cloud', 'Team Cloud'))] - }) + const wrapper = await mountCloud([ + localBuild('lab', 'Video Lab'), + teamBuild(cloudBuild('team-cloud', 'Team Cloud')) + ]) useAuthStore().status = { signedIn: true, workspaceId: 'team-b' } await flushPromises() - expect(wrapper.get('[data-testid="assets-build-picker"]').text()).toBe('Team Cloud') expect(listAssets).toHaveBeenCalledExactlyOnceWith('team-cloud') expect(assetNames(wrapper)).toEqual(['team.png']) }) - it("moves the Cloud session to the picked Cloud build's workspace before listing its assets", async () => { - const wrapper = await mountAssets([], { - builds: [teamBuild(cloudBuild('team-cloud', 'Team Cloud'))] - }) + it("moves the Cloud session to the Cloud build's workspace before listing its assets", async () => { + const wrapper = await mountCloud([teamBuild(cloudBuild('team-cloud', 'Team Cloud'))]) useAuthStore().status = { signedIn: true, workspaceId: 'me', workspaceType: 'personal' } await flushPromises() listAssets.mockImplementation(async () => @@ -701,7 +873,6 @@ describe('AssetsView', () => { useDashboardScopeStore().selectWorkspace('team-b') await flushPromises() - expect(wrapper.get('[data-testid="assets-build-picker"]').text()).toBe('Team Cloud') expect(switchWorkspace).toHaveBeenCalledExactlyOnceWith('team-b', 'chosen') expect(assetNames(wrapper), "the team's files, not the personal workspace's").toEqual([ 'team.png' @@ -711,13 +882,12 @@ describe('AssetsView', () => { it("says the load failed instead of showing another workspace's files when the personal workspace is unknown", async () => { listAssets.mockResolvedValue([asset('t1', 'team.png', 'image')]) listWorkspaces.mockResolvedValue([{ id: 'team-b', name: 'Team B', type: 'team' }]) - const wrapper = await mountAssets([], { builds: [cloudBuild('cloud', 'Comfy Cloud')] }) + const wrapper = await mountCloud([cloudBuild('cloud', 'Comfy Cloud')]) useAuthStore().status = { signedIn: true, workspaceId: 'team-b', workspaceType: 'team' } await flushPromises() useDashboardScopeStore().selectWorkspace('personal') await flushPromises() - expect(wrapper.get('[data-testid="assets-build-picker"]').text()).toBe('Comfy Cloud') expect(listAssets).not.toHaveBeenCalled() expect(wrapper.get('[data-testid="assets-empty"]').text()).toContain("Couldn't load assets") }) @@ -725,7 +895,7 @@ describe('AssetsView', () => { it('does not list Cloud files with a session tied to no known workspace', async () => { listAssets.mockResolvedValue([asset('x1', 'unknown.png', 'image')]) listWorkspaces.mockResolvedValue([{ id: 'team-b', name: 'Team B', type: 'team' }]) - const wrapper = await mountAssets([], { builds: [cloudBuild('cloud', 'Comfy Cloud')] }) + const wrapper = await mountCloud([cloudBuild('cloud', 'Comfy Cloud')]) useAuthStore().status = { signedIn: true } await flushPromises() @@ -737,11 +907,8 @@ describe('AssetsView', () => { signedInToPersonalWithTeamDashboard() listAssets.mockResolvedValue([asset('t1', 'team.png', 'image')]) - const wrapper = await mountAssets([], { - builds: [teamBuild(cloudBuild('team-cloud', 'Team Cloud'))] - }) + const wrapper = await mountCloud([teamBuild(cloudBuild('team-cloud', 'Team Cloud'))]) - expect(wrapper.get('[data-testid="assets-build-picker"]').text()).toBe('Team Cloud') expect(switchWorkspace).toHaveBeenCalledExactlyOnceWith('team-b', 'restored') expect(assetNames(wrapper)).toEqual(['team.png']) }) @@ -755,9 +922,7 @@ describe('AssetsView', () => { workspaceType: 'personal', workspaceSwitchFailure: 'retryable' }) - const wrapper = await mountAssets([], { - builds: [teamBuild(cloudBuild('team-cloud', 'Team Cloud'))] - }) + const wrapper = await mountCloud([teamBuild(cloudBuild('team-cloud', 'Team Cloud'))]) expect(listAssets, "the personal workspace's files are not listed").not.toHaveBeenCalled() expect(wrapper.get('[data-testid="assets-empty"]').text()).toContain("Couldn't load assets") @@ -772,33 +937,28 @@ describe('AssetsView', () => { expect(assetNames(wrapper)).toEqual(['team.png']) }) - it("moves the session to a Cloud build's workspace as the user's choice when they pick the build", async () => { + it("moves the session to the Cloud build's workspace as the user's choice when they pick Comfy Cloud", async () => { signedInToPersonalWithTeamDashboard() listAssets.mockResolvedValue([asset('t1', 'team.png', 'image')]) - const wrapper = await mountAssets([], { - builds: [ - teamBuild(localBuild('team-lab', 'Team Lab', { lastLaunchedAt: 5 })), - teamBuild(cloudBuild('team-cloud', 'Team Cloud')) - ] + const wrapper = await mountPage({ + builds: [teamBuild(localBuild('team-lab', 'Team Lab')), teamBuild(cloudBuild('team-cloud'))] }) - expect(wrapper.get('[data-testid="assets-build-picker"]').text()).toBe('Team Lab') - expect(switchWorkspace, 'a local build needs no workspace').not.toHaveBeenCalled() + expect(switchWorkspace, 'This computer needs no workspace').not.toHaveBeenCalled() - await openBuildPicker(wrapper) - await pickBuild('team-cloud') + await choose(wrapper, 'cloud') expect(switchWorkspace).toHaveBeenCalledExactlyOnceWith('team-b', 'chosen') expect(assetNames(wrapper)).toEqual(['team.png']) }) - it('clears the previous workspace assets while the new workspace loads', async () => { + it('clears the files of the place the user left while the next one loads', async () => { + signedInToPersonal() listAssets.mockReturnValue(new Promise(() => {})) const wrapper = await mountAssets([asset('a', 'forest.png', 'image')], { - builds: [localBuild('lab'), teamBuild(cloudBuild('team-cloud'))] + builds: [cloudBuild('cloud')] }) - useAuthStore().status = { signedIn: true, workspaceId: 'team-b' } - await flushPromises() + await choose(wrapper, 'cloud') expect(wrapper.find('[data-testid="assets-grid"]').exists()).toBe(false) expect(wrapper.find('[data-testid="assets-skeleton"]').exists()).toBe(true) @@ -812,8 +972,10 @@ describe('AssetsView', () => { expect(wrapper.get('[data-testid="assets-empty"]').text()).toContain('No matching assets') }) - it('reports a failed load', async () => { - const wrapper = await mountAssets(Promise.reject(new Error('disk'))) + it('reports a failed Cloud load', async () => { + signedInToPersonal() + listAssets.mockRejectedValue(new Error('offline')) + const wrapper = await mountCloud() expect(wrapper.get('[data-testid="assets-empty"]').text()).toContain("Couldn't load assets") }) @@ -830,7 +992,7 @@ describe('AssetsView', () => { }) it('offers only Download and Copy for a Cloud file, from the more actions button', async () => { - const wrapper = await mountAssets() + const wrapper = await mountCloud() await signInWith([picture('c', 300)]) await wrapper.get('[data-testid="asset-more-c"]').trigger('click') @@ -899,6 +1061,34 @@ describe('AssetsView', () => { expect(document.activeElement).toBe(card.element) }) + it('tells where a file on this computer is saved in the viewer, and shows it in Finder', async () => { + const wrapper = await mountAssets([asset(`${OUTPUT}/forest.png`, 'forest.png', 'image')]) + + await wrapper.get(`[data-testid="asset-open-${OUTPUT}/forest.png"]`).trigger('click') + await flushPromises() + + expect(shownText(viewer()!.querySelector('[data-testid="output-detail-saved-in"]'))).toBe( + 'SAVED IN output /Users/me/ComfyUI-Shared' + ) + const show = viewer()!.querySelector( + '[data-testid="output-detail-show-in-folder"]' + )! + expect(show.textContent?.trim()).toBe('Show in Finder') + show.click() + expect(revealAsset).toHaveBeenCalledExactlyOnceWith('local', `${OUTPUT}/forest.png`) + }) + + it('does not say where a Cloud file is saved in the viewer', async () => { + const wrapper = await mountCloud() + await signInWith([asset('c', 'cloud.png', 'image')]) + + await wrapper.get('[data-testid="asset-open-c"]').trigger('click') + await flushPromises() + + expect(viewer()!.querySelector('[data-testid="output-detail-saved-in"]')).toBeNull() + expect(viewer()!.querySelector('[data-testid="output-detail-show-in-folder"]')).toBeNull() + }) + it('steps through the files in page order with the arrow keys and the filmstrip', async () => { const wrapper = await mountAssets([ asset('new', 'new.png', 'image', { createdAt: '2026-11-03T00:00:00Z' }), diff --git a/src/renderer/src/panel/AssetsView.vue b/src/renderer/src/panel/AssetsView.vue index aa0f38239..89d7ee822 100644 --- a/src/renderer/src/panel/AssetsView.vue +++ b/src/renderer/src/panel/AssetsView.vue @@ -1,20 +1,18 @@ + + diff --git a/src/renderer/src/panel/LocalFolders.vue b/src/renderer/src/panel/LocalFolders.vue new file mode 100644 index 000000000..508d399d8 --- /dev/null +++ b/src/renderer/src/panel/LocalFolders.vue @@ -0,0 +1,266 @@ + + + diff --git a/src/renderer/src/panel/OutputDetailDialog.vue b/src/renderer/src/panel/OutputDetailDialog.vue index 9eee9bd55..ac20238f6 100644 --- a/src/renderer/src/panel/OutputDetailDialog.vue +++ b/src/renderer/src/panel/OutputDetailDialog.vue @@ -3,7 +3,7 @@ import { computed, nextTick, ref, useTemplateRef, watch } from 'vue' import { useI18n } from 'vue-i18n' import { useEventListener, usePreferredReducedMotion } from '@vueuse/core' import { DropdownMenuRadioGroup } from 'reka-ui' -import { AudioLines, Box, Check, ChevronDown, Download, File, X } from '@lucide/vue' +import { AudioLines, Box, Check, ChevronDown, Download, File, FolderSearch, X } from '@lucide/vue' import Button from '@comfyorg/design-system/button/Button' import Tag from '@comfyorg/design-system/chip/Tag' import AudioPreview from '@comfyorg/design-system/media/AudioPreview' @@ -13,6 +13,7 @@ import DesktopDialogSurface from '../components/ui/DesktopDialogSurface.vue' import InfoTooltip from '../components/InfoTooltip.vue' import OutputDetailThumb from './OutputDetailThumb.vue' import { formatBytes } from '../lib/downloadFormatters' +import { revealInFolderKey } from '../composables/usePlatform' import type { AssetKind } from '../types/ipc' export interface OutputDetailItem { @@ -24,6 +25,7 @@ export interface OutputDetailItem { tags: string[] previewUrl: string | null thumbnailUrl: string | null + savedIn?: string | null } type Zoom = 'fit' | 0.5 | 1 | 2 @@ -39,9 +41,11 @@ const index = defineModel('index', { required: true }) const emit = defineEmits<{ close: [] download: [index: number] + 'show-in-folder': [index: number] }>() const { t, locale } = useI18n() +const revealKey = revealInFolderKey(window.api.platform) const preferredMotion = usePreferredReducedMotion() const filmstrip = useTemplateRef('filmstrip') const natural = ref<{ width: number; height: number } | null>(null) @@ -72,6 +76,12 @@ const facts = computed(() => item.value.sizeBytes === null ? null : formatBytes(item.value.sizeBytes) ].filter((fact): fact is string => !!fact) ) +const savedFolder = computed(() => { + const folder = item.value.savedIn + if (!folder) return null + const cut = Math.max(folder.lastIndexOf('/'), folder.lastIndexOf('\\')) + return { name: folder.slice(cut + 1) || folder, parent: cut > 0 ? folder.slice(0, cut) : '' } +}) const percent = computed(() => new Intl.NumberFormat(locale.value, { style: 'percent' })) const zoomLabel = computed(() => zoom.value === 'fit' ? t('assets.detail.fit') : percent.value.format(zoom.value) @@ -269,6 +279,18 @@ useEventListener(window, 'keydown', (event: KeyboardEvent) => { +
+
+ {{ t('assets.detail.savedIn') }} +
+
+ {{ savedFolder.name }} + {{ + savedFolder.parent + }} +
+
+
+
diff --git a/src/renderer/src/preview/fakeBridge.ts b/src/renderer/src/preview/fakeBridge.ts index 21033098f..9c13a04c8 100644 --- a/src/renderer/src/preview/fakeBridge.ts +++ b/src/renderer/src/preview/fakeBridge.ts @@ -250,7 +250,8 @@ export function createFakeBridge(seed: BridgeSeed = {}): FakeBridge { signalOverlayReady: () => {}, navigatePanel: () => {}, listAssets: async () => [], - listLocalAssets: async () => [], + listOutputFolders: async () => [], + listOutputFolder: async () => null, downloadAsset: async () => true, revealAsset: async () => true, copyAsset: async () => true, diff --git a/src/renderer/src/preview/fixtures.ts b/src/renderer/src/preview/fixtures.ts index 628de722f..d1291543b 100644 --- a/src/renderer/src/preview/fixtures.ts +++ b/src/renderer/src/preview/fixtures.ts @@ -5,6 +5,7 @@ import type { FieldOption, GPUInfo, Installation, + OutputFolder, ProgressStep, Source, SystemInfo @@ -311,6 +312,16 @@ export const HOME_WORKFLOWS: CatalogWorkflow[] = [ } ] +export function outputFolders(machine: PreviewMachine): OutputFolder[] { + return [ + { + path: joinPath(machine, 'output'), + builds: ['ComfyUI', 'Video experiments'], + buildIds: ['inst-comfyui', 'inst-video-experiments'] + } + ] +} + export function localAssets(): AssetSummary[] { return ['harbor-at-dusk.png', 'paper-crane.png', 'studio-portrait.png'].map((name, index) => ({ id: `asset-${index + 1}`, diff --git a/src/renderer/src/preview/scenarios.ts b/src/renderer/src/preview/scenarios.ts index b31f40fab..aee649e0d 100644 --- a/src/renderer/src/preview/scenarios.ts +++ b/src/renderer/src/preview/scenarios.ts @@ -1,5 +1,11 @@ import type { BridgeSeed, FakeBridge } from './fakeBridge' -import { INSTALL_STEPS, everydayBuilds, localAssets, type PreviewMachine } from './fixtures' +import { + INSTALL_STEPS, + everydayBuilds, + localAssets, + outputFolders, + type PreviewMachine +} from './fixtures' export interface PreviewStage { bridge: FakeBridge @@ -120,7 +126,10 @@ export const SCENARIOS: PreviewScenario[] = [ ready: '[data-testid="app-sidebar-assets"][aria-current="page"]', seed: (machine) => ({ installations: everydayBuilds(machine), - replies: { listLocalAssets: async () => localAssets() } + replies: { + listOutputFolders: async () => outputFolders(machine), + listOutputFolder: async () => ({ folders: [], files: localAssets(), truncated: false }) + } }), arrange: async ({ click }) => { await click('[data-testid="app-sidebar-assets"]') diff --git a/src/renderer/src/types/ipc.ts b/src/renderer/src/types/ipc.ts index 351549c76..d86238ad3 100644 --- a/src/renderer/src/types/ipc.ts +++ b/src/renderer/src/types/ipc.ts @@ -5,6 +5,9 @@ export type { AppPageStatus, AssetKind, AssetSummary, + OutputFolder, + OutputFolderListing, + OutputSubfolder, CatalogWorkflow, Unsubscribe, BetaActivationNotice, diff --git a/src/types/ipc.ts b/src/types/ipc.ts index 263658151..531093c18 100644 --- a/src/types/ipc.ts +++ b/src/types/ipc.ts @@ -121,7 +121,6 @@ export interface Installation { launchMode?: string launchArgs?: string hasConsole?: boolean - hasOutputFolder?: boolean installPath?: string status?: string lastLaunchedAt?: number @@ -175,6 +174,23 @@ export interface AssetSummary { durationSeconds: number | null } +export interface OutputFolder { + path: string + builds: string[] + buildIds: string[] +} + +export interface OutputSubfolder { + name: string + path: string +} + +export interface OutputFolderListing { + folders: OutputSubfolder[] + files: AssetSummary[] + truncated: boolean +} + export interface BuildStorageSnapshot { sharedDirectoriesFields: Record[] modelsDirs: { path: string; isPrimary: boolean }[] @@ -1161,7 +1177,8 @@ export interface ElectronApi { signalOverlayReady(): void navigatePanel(page: DashboardPage): void listAssets(installationId: string): Promise - listLocalAssets(installationId?: string): Promise + listOutputFolders(): Promise + listOutputFolder(folderPath: string): Promise downloadAsset(source: string, assetId: string, fileName: string): Promise revealAsset(source: string, assetId: string): Promise copyAsset(source: string, assetId: string): Promise From 7231d4554123c8d29b1800ba920b110095395948 Mon Sep 17 00:00:00 2001 From: PabloWiedemann Date: Mon, 16 Nov 2026 13:42:05 -0800 Subject: [PATCH 2/5] refactor(assets): trim the This computer view to its scope Drop the cut-to-newest-files notice and the ten-name cap in the folder tooltip, derive the Cloud choice from the picked place, keep the folder trail as plain paths, and show the folder load error in the same empty state as no folders. --- locales/en.json | 4 +- locales/zh.json | 4 +- src/main/lib/outputFolders.test.ts | 6 +-- src/main/lib/outputFolders.ts | 6 +-- src/renderer/src/panel/AssetsView.test.ts | 33 +++--------- src/renderer/src/panel/AssetsView.vue | 65 +++++++---------------- src/renderer/src/panel/LocalFolders.vue | 56 ++++++------------- src/renderer/src/preview/scenarios.ts | 2 +- src/types/ipc.ts | 1 - 9 files changed, 49 insertions(+), 128 deletions(-) diff --git a/locales/en.json b/locales/en.json index fd076b3c9..beaa05d83 100644 --- a/locales/en.json +++ b/locales/en.json @@ -133,15 +133,13 @@ "folderActions": "Folder actions", "noBuilds": "No build saves here yet", "savedBy": "Saved here by", - "moreBuilds": "and 1 more | and {count} more", "openFolder": "Open folder", "path": "Folder path", "noFoldersTitle": "No output folders yet", "noFoldersBody": "Files appear here after you run a workflow with ComfyUI on this computer.", "emptyFolder": "No images, videos, audio or 3D files here.", "folderFailed": "Couldn't open this folder. It may have been moved or deleted.", - "backToComputer": "Back to This computer", - "truncated": "Showing the newest file. Open the folder to see all of them. | Showing the newest {count} files. Open the folder to see all of them." + "backToComputer": "Back to This computer" } }, "home": { diff --git a/locales/zh.json b/locales/zh.json index 8c605a76c..817daa6f2 100644 --- a/locales/zh.json +++ b/locales/zh.json @@ -133,15 +133,13 @@ "folderActions": "文件夹操作", "noBuilds": "还没有构建保存到这里", "savedBy": "保存到这里的构建", - "moreBuilds": "还有 {count} 个", "openFolder": "打开文件夹", "path": "文件夹路径", "noFoldersTitle": "还没有输出文件夹", "noFoldersBody": "在这台电脑上用 ComfyUI 运行工作流后,文件会显示在这里。", "emptyFolder": "这里没有图片、视频、音频或 3D 文件。", "folderFailed": "无法打开此文件夹。它可能已被移动或删除。", - "backToComputer": "返回这台电脑", - "truncated": "仅显示最新的 {count} 个文件。打开文件夹可查看全部。" + "backToComputer": "返回这台电脑" } }, "home": { diff --git a/src/main/lib/outputFolders.test.ts b/src/main/lib/outputFolders.test.ts index fa9dd1c4c..c719b996c 100644 --- a/src/main/lib/outputFolders.test.ts +++ b/src/main/lib/outputFolders.test.ts @@ -216,7 +216,6 @@ describe('listOutputFolder', () => { { name: 'Apps', path: path.join(sharedDir, 'Apps') }, { name: 'video', path: path.join(sharedDir, 'video') } ]) - expect(listing!.truncated).toBe(false) expect(listing!.files.map((a) => a.name)).toEqual(['new.mp4', 'mesh.glb', 'old.png']) const newVideo = path.join(sharedDir, 'new.mp4') expect(listing!.files[0]).toEqual({ @@ -295,7 +294,7 @@ describe('listOutputFolder', () => { } }) - it('keeps only the newest files when a folder is very large, and says so', async () => { + it('keeps only the newest files when a folder is very large', async () => { for (let i = 0; i <= MAX_LOCAL_ASSETS; i++) write(path.join(sharedDir, `f${i}.png`), '', new Date(Date.UTC(2026, 0, 1, 0, 0, i))) await listOutputFolders() @@ -304,7 +303,6 @@ describe('listOutputFolder', () => { expect(listing!.files).toHaveLength(MAX_LOCAL_ASSETS) expect(listing!.files.map((a) => a.name)).not.toContain('f0.png') - expect(listing!.truncated).toBe(true) }) it('does not follow links out of an output folder', async () => { @@ -313,7 +311,7 @@ describe('listOutputFolder', () => { fs.symlinkSync(path.join(outsideDir, 'secret.png'), path.join(sharedDir, 'secret.png')) await listOutputFolders() - expect(await listOutputFolder(sharedDir)).toEqual({ folders: [], files: [], truncated: false }) + expect(await listOutputFolder(sharedDir)).toEqual({ folders: [], files: [] }) expect(await listOutputFolder(path.join(sharedDir, 'escape'))).toBeNull() }) }) diff --git a/src/main/lib/outputFolders.ts b/src/main/lib/outputFolders.ts index 5598a5444..dc1e418ed 100644 --- a/src/main/lib/outputFolders.ts +++ b/src/main/lib/outputFolders.ts @@ -178,11 +178,7 @@ export async function listOutputFolder(target: unknown): Promise b.createdAt!.localeCompare(a.createdAt!)) .slice(0, MAX_LOCAL_ASSETS) await runPool(newest, STATS_AT_ONCE, addMediaFacts) - return { - folders: folders.sort((a, b) => a.name.localeCompare(b.name)), - files: newest, - truncated: found.length > MAX_LOCAL_ASSETS - } + return { folders: folders.sort((a, b) => a.name.localeCompare(b.name)), files: newest } } function linuxThumbnailSource(file: string, sizeBytes: number): Electron.NativeImage | null { diff --git a/src/renderer/src/panel/AssetsView.test.ts b/src/renderer/src/panel/AssetsView.test.ts index e16d55316..a91641a8e 100644 --- a/src/renderer/src/panel/AssetsView.test.ts +++ b/src/renderer/src/panel/AssetsView.test.ts @@ -80,12 +80,8 @@ function asset( } } -function listing( - files: AssetSummary[], - folders: OutputSubfolder[] = [], - truncated = false -): OutputFolderListing { - return { folders, files, truncated } +function listing(files: AssetSummary[], folders: OutputSubfolder[] = []): OutputFolderListing { + return { folders, files } } function cloudBuild(id: string, name = id): Installation { @@ -414,25 +410,23 @@ describe('AssetsView', () => { }) it('names every build that saves to a folder when its +N button is focused', async () => { - const builds = Array.from({ length: 13 }, (_, i) => `Build ${i + 1}`) + const builds = ['Build 1', 'Build 2', 'Build 3'] const wrapper = await mountPage({ folders: [outputFolder(OUTPUT, builds)] }) const more = wrapper.get(`[data-testid="local-folder-more-${OUTPUT}"]`) - expect(more.text()).toBe('+11') + expect(more.text()).toBe('+1') await more.trigger('focusin') await flushPromises() const bubble = document.querySelector('.tooltip-bubble')?.textContent ?? '' expect(bubble).toContain('Saved here by') - expect(bubble, 'up to ten names').toContain('Build 10') - expect(bubble).not.toContain('Build 11') - expect(bubble, 'then how many more').toContain('and 3 more') + expect(bubble).toContain('Build 3') }) it('says when there is no output folder yet', async () => { const wrapper = await mountPage({ folders: [] }) - expect(text(wrapper, 'local-no-folders')).toContain('No output folders yet') + expect(text(wrapper, 'local-folders-empty')).toContain('No output folders yet') }) it('walks into a folder and its subfolders, and back with the path', async () => { @@ -511,19 +505,6 @@ describe('AssetsView', () => { expect(openPath).toHaveBeenCalledExactlyOnceWith(OUTPUT) }) - it('says when a folder is cut to its newest files', async () => { - listOutputFolder.mockResolvedValue( - listing([asset(`${OUTPUT}/a.png`, 'a.png', 'image')], [], true) - ) - const wrapper = await mountPage() - - await openFolder(wrapper, OUTPUT) - - expect(text(wrapper, 'assets-truncated')).toBe( - 'Showing the newest file. Open the folder to see all of them.' - ) - }) - it('says a folder could not be opened, with a way back to This computer', async () => { listOutputFolder.mockResolvedValue(null) const wrapper = await mountPage() @@ -543,7 +524,7 @@ describe('AssetsView', () => { const wrapper = mount(AssetsView, { attachTo: page }) await flushPromises() - expect(text(wrapper, 'local-failed')).toBe("Couldn't load assets") + expect(text(wrapper, 'local-folders-empty')).toBe("Couldn't load assets") }) it('remembers the place the user chose', async () => { diff --git a/src/renderer/src/panel/AssetsView.vue b/src/renderer/src/panel/AssetsView.vue index 89d7ee822..0052d8a63 100644 --- a/src/renderer/src/panel/AssetsView.vue +++ b/src/renderer/src/panel/AssetsView.vue @@ -32,7 +32,6 @@ import ContextMenu from '../components/ContextMenu.vue' import SegmentedControl from '../components/ui/SegmentedControl.vue' import Tooltip from '../components/ui/Tooltip.vue' import LocalFolders from './LocalFolders.vue' -import type { FolderCrumb } from './LocalFolders.vue' import OutputDetailDialog from './OutputDetailDialog.vue' import type { OutputDetailItem } from './OutputDetailDialog.vue' import { useModal } from '../composables/useModal' @@ -75,7 +74,6 @@ interface Loaded { assets: GalleryAsset[] folders: OutputFolder[] | null subfolders: OutputSubfolder[] - truncated: boolean } interface Shape { @@ -127,12 +125,10 @@ 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 cloudChosenHere = ref(false) let windowFolderOpened = false -const trail = ref([]) +const trail = ref([]) const outputFolders = ref(null) const subfolders = ref([]) -const truncated = ref(false) const assets = ref([]) const scroller = useTemplateRef('scroller') @@ -181,7 +177,6 @@ const placeOptions = computed(() => [ function choosePlace(next: Place): void { pickedPlace.value = next savedPlace.value = next - cloudChosenHere.value = next === 'cloud' } function openWindowBuildFolder(folders: OutputFolder[] | null): void { @@ -190,13 +185,11 @@ function openWindowBuildFolder(folders: OutputFolder[] | null): void { return windowFolderOpened = true const folder = folders.find((candidate) => candidate.buildIds.includes(build.id)) - if (!folder) return - const name = folder.path.split(/[\\/]/).filter(Boolean).at(-1) ?? folder.path - trail.value = [{ name, path: folder.path }] + if (folder) trail.value = [folder.path] } -function enterFolder(crumb: FolderCrumb): void { - trail.value = [...trail.value, crumb] +function enterFolder(folderPath: string): void { + trail.value = [...trail.value, folderPath] } function goToFolder(depth: number): void { @@ -240,9 +233,8 @@ const kindOptions = computed(() => })) ) -const currentKind = computed( - () => - kindOptions.value.find((option) => option.value === kindFilter.value) ?? kindOptions.value[0] +const currentKind = computed(() => + kindOptions.value.find((option) => option.value === kindFilter.value)! ) async function fitToolbar(): Promise { @@ -389,29 +381,23 @@ async function moveSessionToWorkspaceOf(build: Installation, userAsked: boolean) } async function loadPlace(userAsked: boolean): Promise { - const none: Loaded = { - assets: [], - folders: outputFolders.value, - subfolders: [], - truncated: false - } + const none: Loaded = { assets: [], folders: outputFolders.value, subfolders: [] } const folder = currentFolder.value if (place.value === 'computer' && !folder) { return { ...none, folders: await window.api.listOutputFolders() } } if (folder) { - const listing = await window.api.listOutputFolder(folder.path) + const listing = await window.api.listOutputFolder(folder) if (!listing) throw new Error('the folder could not be read') return { ...none, assets: listing.files.map((asset) => ({ ...asset, source: LOCAL_ASSETS_SOURCE })), - subfolders: listing.folders, - truncated: listing.truncated + subfolders: listing.folders } } const build = cloudBuild.value if (!build || !authStore.isSignedIn) return none - await moveSessionToWorkspaceOf(build, userAsked || cloudChosenHere.value) + await moveSessionToWorkspaceOf(build, userAsked || pickedPlace.value === 'cloud') const listed = await window.api.listAssets(build.id) return { ...none, assets: listed.map((asset) => ({ ...asset, source: build.id })) } } @@ -426,7 +412,6 @@ async function loadAssets(userAsked = false): Promise { assets.value = loaded.assets outputFolders.value = loaded.folders subfolders.value = loaded.subfolders - truncated.value = loaded.truncated } catch { if (current !== requestId) return assets.value = [] @@ -443,7 +428,7 @@ const accountContext = computed( const loadKey = computed(() => { if (windowHintPending.value) return '' - if (place.value === 'computer') return `computer\n${currentFolder.value?.path ?? ''}` + if (place.value === 'computer') return `computer\n${currentFolder.value ?? ''}` if (!buildsKnown.value) return '' return `cloud\n${cloudBuild.value?.id ?? ''}\n${accountContext.value}` }) @@ -453,7 +438,6 @@ watch( (key) => { assets.value = [] subfolders.value = [] - truncated.value = false if (key) void loadAssets() else { requestId++ @@ -493,7 +477,7 @@ const detailItems = computed(() => tags: asset.tags, previewUrl: asset.previewUrl, thumbnailUrl: asset.thumbnailUrl, - savedIn: isLocal(asset) ? (currentFolder.value?.path ?? null) : null + savedIn: isLocal(asset) ? currentFolder.value : null })) ) @@ -673,17 +657,13 @@ function extensionOf(name: string): string { :label="t('assets.placeLabel')" @update:model-value="choosePlace" /> -
- -
-
+ +
-

- {{ t('assets.local.truncated', assets.length) }} -

() const emit = defineEmits<{ - enter: [crumb: FolderCrumb] + enter: [folderPath: string] go: [depth: number] }>() @@ -35,7 +29,7 @@ const { t } = useI18n() const idPrefix = useId() const current = computed(() => trail.at(-1) ?? null) -const crumbs = computed(() => [{ name: t('assets.thisComputer'), path: '' }, ...trail]) +const crumbs = computed(() => [t('assets.thisComputer'), ...trail.map(folderName)]) function pathParts(path: string): string[] { return path.split(/[\\/]/).filter(Boolean) @@ -99,7 +93,7 @@ function openFolder(path: string): void { class="truncate text-foreground" aria-current="page" > - {{ crumb.name }} + {{ crumb }} @@ -117,9 +111,9 @@ function openFolder(path: string): void { variant="secondary" size="md" class="ml-auto shrink-0 gap-1.5 px-3 text-ui" - :title="current.path" + :title="current" data-testid="local-open-folder" - @click="openFolder(current.path)" + @click="openFolder(current)" >