Skip to content
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

Add mock electron APIs used by the frontend #228

Merged
merged 1 commit into from
Nov 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions src/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -147,6 +161,55 @@ const electronAPI = {
isFirstTimeSetup: (): Promise<boolean> => {
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<MigrationItem[]> =>
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;
Expand Down
Loading