Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,20 @@
},
"assets": {
"kindLabel": "Asset type",
"buildPickerLabel": "Build",
"browseAssetsOf": "Browse the assets of",
"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",
Expand Down Expand Up @@ -104,7 +118,6 @@
"deleteFailed": "Couldn't delete asset",
"noMatches": "No matching assets",
"noMatchesHint": "Try another type or search.",
"filter": "Filter",
"signedOutTitle": "Log in to see your assets",
"signedOutBody": "Assets that you make in Comfy Cloud show here.",
"signIn": "Log in to Comfy Cloud",
Expand Down
15 changes: 14 additions & 1 deletion locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,20 @@
},
"assets": {
"kindLabel": "资产类型",
"buildPickerLabel": "构建",
"browseAssetsOf": "浏览以下构建的资产",
"thisComputer": "这台电脑",
"outputFolder": "输出文件夹",
"buildStatus": "{where} · {state}",
"buildWhere": {
"local": "本地",
"cloud": "云端"
},
"buildState": {
"running": "运行中",
"starting": "启动中",
"stopped": "已停止"
},
"kind": {
"all": "全部",
"image": "图片",
Expand Down Expand Up @@ -104,7 +118,6 @@
"deleteFailed": "无法删除资产",
"noMatches": "没有匹配的资产",
"noMatchesHint": "试试其他类型或搜索词。",
"filter": "筛选",
"signedOutTitle": "登录以查看你的资产",
"signedOutBody": "你在 Comfy Cloud 中生成的资产会显示在这里。",
"signIn": "登录 Comfy Cloud",
Expand Down
78 changes: 78 additions & 0 deletions src/main/lib/ipc/installationsForRenderer.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
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
})
})
})
2 changes: 2 additions & 0 deletions src/main/lib/ipc/registerInstallationHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ 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'
Expand Down Expand Up @@ -129,6 +130,7 @@ 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 } : {})
Expand Down
81 changes: 61 additions & 20 deletions src/main/lib/outputFolders.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,8 @@ vi.mock('../settings', () => ({
}))
vi.mock('./ipc/shared', () => ({
sourceMap: {
standalone: { category: 'local', getLaunchCommand: () => ({ cmd: 'python' }) },
desktop: {
category: 'local',
getLaunchCommand: () => ({ cmd: 'open', skipSharedPaths: true })
},
standalone: { category: 'local' },
desktop: { category: 'local', managesOwnPaths: true },
cloud: { category: 'cloud' }
}
}))
Expand All @@ -89,6 +86,7 @@ import {
MAX_LOCAL_ASSETS,
THUMBNAIL_WAIT_MS,
copyOutputImage,
hasOutputFolder,
revealOutputFile,
trashOutputFile,
listLocalAssets,
Expand Down Expand Up @@ -164,6 +162,22 @@ describe('outputDirOverride', () => {
})
})

describe('hasOutputFolder', () => {
it('is true only for a local build that leaves its paths to Desktop', () => {
expect(hasOutputFolder(install('a')), 'a build on the shared folder').toBe(true)
expect(
hasOutputFolder(install('a', { useSharedOutput: false })),
'a build that saves inside its install'
).toBe(true)
expect(hasOutputFolder(install('a', { sourceId: 'cloud' })), 'Cloud').toBe(false)
expect(
hasOutputFolder(install('a', { sourceId: 'desktop' })),
'a build that manages its own paths'
).toBe(false)
expect(hasOutputFolder(install('a', { sourceId: 'gone' })), 'an unknown source').toBe(false)
})
})

