Intial Version
This commit is contained in:
34
electron-app/src/preload.ts
Normal file
34
electron-app/src/preload.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { contextBridge, ipcRenderer } from 'electron';
|
||||
|
||||
// Expose protected methods that allow the renderer process to use
|
||||
// the ipcRenderer without exposing the entire object
|
||||
contextBridge.exposeInMainWorld('electron', {
|
||||
ipcRenderer: {
|
||||
invoke: (channel: string, ...args: any[]) => ipcRenderer.invoke(channel, ...args),
|
||||
on: (channel: string, func: (...args: any[]) => void) => {
|
||||
ipcRenderer.on(channel, (_event: any, ...args: any[]) => func(...args));
|
||||
},
|
||||
once: (channel: string, func: (...args: any[]) => void) => {
|
||||
ipcRenderer.once(channel, (_event: any, ...args: any[]) => func(...args));
|
||||
},
|
||||
removeAllListeners: (channel: string) => {
|
||||
ipcRenderer.removeAllListeners(channel);
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
// Type definitions for TypeScript
|
||||
export interface IElectronAPI {
|
||||
ipcRenderer: {
|
||||
invoke: (channel: string, ...args: any[]) => Promise<any>;
|
||||
on: (channel: string, func: (...args: any[]) => void) => void;
|
||||
once: (channel: string, func: (...args: any[]) => void) => void;
|
||||
removeAllListeners: (channel: string) => void;
|
||||
};
|
||||
}
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
electron: IElectronAPI;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user