From 3421a67020d28e3bdc5fd9fd271024e62c323e21 Mon Sep 17 00:00:00 2001 From: huchenlei Date: Tue, 12 Nov 2024 13:51:48 -0500 Subject: [PATCH] Add mock electron APIs used by the frontend --- src/preload.ts | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/src/preload.ts b/src/preload.ts index b1ca8f62..baf9b5cb 100644 --- a/src/preload.ts +++ b/src/preload.ts @@ -12,6 +12,20 @@ const openFolder = async (folderPath: string) => { ipcRenderer.send(IPC_CHANNELS.OPEN_PATH, path.join(basePath, folderPath)); }; +export interface MigrationItem { + id: string; + label: string; + description: string; +} + +export interface InstallOptions { + installPath: string; + autoUpdate: boolean; + allowMetrics: boolean; + migrationSourcePath?: string; + migrationItemIds?: string[]; +} + const electronAPI = { /** * Callback for progress updates from the main process for starting ComfyUI. @@ -147,6 +161,55 @@ const electronAPI = { isFirstTimeSetup: (): Promise => { return ipcRenderer.invoke(IPC_CHANNELS.IS_FIRST_TIME_SETUP); }, + // TODO(robinjhuang): Implement these methods. + // Currently, they are mocked. + /** + * Get the system paths for the application. + */ + getSystemPaths: () => + Promise.resolve({ + appData: 'C:/Users/username/AppData/Roaming', + appPath: 'C:/Program Files/comfyui-electron/resources/app', + defaultInstallPath: 'C:/Users/username/comfyui-electron', + }), + /** + * Validate the install path for the application. Check whether the path is valid + * and writable. The disk should have enough free space to install the application. + */ + validateInstallPath: (path: string) => { + if (path === 'bad') { + return { isValid: false, error: 'Bad path!' }; + } + return { isValid: true }; + }, + /** + * Get the migration items for the application. + */ + migrationItems: (): Promise => + Promise.resolve([ + { + id: 'user_files', + label: 'User Files', + description: 'Settings and user-created workflows', + }, + ]), + /** + * Validate whether the given path is a valid ComfyUI source path. + */ + validateComfyUISource: (path: string) => { + if (path === 'bad') { + return { isValid: false, error: 'Bad path!' }; + } + return { isValid: true }; + }, + /** + * Show a directory picker dialog and return the selected path. + */ + showDirectoryPicker: () => Promise.resolve('C:/Users/username/comfyui-electron/1'), + /** + * Install ComfyUI with given options. + */ + installComfyUI: (installOptions: InstallOptions) => Promise.resolve(), } as const; export type ElectronAPI = typeof electronAPI;