Skip to content

Latest commit

 

History

History
 
 

suite-desktop-api

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

@trezor/suite-desktop-api

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;

Usage examples in main process

Usage examples in renderer process

How to add new method/channel

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 as DesktopApiInvoke<'your-new-channel'>
  • process incoming request in @trezor/suite-desktop/src-electron/modules/* using ipcMain.handle('your-new-channel', (arg?: string) => { return 1; })
  • trigger it from @trezor/suite using const r = await desktopApi.yourNewFunction()

To receive asynchronous event in renderer process

  • add channel to ./src/api.ts RendererChannels
  • set listener in @trezor/suite using await desktopApi.on('your-new-channel', (payload) => {})
  • trigger event from @trezor/suite-desktop/src-electron/modules/* using mainWindow.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 as DesktopApiSend<'your-new-channel'>
  • set listener in @trezor/suite-desktop/src-electron/modules/* using ipcMain.on('your-new-channel', (_, { foo }) => {})
  • trigger event from @trezor/suite using desktopApi.yourNewFunction({ foo: 'bar' })