mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-19 06:20:10 +00:00
## Summary Extracts desktop UI into apps/desktop-ui package with minimal changes. ## Changes - **What**: - Separates desktop-specific code into standalone package with independent Vite config, router, and i18n - Drastically simplifies the main app router by removing all desktop routes - Adds a some code duplication, most due to the existing design - Some duplication can be refactored to be *simpler* on either side - no need to split things by `isElectron()` - Rudimentary storybook support has been added - **Breaking**: Stacked PR for publishing must be merged before this PR makes it to stable core (but publishing _could_ be done manually) - #5915 - **Dependencies**: Takes full advantage of pnpm catalog. No additional dependencies added. ## Review Focus - Should be no changes to normal frontend operation - Scripts added to root package.json are acceptable - The duplication in this PR is copied as is, wherever possible. Any corrections or fix-ups beyond the scope of simply migrating the functionality as-is, can be addressed in later PRs. That said, if any changes are made, it instantly becomes more difficult to separate the duplicated code out into a shared utility. - Tracking issue to address concerns: #5925 ### i18n Fixing i18n is out of scope for this PR. It is a larger task that we should consider carefully and implement properly. Attempting to isolate the desktop i18n and duplicate the _current_ localisation scripts would be wasted energy.
76 lines
2.1 KiB
TypeScript
76 lines
2.1 KiB
TypeScript
export interface DialogAction {
|
|
readonly label: string
|
|
readonly action: 'openUrl' | 'close' | 'cancel'
|
|
readonly url?: string
|
|
readonly severity?: 'danger' | 'primary' | 'secondary' | 'warn'
|
|
readonly returnValue: string
|
|
}
|
|
|
|
interface DesktopDialog {
|
|
readonly title: string
|
|
readonly message: string
|
|
readonly buttons: DialogAction[]
|
|
}
|
|
|
|
export const DESKTOP_DIALOGS = {
|
|
/** Shown when a corrupt venv is detected. */
|
|
reinstallVenv: {
|
|
title: 'Reinstall ComfyUI (Fresh Start)?',
|
|
message: `Sorry, we can't launch ComfyUI because some installed packages aren't compatible.
|
|
|
|
Click Reinstall to restore ComfyUI and get back up and running.
|
|
|
|
Please note: if you've added custom nodes, you'll need to reinstall them after this process.`,
|
|
buttons: [
|
|
{
|
|
label: 'Learn More',
|
|
action: 'openUrl',
|
|
url: 'https://docs.comfy.org',
|
|
returnValue: 'openDocs'
|
|
},
|
|
{
|
|
label: 'Reinstall',
|
|
action: 'close',
|
|
severity: 'danger',
|
|
returnValue: 'resetVenv'
|
|
}
|
|
]
|
|
},
|
|
/** A dialog that is shown when an invalid dialog ID is provided. */
|
|
invalidDialog: {
|
|
title: 'Invalid Dialog',
|
|
message: `Invalid dialog ID was provided.`,
|
|
buttons: [
|
|
{
|
|
label: 'Close',
|
|
action: 'cancel',
|
|
returnValue: 'cancel'
|
|
}
|
|
]
|
|
}
|
|
} as const satisfies { [K: string]: DesktopDialog }
|
|
|
|
/** The ID of a desktop dialog. */
|
|
type DesktopDialogId = keyof typeof DESKTOP_DIALOGS
|
|
|
|
/**
|
|
* Checks if {@link id} is a valid dialog ID.
|
|
* @param id The string to check
|
|
* @returns `true` if the ID is a valid dialog ID, otherwise `false`
|
|
*/
|
|
function isDialogId(id: unknown): id is DesktopDialogId {
|
|
return typeof id === 'string' && id in DESKTOP_DIALOGS
|
|
}
|
|
|
|
/**
|
|
* Gets the dialog with the given ID.
|
|
* @param dialogId The ID of the dialog to get
|
|
* @returns The dialog with the given ID
|
|
*/
|
|
export function getDialog(
|
|
dialogId: string | string[]
|
|
): DesktopDialog & { id: DesktopDialogId } {
|
|
const id = isDialogId(dialogId) ? dialogId : 'invalidDialog'
|
|
return { id, ...structuredClone(DESKTOP_DIALOGS[id]) }
|
|
}
|