Repository navigation
feat(apps): show an app page's outputs in Desktop's output dialog #2156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: PabloWiedemann/assets-local-folders
Are you sure you want to change the base?
Changes from all commits
9166ad4
7065fa3
23debf0
3a18ad5
29a2c4a
36f1683
9881948
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,7 @@ import path from 'path' | |
|
|
||
| import { isAppsListUrl, isInAppsScope, isWebUrl } from '../../shared/appsLocation' | ||
| import type { AppsLocation } from '../../shared/appsLocation' | ||
| import type { AppPagePlacement, AppPageStatus } from '../../types/ipc' | ||
| import type { AppOutputAction, AppOutputs, AppPagePlacement, AppPageStatus } from '../../types/ipc' | ||
| import { comfyWindows } from '../host/registry' | ||
| import type { ComfyWindowEntry } from '../host/registry' | ||
| import { attachSessionDownloadHandler } from '../lib/comfyDownloadManager' | ||
|
|
@@ -20,6 +20,8 @@ import { registerAppsPage } from './appsPages' | |
| export const APPS_PARTITION = 'persist:comfy-apps' | ||
| export const APP_PAGE_STATUS_CHANNEL = 'apps:page-status-changed' | ||
| export const APP_PAGE_CLOSED_CHANNEL = 'apps:page-closed' | ||
| export const APP_OUTPUTS_CHANNEL = 'apps:outputs' | ||
| export const APP_OUTPUT_ACTION_CHANNEL = 'apps-outputs:action' | ||
| export const APP_OPENED_EVENT = 'comfy.desktop.apps.app_opened' | ||
| export const APP_PAGE_FAILED_EVENT = 'comfy.desktop.apps.app_page_failed' | ||
|
|
||
|
|
@@ -34,6 +36,11 @@ export interface LoadedAppPage { | |
| document: number | ||
| } | ||
|
|
||
| interface ShownOutputs { | ||
| page: LoadedAppPage | ||
| count: number | ||
| } | ||
|
|
||
| interface HostedPage { | ||
| view: WebContentsView | ||
| appId: string | null | ||
|
|
@@ -45,6 +52,7 @@ interface HostedPage { | |
| status: AppPageStatus | ||
| wanted: boolean | ||
| focusWhenReady: boolean | ||
| outputs: ShownOutputs | null | ||
| forget: () => void | ||
| } | ||
|
|
||
|
|
@@ -238,6 +246,7 @@ function createHostedPage({ windowKey, entry }: PageHost, location: AppsLocation | |
| status: 'loading', | ||
| wanted: false, | ||
| focusWhenReady: false, | ||
| outputs: null, | ||
| forget: registerAppsPage(contents) | ||
| } | ||
| const steer = (event: Event, url: string, pageStillShowsApp: boolean): void => { | ||
|
|
@@ -312,7 +321,10 @@ function isMeasure(value: unknown): value is number { | |
|
|
||
| function parsePlacement(raw: unknown): AppPagePlacement | null { | ||
| if (!raw || typeof raw !== 'object') return null | ||
| const { x, y, width, height, cornerRadius, justOpened, retry } = raw as Record<string, unknown> | ||
| const { x, y, width, height, cornerRadius, justOpened, retry, focus } = raw as Record< | ||
| string, | ||
| unknown | ||
| > | ||
| if (!isMeasure(x) || !isMeasure(y) || !isMeasure(width) || !isMeasure(height)) return null | ||
| if (!isMeasure(cornerRadius)) return null | ||
| return { | ||
|
|
@@ -322,7 +334,8 @@ function parsePlacement(raw: unknown): AppPagePlacement | null { | |
| height, | ||
| cornerRadius, | ||
| justOpened: justOpened === true, | ||
| retry: retry === true | ||
| retry: retry === true, | ||
| focus: focus === true | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -392,7 +405,7 @@ export async function showAppPage( | |
| } | ||
| if (placement.justOpened) mainTelemetry.capture(APP_OPENED_EVENT, { app_id: appId }) | ||
| hosted.wanted = true | ||
| hosted.focusWhenReady = hosted.focusWhenReady || askedFresh | ||
| hosted.focusWhenReady = hosted.focusWhenReady || askedFresh || placement.focus === true | ||
| place(host.entry, hosted.view, placement) | ||
| raiseAbovePanel(host.entry, hosted.view) | ||
| applyVisibility(hosted) | ||
|
|
@@ -417,6 +430,35 @@ export async function captureAppPage(panel: WebContents): Promise<string | null> | |
| } | ||
| } | ||
|
|
||
| function isStillLoaded(hosted: HostedPage, page: LoadedAppPage): boolean { | ||
| return hosted.loaded?.appId === page.appId && hosted.loaded.document === page.document | ||
| } | ||
|
|
||
| export function showAppOutputs( | ||
| contents: WebContents, | ||
| sentFrom: LoadedAppPage, | ||
| outputs: AppOutputs | ||
| ): boolean { | ||
| for (const [windowKey, hosted] of hostedByWindow) { | ||
| if (hosted.view.webContents !== contents) continue | ||
| const panel = panelOf(windowKey) | ||
| if (!panel || !isOnScreen(hosted) || !isStillLoaded(hosted, sentFrom)) return false | ||
| hosted.outputs = { page: sentFrom, count: outputs.items.length } | ||
| if (comfyWindows.get(windowKey)?.window.isFocused()) panel.focus() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Medium —
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not changing: panelOf already returns null for a destroyed panel, and the window cannot be destroyed between these two synchronous calls. |
||
| panel.send(APP_OUTPUTS_CHANNEL, sentFrom.appId, outputs) | ||
| return true | ||
| } | ||
| return false | ||
| } | ||
|
|
||
| export function sendAppOutputAction(panel: WebContents, action: AppOutputAction): void { | ||
| 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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Medium —
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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. |
||
| hosted.view.webContents.send(APP_OUTPUT_ACTION_CHANNEL, action) | ||
| } | ||
|
|
||
| export function _resetForTest(): void { | ||
| hostedByWindow.clear() | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 Medium —
ShownOutputsrecords onlypageandcount, with no generation identifier, and is overwritten by eachshowOutput. If a page replaces its outputs while the dialog still displays the previous set, a click validates against the newcountand 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.