mirror of
https://github.com/ElectronNET/Electron.NET.git
synced 2026-02-14 13:44:47 +00:00
27 lines
842 B
TypeScript
27 lines
842 B
TypeScript
import { ipcMain, BrowserWindow } from 'electron';
|
|
|
|
module.exports = (socket: SocketIO.Server) => {
|
|
socket.on('registerIpcMainChannel', (channel) => {
|
|
ipcMain.on(channel, (event, args) => {
|
|
socket.emit(channel, [event.preventDefault(), args]);
|
|
});
|
|
});
|
|
|
|
socket.on('registerOnceIpcMainChannel', (channel) => {
|
|
ipcMain.once(channel, (event, args) => {
|
|
socket.emit(channel, [event.preventDefault(), args]);
|
|
});
|
|
});
|
|
|
|
socket.on('removeAllListenersIpcMainChannel', (channel) => {
|
|
ipcMain.removeAllListeners(channel);
|
|
});
|
|
|
|
socket.on('sendToIpcRenderer', (browserWindow, channel, ...data) => {
|
|
const window = BrowserWindow.fromId(browserWindow.id);
|
|
|
|
if (window) {
|
|
window.webContents.send(channel, data);
|
|
}
|
|
});
|
|
} |