32 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
			
		
		
	
	
			32 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
/* eslint-disable @typescript-eslint/no-explicit-any */
 | 
						|
import { ipcRenderer, contextBridge } from "electron";
 | 
						|
 | 
						|
// --------- Expose some API to the Renderer process ---------
 | 
						|
contextBridge.exposeInMainWorld("ipcRenderer", {
 | 
						|
  on(...args: Parameters<typeof ipcRenderer.on>) {
 | 
						|
    const [channel, listener] = args;
 | 
						|
    return ipcRenderer.on(channel, (event, ...args) =>
 | 
						|
      listener(event, ...args)
 | 
						|
    );
 | 
						|
  },
 | 
						|
  off(...args: Parameters<typeof ipcRenderer.off>) {
 | 
						|
    const [channel, ...omit] = args;
 | 
						|
    return ipcRenderer.off(channel, ...omit);
 | 
						|
  },
 | 
						|
  send(...args: Parameters<typeof ipcRenderer.send>) {
 | 
						|
    const [channel, ...omit] = args;
 | 
						|
    return ipcRenderer.send(channel, ...omit);
 | 
						|
  },
 | 
						|
  invoke(...args: Parameters<typeof ipcRenderer.invoke>) {
 | 
						|
    const [channel, ...omit] = args;
 | 
						|
    return ipcRenderer.invoke(channel, ...omit);
 | 
						|
  },
 | 
						|
 | 
						|
  // Websocket
 | 
						|
  onNewNote: (callback: (data: any) => void) =>
 | 
						|
    ipcRenderer.on("newNote", (_, data) => callback(data)),
 | 
						|
  openDevTools: () => ipcRenderer.send("open-devtools"),
 | 
						|
  // You can expose other APTs you need here.
 | 
						|
  // ...
 | 
						|
});
 |