Skip to content

Commit

Permalink
feat(main): expose on & once events
Browse files Browse the repository at this point in the history
  • Loading branch information
antonreshetov committed Apr 3, 2022
1 parent 3fce6b5 commit 008e11a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/main/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import type { ElectronBridge } from './types'

contextBridge.exposeInMainWorld('electron', {
ipc: {
invoke: (channel, payload) => ipcRenderer.invoke(channel, payload)
invoke: (channel, payload) => ipcRenderer.invoke(channel, payload),
on: (channel, cb) => ipcRenderer.on(channel, cb),
once: (channel, cb) => ipcRenderer.once(channel, cb)
},
store: {
app: {
Expand Down
9 changes: 8 additions & 1 deletion src/main/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import type { IpcRendererEvent } from 'electron'
import type { AppStore, PreferencesStore } from '../store/module/types'
import type { DB, Folder, Tag, Snippet } from './db'

type ChannelSubject = 'snippet' | 'snippet-fragment' | 'folder'
type ChannelSubject = 'snippet' | 'snippet-fragment' | 'folder' | 'close'

type ContextMenuAction =
| 'rename'
Expand Down Expand Up @@ -34,6 +35,10 @@ export interface ContextMenuResponse {
data: any
}

interface EventCallback {
(event?: IpcRendererEvent, ...args: any[]): void
}

interface StoreGet<T> {
(name: keyof T): any
}
Expand All @@ -51,6 +56,8 @@ interface StoreProperties<T> {
export interface ElectronBridge {
ipc: {
invoke<T, U>(channel: Channel, payload: U): Promise<T>
on(channel: Channel, cb: EventCallback): void
once(channel: Channel, cb: EventCallback): void
}
store: {
app: StoreProperties<AppStore>
Expand Down

0 comments on commit 008e11a

Please sign in to comment.