Skip to content

Commit

Permalink
feat(main): expose only invoke ipc
Browse files Browse the repository at this point in the history
  • Loading branch information
antonreshetov committed Mar 31, 2022
1 parent 4dc4974 commit daf42b5
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 20 deletions.
10 changes: 1 addition & 9 deletions src/main/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,7 @@ import type { ElectronBridge } from './types'

contextBridge.exposeInMainWorld('electron', {
ipc: {
on: (channel, cb) => ipcRenderer.on(channel, cb),
send: (channel, data, cb) => {
ipcRenderer.send(channel, data)
if (cb && typeof cb === 'function') {
ipcRenderer.on(channel, cb)
}
},
removeListener: (channel, cb) => ipcRenderer.removeListener(channel, cb),
removeListeners: channel => ipcRenderer.removeAllListeners(channel)
invoke: (channel, payload) => ipcRenderer.invoke(channel, payload)
},
store: {
app: {
Expand Down
12 changes: 1 addition & 11 deletions src/main/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type { IpcRendererEvent } from 'electron'
import type { AppStore, PreferencesStore } from '../store/module/types'
import type { DB, Folder, Tag, Snippet } from './db'

Expand All @@ -16,10 +15,7 @@ interface StoreSet<T> {

export interface ElectronBridge {
ipc: {
on: (channel: string, cb: EventCallback) => void
send: (channel: string, data: any, cb: EventCallback) => void
removeListener: (channel: string, cb: EventCallback) => void
removeListeners: (channel: string) => void
invoke<T, U>(channel: Channel, payload: U): Promise<T>
}
store: {
app: {
Expand All @@ -40,9 +36,3 @@ export interface ElectronBridge {
) => void
}
}

declare global {
interface Window {
electron: ElectronBridge
}
}

0 comments on commit daf42b5

Please sign in to comment.