Repository navigation
feat(apps): show an app page's outputs in Desktop's output dialog - #2156
PabloWiedemann wants to merge 7 commits into
Conversation
An app page can now ask Desktop to show its outputs through a new bridge,
window.comfyDesktopOutputs. showOutput({ items, index }) takes each
output's name, media type, bytes, tags and whether it has a saved
workflow, the same payload the Apps pages send today. Desktop opens the
output dialog that Assets uses over the Apps view, with the outputs and
the one to show first.
Main checks the request the way it checks other page calls: only from
the hosted Apps page, while Apps is on, and only for the page document
that is still loaded. It takes at most 40 outputs and 100 MB in all, and
only image, video and audio types the dialog can show. A request it
cannot show is rejected; it resolves false while the app is not on
screen.
Download, and Open workflow for an output with a saved workflow, go back
to the page on onOutputAction, so the page uses its own download link
and its own Open in ComfyUI. Main sends an action only to the page
document that showed the outputs, and only for an index it sent.
The dialog covers the app page, so the page host swaps the app for its
still frame as it does for any cover. When the dialog closes, the app
gets the keyboard back. The panel CSP allows blob: for the output
previews.
This is the Apps half of #2008, rebuilt on main's Apps page. The Assets
half landed in #2140.
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the
|
…ers' into PabloWiedemann/apps-output-dialog
Register the panel's output action listener next to the show handler, so registerAppsHandlers stays as it is on main.
…ers' into PabloWiedemann/apps-output-dialog
There was a problem hiding this comment.
🔍 Cursor Review — Consolidated panel
Triggered by @PabloWiedemann.
Found 10 finding(s).
| Severity | Count |
|---|---|
| 🟠 High | 1 |
| 🟡 Medium | 6 |
| 🟢 Low | 3 |
Panel: 8/8 reviewers contributed findings.
| function hasHiddenCharacters(value: string): boolean { | ||
| return ( | ||
| BIDI_CONTROL.test(value) || | ||
| Array.from(value).some((char) => { |
There was a problem hiding this comment.
🟠 High — hasHiddenCharacters runs Array.from(value) on the untruncated string, and trimmed only slices to MAX_NAME_LENGTH/MAX_TAG_LENGTH afterwards. Since name and tags are unbounded and are not counted toward MAX_OUTPUTS_BYTES (which sums only bytes buffers), one request with multi-megabyte names/tags materializes hundreds of millions of per-character strings in the main process, blocking the event loop or OOM-killing the app. Reject strings longer than the max (or slice first) before scanning characters. Raised by 4 of 8 reviewers (claude-opus-5-thinking-max adversarial, gemini-3.1-pro adversarial, gpt-5.6-sol-max adversarial, gpt-5.6-sol-max edge-case).
There was a problem hiding this comment.
Fixed in 9881948: names and tags are cut to their limit before the character check, so a very long string is scanned only up to 200 or 40 characters. A test sends a 5 MB name.
| const outputs = Array.from(items, readOutput) | ||
| if (outputs.some((output) => output === null)) return null | ||
| const shown = outputs as AppOutput[] | ||
| const sentBytes = shown.reduce((sum, output) => sum + output.bytes.buffer.byteLength, 0) |
There was a problem hiding this comment.
🟡 Medium — sentBytes sums output.bytes.buffer.byteLength, which double-counts when several outputs are views into one ArrayBuffer — structured clone preserves that sharing and transfers the buffer once. Two 30 MB views of a single 60 MB buffer, or 40 small views of one large buffer, are rejected with a thrown error even though the real payload is well inside the limit; sum byteLength per view, or dedupe buffers by identity. Raised by 2 of 8 reviewers (claude-opus-5-thinking-max edge-case, gemini-3.1-pro edge-case).
There was a problem hiding this comment.
Not changing: counting the whole buffer is deliberate, so a small view cannot carry a large buffer past the limit; a page sends one buffer per output.
| if (sentFrom === null || !(await isFromAppsPage(event))) return false | ||
| const outputs = readOutputRequest(request) | ||
| if (!outputs) throw new Error('Desktop cannot show these outputs.') | ||
| return showAppOutputs(event.sender, sentFrom, outputs) |
There was a problem hiding this comment.
🟡 Medium — showOutputFromAppsPage accepts up to 100 MB per request with no per-page, per-window, or global rate limit, and the payload is fully deserialized into main-process memory before validation, then copied again to the panel renderer and a third time into Blobs. A hosted page can loop showOutput to exhaust memory; the sibling hosted-page channel already enforces PAGE_EVENTS_PER_MINUTE/PAGE_EVENTS_PER_SESSION in appPageEvents.ts. Raised by 3 of 8 reviewers (kimi-k2.7-code adversarial, claude-opus-5-thinking-max adversarial, gpt-5.6-sol-max adversarial).
There was a problem hiding this comment.
Not changing: each request replaces the previous one in the dialog and is capped at 100 MB, and the sender is the hosted Apps page, not arbitrary content.
| const panel = panelOf(windowKey) | ||
| if (!panel || !isOnScreen(hosted) || !isStillLoaded(hosted, sentFrom)) return false | ||
| hosted.outputs = { page: sentFrom, count: outputs.items.length } | ||
| if (comfyWindows.get(windowKey)?.window.isFocused()) panel.focus() |
There was a problem hiding this comment.
🟡 Medium — comfyWindows.get(windowKey)?.window.isFocused() has no isDestroyed() guard, unlike hostOf which checks !entry.window.isDestroyed() before touching entry.window. If the window is torn down between the panelOf check and this call, isFocused() throws Object has been destroyed, which escapes showAppOutputs and rejects the page's showOutput invoke instead of resolving false as the bridge contract documents. Raised by 1 of 8 reviewers (claude-opus-5-thinking-max edge-case).
There was a problem hiding this comment.
Not changing: panelOf already returns null for a destroyed panel, and the window cannot be destroyed between these two synchronous calls.
| const host = hostOf(panel) | ||
| const hosted = host && hostedFor(host) | ||
| const shown = hosted?.outputs | ||
| if (!hosted || !shown || action.index >= shown.count || !isStillLoaded(hosted, shown.page)) return |
There was a problem hiding this comment.
🟡 Medium — sendAppOutputAction checks isStillLoaded but not isOnScreen(hosted), while showAppOutputs requires both, and hosted.outputs is never cleared once set. After closeForList conceals the page with pageStillShowsApp true, hosted.loaded survives, so an action can still be delivered to a page the user can no longer see. Raised by 3 of 8 reviewers (claude-opus-5-thinking-max edge-case, kimi-k2.7-code edge-case, claude-opus-5-thinking-max adversarial).
There was a problem hiding this comment.
Not changing: while the dialog is open the app page is hidden behind a still frame, so requiring it to be on screen would drop every action. isStillLoaded keeps actions to the page that sent the outputs, and closing the app removes the dialog.
| if (hosted.view.webContents !== contents) continue | ||
| const panel = panelOf(windowKey) | ||
| if (!panel || !isOnScreen(hosted) || !isStillLoaded(hosted, sentFrom)) return false | ||
| hosted.outputs = { page: sentFrom, count: outputs.items.length } |
There was a problem hiding this comment.
🟡 Medium — ShownOutputs records only page and count, with no generation identifier, and is overwritten by each showOutput. If a page replaces its outputs while the dialog still displays the previous set, a click validates against the new count and the forwarded {action, index} resolves on the page against the newer set, so Download or Open workflow acts on an output the user never saw. Stamp each request with an incrementing id and include it in the action. Raised by 2 of 8 reviewers (claude-opus-5-thinking-max adversarial, gpt-5.6-sol-max adversarial).
There was a problem hiding this comment.
Not changing: a new request replaces the dialog's items as soon as it arrives, so the panel and the page use the same set; only a click in the same instant could race.
|
|
||
| function hasHiddenCharacters(value: string): boolean { | ||
| return ( | ||
| BIDI_CONTROL.test(value) || |
There was a problem hiding this comment.
🟡 Medium — The hidden-character screen only catches C0 controls, DEL, and U+202A–U+202E/U+2066–U+2069. It lets through bidi marks U+200E/U+200F/U+061C, zero-width characters U+200B–U+200D and U+FEFF, U+2028/U+2029, and the C1 block U+0080–U+009F, so a page can still send a visually deceptive name that renders in Desktop's own h2 and aria-label — which the published bridge contract promises is refused. Raised by 4 of 8 reviewers (claude-opus-5-thinking-max edge-case, claude-opus-5-thinking-max adversarial, gpt-5.6-sol-max adversarial, gpt-5.6-sol-max edge-case).
There was a problem hiding this comment.
Fixed in 9881948: the check now also refuses C1 controls, bidi marks (U+200E, U+200F, U+061C), zero-width characters, U+2028/U+2029 and U+FEFF, with tests.
| } | ||
| justOpened = false | ||
| retrying = false | ||
| focusPage = false |
There was a problem hiding this comment.
🟢 Low — focusPage is only cleared after takePlacement passes its rect.width === 0 || rect.height === 0 early return. If the host measures zero when the output dialog closes, the flag stays set and the next unrelated placement — a plain resize, say — carries focus: true and pulls the keyboard into the app page while the user is working in the panel. Raised by 1 of 8 reviewers (claude-opus-5-thinking-max edge-case).
There was a problem hiding this comment.
Not changing: the host has its size whenever the dialog closes over it; it is zero only while the app is hidden, and the next placement is then the one that shows the app.
|
|
||
| function trimmed(value: unknown, max: number): string | null { | ||
| if (typeof value !== 'string' || value.trim() === '' || hasHiddenCharacters(value)) return null | ||
| return value.trim().slice(0, max) |
There was a problem hiding this comment.
🟢 Low — value.trim().slice(0, max) cuts by UTF-16 code unit, so a name or tag whose 200th (or 40th) unit falls inside a surrogate pair is truncated to a lone surrogate and renders as a replacement character in the dialog even though the input was well-formed. Slice by code points instead. Raised by 3 of 8 reviewers (claude-opus-5-thinking-max edge-case, gemini-3.1-pro edge-case, gpt-5.6-sol-max edge-case).
There was a problem hiding this comment.
Not changing: a lone surrogate only appears when a 200-character name or a 40-character tag is cut inside an emoji, which is cosmetic.
| function readTags(value: unknown): string[] { | ||
| if (!Array.isArray(value)) return [] | ||
| return value | ||
| .slice(0, MAX_TAGS) |
There was a problem hiding this comment.
🟢 Low — readTags slices to MAX_TAGS before mapping and filtering, so invalid tags early in the array consume the quota and valid tags later in the list are dropped. Filter first and take the first 8 valid tags to match the documented "keeps the first 8 tags" behaviour. Raised by 1 of 8 reviewers (gemini-3.1-pro edge-case).
There was a problem hiding this comment.
Not changing: taking the first 8 entries before checking them keeps the work bounded for a very long tag list.
…ers' into PabloWiedemann/apps-output-dialog
…e invisible characters
TL;DR: An app page can show its outputs in the same Desktop output dialog that Assets uses, through a new bridge,
window.comfyDesktopOutputs.Why: every app had its own output card. One dialog that Desktop owns makes outputs look and work the same in Apps and Assets.
Can affect: the app page bridge (
src/types/comfyDesktopBridge.ts),AppPageHost.vue, the output dialog, and the panel CSP (blob:inimg-srcandmedia-src).Stacked on #2155. Replaces the Apps half of #2008; the Assets half landed in #2140.
Changes
showOutput({ items, index })with each output's name, media type, bytes, tags and whether it has a saved workflow.onOutputActionsends Download and Open workflow back to the page.registerAppsOutputsHandlers.ts.Website
The pages read
window.comfyDesktopAppstoday. They need one line to preferwindow.comfyDesktopOutputs. That change is in Comfy-Org/comfy-website#456.Size
About 360 non-test lines added.
Checks