Private package provides strongly typed DesktopApi
used in @trezor/suite
and @trezor/suite-desktop
Exported modules:
main
(default) used in@trezor/suite-desktop/src-electron
in main (nodejs) context.renderer
(browser) used in@trezor/suite
and@trezor/suite-desktop/src
in renderer context.
export function getDesktopApi(ipcRenderer?: Electron.IpcRenderer): DesktopApi;
export const desktopApi: DesktopApi;
-
Overload
electron
types. see typed-electron.ts -
Create
DesktopApi
instance and expose it to rendererwindow.desktopApi
object. see preload.ts -
Receive invoke messages from renderer. see metadata module
-
Receive event messages from renderer. see theme module
-
Send event messages to renderer. see
mainWindow.webContents.send
in autoupdater module
-
DesktopApi.invoke
. see metadata module -
DesktopApi.on
. see AutoUpdater component -
DesktopApi.send
. see metadata module
To invoke method on main
process and return asynchronous result to renderer
process
- add channel to
./src/api.ts InvokeChannels
- add method to
./src/api.ts DesktopApi
asDesktopApiInvoke<'your-new-channel'>
- process incoming request in
@trezor/suite-desktop/src-electron/modules/*
usingipcMain.handle('your-new-channel', (arg?: string) => { return 1; })
- trigger it from
@trezor/suite
usingconst r = await desktopApi.yourNewFunction()
To receive asynchronous event in renderer
process
- add channel to
./src/api.ts RendererChannels
- set listener in
@trezor/suite
usingawait desktopApi.on('your-new-channel', (payload) => {})
- trigger event from
@trezor/suite-desktop/src-electron/modules/*
usingmainWindow.webContents.send('your-new-channel', { foo: 'bar' })
To receive asynchronous event in main
process
- add channel to
./src/api.ts MainChannels
- add method to
./src/api.ts DesktopApi
asDesktopApiSend<'your-new-channel'>
- set listener in
@trezor/suite-desktop/src-electron/modules/*
usingipcMain.on('your-new-channel', (_, { foo }) => {})
- trigger event from
@trezor/suite
usingdesktopApi.yourNewFunction({ foo: 'bar' })