Comfy-Org / Comfy-Org/Comfy-Desktop

Runtime detection of launcher IPC bridge in ComfyUI frontend

Open
#423 0 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
TypeScript
Stars
458
Forks
59
Avg merge
22h 18m
Merged PRs (30d)
45

Description

## Summary

Expose launcher management features to the ComfyUI frontend via runtime detection of the existing `window.__comfyDesktop2` IPC bridge, avoiding the need for special frontend builds or compile-time distribution flags.

## Background

The legacy desktop app (`desktop/`) uses a compile-time `__DISTRIBUTION__ = 'desktop'` flag to gate all Electron features behind `isDesktop`. The frontend accesses native APIs through `window.electronAPI`, exposed by the desktop's `preload.ts` via `contextBridge`.

The launcher already exposes a `window.__comfyDesktop2` bridge in `src/preload/comfyPreload.ts` with download-related APIs, but the ComfyUI frontend does not consume it yet.

## Approach

### Phase 1: Expand the launcher bridge
- Add new IPC methods to `comfyPreload.ts`'s `__comfyDesktop2` object (e.g. snapshots, instance management, system info)
- Register corresponding `ipcMain.handle` handlers in the main process
- Define a shared TypeScript interface for the bridge contract

### Phase 2: Frontend runtime detection
- Add runtime detection of `window.__comfyDesktop2` in the ComfyUI frontend (no compile-time flag needed)
- Create a composable (e.g. `useLauncherAPI()`) that checks for the bridge's presence
- Gate launcher-specific UI features behind feature flags that check for the bridge
- Register launcher-specific commands/settings similar to `electronAdapter.ts`, but gated on `!!window.__comfyDesktop2` instead of `isDesktop`

## Benefits

- **Single frontend build** works for localhost, legacy desktop, and launcher — features light up when the bridge is present
- **Incremental development** — bridge surface grows and is testable at each step
- **No special builds** — runtime detection + feature flags replace compile-time distribution constants

## Related Files

- Launcher bridge: `src/preload/comfyPreload.ts`
- Launcher IPC handlers: `src/main/lib/ipc/`
- Frontend desktop adapter (reference pattern): `ComfyUI_frontend/src/extensions/core/electronAdapter.ts`
- Frontend env util: `ComfyUI_frontend/src/utils/envUtil.ts`
- Frontend distribution types: `ComfyUI_frontend/src/platform/distribution/types.ts`

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.