Skip to content

Commit

Permalink
feat(main): provide store to renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
antonreshetov committed Mar 25, 2022
1 parent 18462a4 commit 9829f0a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/main/preload.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { contextBridge, ipcRenderer } from 'electron'
import { store } from './store'
import type { ElectronBridge } from './types'

contextBridge.exposeInMainWorld('electron', {
Expand All @@ -12,5 +13,11 @@ contextBridge.exposeInMainWorld('electron', {
},
removeListener: (channel, cb) => ipcRenderer.removeListener(channel, cb),
removeListeners: channel => ipcRenderer.removeAllListeners(channel)
},
store: {
app: {
get: name => store.app.get(name),
set: (name, value) => store.app.set(name, value)
}
}
} as ElectronBridge)
7 changes: 7 additions & 0 deletions src/main/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { IpcRendererEvent } from 'electron'
import type { AppStoreSchema } from '../store/module/app'
interface EventCallback {
(event?: IpcRendererEvent, ...args: any[]): void
}
Expand All @@ -9,6 +10,12 @@ export interface ElectronBridge {
removeListener: (channel: string, cb: EventCallback) => void
removeListeners: (channel: string) => void
}
store: {
app: {
get: (name: keyof AppStoreSchema) => string
set: (name: keyof AppStoreSchema, value: any) => void
}
}
}

declare global {
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/electron.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
const { ipc } = window.electron
const { ipc, store } = window.electron

export { ipc }
export { ipc, store }

0 comments on commit 9829f0a

Please sign in to comment.