36 lines
1.4 KiB
TypeScript
36 lines
1.4 KiB
TypeScript
import { contextBridge, ipcRenderer } from "electron";
|
|
console.log("setting PreLoad")
|
|
|
|
|
|
contextBridge.exposeInMainWorld('electron', {
|
|
login: (credentials: { email: string, password: string }) => ipcRenderer.invoke('login-request', credentials),
|
|
logout: () => ipcRenderer.invoke('logout-request'),
|
|
getToken: (TOKEN_KEY: "ACCESS_TOKEN" | "REFRESH_TOKEN") => ipcRenderer.invoke('get-token', TOKEN_KEY),
|
|
uploadScreenshot: () => ipcRenderer.invoke('upload-screenshot'),
|
|
getActiveAppDetails: () => ipcRenderer.invoke('get-active-app'),
|
|
toggleCloseBtn: (shouldEnable: boolean) => ipcRenderer.invoke('toggle-close-btn', shouldEnable),
|
|
resizeWindow: (width: number, height: number) => ipcRenderer.invoke('resize-window', width, height),
|
|
} satisfies Window['electron']);
|
|
|
|
// function ipcInvoke<Key extends keyof EventPayloadMapping>(
|
|
// key: Key
|
|
// ): Promise<EventPayloadMapping[Key]> {
|
|
// return ipcRenderer.invoke(key);
|
|
// }
|
|
|
|
// function ipcOn<Key extends keyof EventPayloadMapping>(
|
|
// key: Key,
|
|
// callback: (payload: EventPayloadMapping[Key]) => void
|
|
// ) {
|
|
// const cb = (_: Electron.IpcRendererEvent, payload: any) => callback(payload);
|
|
// ipcRenderer.on(key, cb);
|
|
// return () => ipcRenderer.off(key, cb);
|
|
// }
|
|
|
|
// function ipcSend<Key extends keyof EventPayloadMapping>(
|
|
// key: Key,
|
|
// payload: EventPayloadMapping[Key]
|
|
// ) {
|
|
// ipcRenderer.send(key, payload);
|
|
// }
|