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 electron API to open external URLs. #153

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const IPC_CHANNELS = {
CANCEL_DOWNLOAD: 'cancel-download',
DELETE_MODEL: 'delete-model',
GET_ALL_DOWNLOADS: 'get-all-downloads',
OPEN_EXTERNAL: 'open-external',
} as const;

export const COMFY_ERROR_MESSAGE =
Expand Down
6 changes: 6 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -951,3 +951,9 @@ const rotateLogFiles = (logDir: string, baseName: string) => {
fs.renameSync(currentLogPath, newLogPath);
}
};

// TODO(robinhuang): Pop up a warning and ask user to optionally whitelist URLs.
ipcMain.handle(IPC_CHANNELS.OPEN_EXTERNAL, async (_event, url: string) => {
log.info(`Opening external URL: ${url}`);
await shell.openExternal(url);
});
4 changes: 4 additions & 0 deletions src/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export interface ElectronAPI {
deleteModel: (filename: string, path: string) => Promise<boolean>;
getAllDownloads: () => Promise<DownloadItem[]>;
};
openExternal: (url: string) => Promise<void>;
}

const electronAPI: ElectronAPI = {
Expand Down Expand Up @@ -138,6 +139,9 @@ const electronAPI: ElectronAPI = {
return ipcRenderer.invoke(IPC_CHANNELS.GET_ALL_DOWNLOADS);
},
},
openExternal: (url: string) => {
return ipcRenderer.invoke(IPC_CHANNELS.OPEN_EXTERNAL, url);
},
};

contextBridge.exposeInMainWorld(ELECTRON_BRIDGE_API, electronAPI);
Loading