import { remote } from 'electron' ; import { Dispatch , connect } from 'react-redux' ; import { exec } from 'child_process' ; import * as path from 'path' ; import * as AppUIActions from '../actions/appUI' ; import * as ResponseViewerActions from '../actions/responseViewer' ; import { AppState } from '../reducers/index' ; import { ErrorDialogState } from '../reducers/appUI' ; import AppComponent , { AppComponentMethods , AppComponentState } from '../components/app' ; export const checkConsoleErrorMessage = 'Check the logs.' ; export const DEV_PATH_TO_POLYGLOT_BINARY = `${ process . cwd ( ) }/app/polyglot_deploy.jar` ; export const PROD_PATH_TO_POLYGLOT_BINARY = path . join ( remote . app . getAppPath ( ) , 'polyglot_deploy.jar' ) . replace ( 'app.asar' , 'app.asar.unpacked' ) ; returns { ( dispatch : Dispatch < AppState > , getState : ( ) => AppState ) => void } function closeDialog ( ) { return ( dispatch , getState ) => { console . log ( 'closeDialog' ) ; if ( getState ( ) . appUIState . errorDialogQueue . length <= 1 ) { dispatch ( AppUIActions . setErrorDialogVisible ( false ) ) ; } dispatch ( AppUIActions . dequeueErrorDialogState ( ) ) ; } ; } returns { ( dispatch : Dispatch < AppState > , getState : ( ) => AppState ) => void } function openDialog ( title , explanation , onAccept ? , onCancel ? ) { return ( dispatch ) => { const dialogState = { errorDialogTitle : title , errorDialogExplanation : explanation , onAccept : onAccept , onCancel : onCancel , } ; dispatch ( AppUIActions . enqueueErrorDialogState ( dialogState ) ) ; dispatch ( AppUIActions . setErrorDialogVisible ( true ) ) ; } ; } returns { void } function showNotification ( title , body ) { const notification = new Notification ( title , { body : body , } ) ; console . log ( `Showing notification ${ notification }` ) ; } returns { ( dispatch : Dispatch < AppState > , getState : ( ) => AppState ) => void } function handleSettingsClick ( ) { return ( dispatch , getState ) => { dispatch ( AppUIActions . setSettingsOpen ( ! getState ( ) . appUIState . settingsOpen ) ) ; } ; } returns { ( dispatch : Dispatch < AppState > , getState : ( ) => AppState ) => void } function checkRuntimeJavaVersion ( ) { return ( dispatch ) => { exec ( 'java -version' , ( error , stdout , stderr ) => { if ( error ) { console . error ( 'Error checking java version' ) ; } else { const regex = /java version \"([0-9]+.[0-9]+)/g ; const match = regex . exec ( stderr ) ; if ( match !== null ) { const rawJavaVersion = match [ 1 ] ; const parsedJavaVersion = parseFloat ( rawJavaVersion ) ; if ( ! isNaN ( parsedJavaVersion ) && parsedJavaVersion < 1.8 ) { showNotification ( 'Java Runtime Version Error' , 'Polyglot requires version >= 1.8' ) ; } } } } ) ; } ; } function mapStateToProps ( state ) { return { appState : state , } ; } function mapDispatchToProps ( dispatch ) { return { closeDialog : ( ) => dispatch ( closeDialog ( ) ) , openDialog : ( title , explanation , onAccept ? , onCancel ? ) => dispatch ( openDialog ( title , explanation , onAccept , onCancel ) ) , handleSettingsClick : ( ) => dispatch ( handleSettingsClick ( ) ) , checkRuntimeJavaVersion : ( ) => dispatch ( checkRuntimeJavaVersion ( ) ) , showNotification : ( title , body ) => showNotification ( title , body ) , clearLogs : ( ) => dispatch ( ResponseViewerActions . clearLogs ( ) ) , } ; } export default connect ( mapStateToProps , mapDispatchToProps ) ( AppComponent ) ;