0.1.3 • Published 6 months ago

@ipsme/reflector-electron-ipc-main v0.1.3

Weekly downloads
-
License
ISC
Repository
github
Last release
6 months ago

main.js|electron.js

//------------------------------------------------------------------------------------------------- // reflector nsdnc <-> ipc

const Reflector_IPC_main = require('@ipsme/reflector-electron-ipc-main'); const { ipcMain } = require('electron');

const reflectorIPC_main= new ReflectorIPC_main(ipcMain); reflector_IPC_main.subscribe();

//-------------------------------------------------------------------------------------------------

function createWindow() { // Create the browser window. const win = new BrowserWindow({ // ... webPreferences: { // nodeIntegration: true, preload: __dirname + '/preload.js' }, });

// ...

reflector_IPC_main_.add_window(win);

win.on('closed', () => {
	reflector_IPC_main_.remove_window(win);
	// ...
});

}

//------------------------------------------------------------------------------------------------- // preload.js

// https://github.com/electron/electron/issues/9920#issuecomment-947170941

const { contextBridge, ipcRenderer } = require("electron");

// As an example, here we use the exposeInMainWorld API to expose the IPC renderer // to the main window. They'll be accessible at "window.ipc_reflector". process.once("loaded", () => { contextBridge.exposeInMainWorld('ipc_reflector', { // https://github.com/electron/electron/issues/21437#issuecomment-573522360 send: (msg) => ipcRenderer.send('ipc-reflector-to-main', msg), recv: (fn) => { // Deliberately strip event as it includes sender ipcRenderer.on('ipc-reflector-to-window', (event, ...args) => fn(...args)); } } ); });

// --OR // preload.ts

// https://github.com/electron/electron/issues/9920#issuecomment-947170941

import { IpcRendererEvent } from "electron";

const { contextBridge, ipcRenderer } = require("electron");

// As an example, here we use the exposeInMainWorld API to expose the IPC renderer // to the main window. They'll be accessible at "window.ipc_reflector". process.once("loaded", () => { contextBridge.exposeInMainWorld('ipc_reflector', { // https://github.com/electron/electron/issues/21437#issuecomment-573522360 send: (msg : any) => ipcRenderer.send('ipc-reflector-to-main', msg), recv: (fn : (...args : any[]) => void ) => { // Deliberately strip event as it includes sender ipcRenderer.on('ipc-reflector-to-window', (_event : IpcRendererEvent, ...args: any[]) => fn(...args)); } } ); });

0.1.1

6 months ago

0.1.3

6 months ago

0.0.21

12 months ago

0.0.10

2 years ago

0.0.11

2 years ago

0.0.12

2 years ago

0.0.13

2 years ago

0.0.14

1 year ago

0.0.17

1 year ago

0.0.3

2 years ago

0.0.9

2 years ago

0.0.6

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago