import { BrowserWindow } from "electron" ; import { Store } from "redux" ; import { ActionCommand } from "./types" ; export const dispatchCommandInMain = < STORE extends Store , COMMAND extends ActionCommand < STORE , PROPS > , PROPS > ( command , props ) => { if ( command . runInMainThread ) { command . runInMainThread ( props ) ; } const focusedWindow = BrowserWindow . getFocusedWindow ( ) ; if ( focusedWindow ) { focusedWindow . webContents . send ( "command" , command . name , props ) ; } } ; export const dispatchCommandInRenderer = < STORE extends Store < any , any > , COMMAND extends ActionCommand < STORE , PROPS > , PROPS > ( store , command , props ) => { if ( command . makeAction ) { store . dispatch ( command . makeAction ( props ) ) ; } if ( command . makeActions ) { const actions = command . makeActions ( store , props ) ; Promise . resolve ( actions ) . then ( async ( result ) => { for await ( const action of result ) { store . dispatch ( await action ) ; } } ) ; } } ;