Skip to content
This repository has been archived by the owner on Oct 18, 2024. It is now read-only.

Commit

Permalink
Add client side Event helper (#38)
Browse files Browse the repository at this point in the history
* Add broadcasting endpoint & dispatch ipc event

* Inject Native helper object in browser window

* Strip leading slashes before matching event name

* added event name as second callback parameter
  • Loading branch information
gwleuverink authored Sep 13, 2024
1 parent 861dfab commit 7bae295
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/preload/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { contextBridge, ipcRenderer } from 'electron'
import * as remote from '@electron/remote'

import Native from './native';

// @ts-ignore
window.Native = Native;

// @ts-ignore
window.remote = remote;

Expand Down
16 changes: 16 additions & 0 deletions src/preload/native.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { ipcRenderer } from 'electron'

export default {
on: (event, callback) => {
ipcRenderer.on('native-event', (_, data) => {

// Strip leading slashes
event = event.replace(/^(\\)+/, '');
data.event = data.event.replace(/^(\\)+/, '');

if(event === data.event) {
return callback(data.payload, event);
}
})
}
}

0 comments on commit 7bae295

Please sign in to comment.