describe('listOutputFolders', () => {
it('lists each real output folder once, leaving out Cloud and builds that manage their own paths', async () => {
expect(await listOutputFolders()).toEqual([
Expand All @@ -182,22 +196,18 @@ describe('listOutputFolders', () => {
})

describe('listLocalAssets', () => {
it('lists media from every output folder and its subfolders, newest first', async () => {
it("lists the media in the picked build's output folder and its subfolders, newest first", 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, '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(installDir, 'ComfyUI', 'output', 'mesh.glb'),
'x',
new Date('2026-11-02T00:00:00Z')
)
write(path.join(sharedDir, 'notes.txt'))
write(path.join(sharedDir, '.hidden.png'))
write(path.join(sharedDir, '.cache', 'inside-hidden.png'))

const assets = await listLocalAssets()
const assets = await listLocalAssets('Test Instance')

expect(assets.map((a) => a.name)).toEqual(['new.mp4', 'voice.wav', 'mesh.glb', 'old.png'])
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({
id: newVideo,
Expand All @@ -214,10 +224,10 @@ describe('listLocalAssets', () => {
durationSeconds: null
})
const oldPicture = path.join(sharedDir, 'old.png')
expect(assets[3]!.thumbnailUrl, 'an image thumbnail link changes when the file does').toBe(
expect(assets[2]!.thumbnailUrl, 'an image thumbnail link changes when the file does').toBe(
outputFileUrl(oldPicture, fs.statSync(oldPicture).mtimeMs)
)
expect(assets[2]!.previewUrl, '3D files have no preview').toBeNull()
expect(assets[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 () => {
Expand All @@ -226,7 +236,7 @@ describe('listLocalAssets', () => {
write(path.join(sharedDir, 'broken.png'), 'not a picture')

const facts = Object.fromEntries(
(await listLocalAssets()).map((a) => [
(await listLocalAssets('Test Instance')).map((a) => [
a.name,
[a.width, a.height, a.durationSeconds && Math.round(a.durationSeconds)]
])
Expand All @@ -239,17 +249,48 @@ describe('listLocalAssets', () => {
})
})

it('finds a file once when two builds save to the same folder', async () => {
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)

expect((await listLocalAssets()).map((a) => a.name)).toEqual(['shared.png'])
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([])
expect(
(await listLocalAssets()).map((a) => a.name),
'no build: the shared output folder'
).toEqual(['shared.png'])
})

it('opens a file it listed for a build added a moment ago', async () => {
await listOutputFolders()
const newDir = path.join(root, 'new-output')
const file = path.join(newDir, 'first.png')
write(file)
installs.mockResolvedValue([install('New', { useSharedOutput: false, outputDir: newDir })])
try {
const [listed] = await listLocalAssets('New')

expect(listed!.id).toBe(file)
expect(await outputFilePath(listed!.id)).toBe(file)
} finally {
fs.rmSync(newDir, { recursive: true, force: true })
}
})

it('keeps only the newest files when the folders are 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)))

const assets = await listLocalAssets()
const assets = await listLocalAssets('Test Instance')

expect(assets).toHaveLength(MAX_LOCAL_ASSETS)
expect(assets.map((a) => a.name)).not.toContain('f0.png')
Expand All @@ -264,7 +305,7 @@ describe('listLocalAssets', () => {
)
write(path.join(deep, 'too-deep.png'))

expect(await listLocalAssets()).toEqual([])
expect(await listLocalAssets('Test Instance')).toEqual([])
})
})

Expand Down
49 changes: 33 additions & 16 deletions src/main/lib/outputFolders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,13 @@ export function outputDirOverride(inst: InstallationRecord, sharedDir: string):
return (inst.outputDir as string | undefined) || null
}

function outputDirFor(inst: InstallationRecord, sharedDir: string): string | null {
export function hasOutputFolder(inst: InstallationRecord): boolean {
const source = sourceMap[inst.sourceId]
if (source?.category !== 'local' || source.getLaunchCommand(inst)?.skipSharedPaths) return null
return source?.category === 'local' && !source.managesOwnPaths
}

function outputDirFor(inst: InstallationRecord, sharedDir: string): string | null {
if (!hasOutputFolder(inst)) return null
return outputDirOverride(inst, sharedDir) ?? installOutputDir(inst.installPath)
}

Expand All @@ -57,19 +61,29 @@ async function realDir(dir: string): Promise<string | null> {
return stat?.isDirectory() ? real : null
}

export async function listOutputFolders(): Promise<string[]> {
const shared = sharedOutputDir()
const folders = new Set<string>()
const sharedReal = await realDir(shared)
if (sharedReal) folders.add(sharedReal)
interface OutputFolders {
all: string[]
shared: string | null
ofBuild: Map<string, string>
}

async function findOutputFolders(): Promise<OutputFolders> {
const sharedDir = sharedOutputDir()
const shared = await realDir(sharedDir)
const ofBuild = new Map<string, string>()
for (const inst of await installations.list()) {
const dir = outputDirFor(inst, shared)
const dir = outputDirFor(inst, sharedDir)
const real = dir ? await realDir(dir) : null
if (real) folders.add(real)
if (real) ofBuild.set(inst.id, real)
}
allowedRoots = [...folders]
const all = [...new Set([...(shared ? [shared] : []), ...ofBuild.values()])]
allowedRoots = all
allowedRootsAt = Date.now()
return allowedRoots
return { all, shared, ofBuild }
}

export async function listOutputFolders(): Promise<string[]> {
return (await findOutputFolders()).all
}

function isInsideRoot(target: string, root: string): boolean {
Expand All @@ -79,7 +93,7 @@ function isInsideRoot(target: string, root: string): boolean {

async function allowedPath(target: string): Promise<string | null> {
if (!path.isAbsolute(target)) return null
if (Date.now() - allowedRootsAt > ROOTS_FRESH_MS) await listOutputFolders()
if (Date.now() - allowedRootsAt > ROOTS_FRESH_MS) await findOutputFolders()
const real = await fsp.realpath(target).catch(() => null)
if (!real) return null
return allowedRoots.some((root) => isInsideRoot(real, root)) ? real : null
Expand Down Expand Up @@ -161,9 +175,10 @@ async function addMediaFacts(asset: AssetSummary): Promise<void> {
Object.assign(asset, await mediaFactsFromFile(asset.id, asset.kind))
}

export async function listLocalAssets(): Promise<AssetSummary[]> {
const folders = await listOutputFolders()
const files = [...new Set((await Promise.all(folders.map(collectMediaFiles))).flat())]
export async function listLocalAssets(installationId?: string): Promise<AssetSummary[]> {
const folders = await findOutputFolders()
const folder = installationId === undefined ? folders.shared : folders.ofBuild.get(installationId)
const files = folder ? await collectMediaFiles(folder) : []
const found: AssetSummary[] = []
await runPool(files, STATS_AT_ONCE, async (file) => {
const stat = await fsp.stat(file).catch(() => null)
Expand Down Expand Up @@ -304,5 +319,7 @@ export function registerOutputFilesScheme(): void {

export function registerOutputFolderHandlers(): void {
protocol.handle(OUTPUT_FILES_SCHEME, serveOutputFile)
ipcMain.handle(LIST_LOCAL_CHANNEL, () => listLocalAssets())
ipcMain.handle(LIST_LOCAL_CHANNEL, (_event, installationId: unknown) =>
listLocalAssets(typeof installationId === 'string' ? installationId : undefined)
)
}
Loading
Loading