|
| 1 | +export interface DialogAction { |
| 2 | + readonly label: string |
| 3 | + readonly action: 'openUrl' | 'close' | 'cancel' |
| 4 | + readonly url?: string |
| 5 | + readonly severity?: 'danger' | 'primary' | 'secondary' | 'warn' |
| 6 | + readonly returnValue: string |
| 7 | +} |
| 8 | + |
| 9 | +interface DesktopDialog { |
| 10 | + readonly title: string |
| 11 | + readonly message: string |
| 12 | + readonly buttons: DialogAction[] |
| 13 | +} |
| 14 | + |
| 15 | +export const DESKTOP_DIALOGS = { |
| 16 | + /** Shown when a corrupt venv is detected. */ |
| 17 | + reinstallVenv: { |
| 18 | + title: 'Reinstall ComfyUI (Fresh Start)?', |
| 19 | + message: `Sorry, we can't launch ComfyUI because some installed packages aren't compatible. |
| 20 | +
|
| 21 | +Click Reinstall to restore ComfyUI and get back up and running. |
| 22 | +
|
| 23 | +Please note: if you've added custom nodes, you'll need to reinstall them after this process.`, |
| 24 | + buttons: [ |
| 25 | + { |
| 26 | + label: 'Learn More', |
| 27 | + action: 'openUrl', |
| 28 | + url: 'https://docs.comfy.org', |
| 29 | + returnValue: 'openDocs' |
| 30 | + }, |
| 31 | + { |
| 32 | + label: 'Reinstall', |
| 33 | + action: 'close', |
| 34 | + severity: 'danger', |
| 35 | + returnValue: 'resetVenv' |
| 36 | + } |
| 37 | + ] |
| 38 | + }, |
| 39 | + /** A dialog that is shown when an invalid dialog ID is provided. */ |
| 40 | + invalidDialog: { |
| 41 | + title: 'Invalid Dialog', |
| 42 | + message: `Invalid dialog ID was provided.`, |
| 43 | + buttons: [ |
| 44 | + { |
| 45 | + label: 'Close', |
| 46 | + action: 'cancel', |
| 47 | + returnValue: 'cancel' |
| 48 | + } |
| 49 | + ] |
| 50 | + } |
| 51 | +} as const satisfies { [K: string]: DesktopDialog } |
| 52 | + |
| 53 | +/** The ID of a desktop dialog. */ |
| 54 | +type DesktopDialogId = keyof typeof DESKTOP_DIALOGS |
| 55 | + |
| 56 | +/** |
| 57 | + * Checks if {@link id} is a valid dialog ID. |
| 58 | + * @param id The string to check |
| 59 | + * @returns `true` if the ID is a valid dialog ID, otherwise `false` |
| 60 | + */ |
| 61 | +function isDialogId(id: unknown): id is DesktopDialogId { |
| 62 | + return typeof id === 'string' && id in DESKTOP_DIALOGS |
| 63 | +} |
| 64 | + |
| 65 | +/** |
| 66 | + * Gets the dialog with the given ID. |
| 67 | + * @param dialogId The ID of the dialog to get |
| 68 | + * @returns The dialog with the given ID |
| 69 | + */ |
| 70 | +export function getDialog( |
| 71 | + dialogId: string | string[] |
| 72 | +): DesktopDialog & { id: DesktopDialogId } { |
| 73 | + const id = isDialogId(dialogId) ? dialogId : 'invalidDialog' |
| 74 | + return { id, ...structuredClone(DESKTOP_DIALOGS[id]) } |
| 75 | +} |
0 commit comments