import React from 'react' ; import uuid from 'uuid' ; import { sendAnalyticsEvent } from './analytics' ; import AppState from './AppState' ; import { CmdShell , CommandInput } from './cmd' ; import AboutResultView from './components/AboutResultView' ; import DonateResultView from './components/DonateResultView' ; import ErrorResultView from './components/ErrorResultView' ; import HelpResultView from './components/HelpResultView' ; import TextResultView from './components/TextResultView' ; import WhatsnewResultView from './components/WhatsNewResultView' ; import { STARTUP_COMMAND_KEY } from './startup' ; const shellModule = { setup : function ( appState , cmd ) { cmd . debugMode = appState . debugMode ; appState . onChange ( ( ) => cmd . debugMode = appState . debugMode ) ; cmd . command ( "help" , ( c ) => appState . addCommandResult ( c . input , < HelpResultView />)); cmd . command ( "clear" , ( ) => appState . clearCommandResults ( ) ) ; cmd . command ( "em" , ( ) => appState . toggleEmphasizeBytes ( ) ) ; cmd . command ( "dark" , ( ) => appState . setUiTheme ( 'dark' ) ) ; cmd . command ( "light" , ( ) => appState . setUiTheme ( 'light' ) ) ; cmd . command ( "midnight" , ( ) => appState . setUiTheme ( 'midnight' ) ) ; cmd . command ( "about" , ( c ) => appState . addCommandResult ( c . input , < AboutResultView />)); cmd . command ( "whatsnew" , ( c ) => appState . addCommandResult ( c . input , < WhatsnewResultView />)); cmd . command ( "guid" , ( c ) => appState . addCommandResult ( c . input , < TextResultView text = { uuid ( ) } / > ) ) ; cmd . command ( "-notrack" , ( ) => { } ) ; cmd . command ( "-debug" , ( c ) => { appState . toggleDebugMode ( ) ; appState . addCommandResult ( c . input , < TextResultView text = { `Debug Mode: ${ appState . debugMode }` } />); } ) ; cmd . command ( "donate" , ( c ) => { if ( appState . onDonationClicked ( ) ) { sendAnalyticsEvent ( { eventCategory : "Donation" , eventAction : "DonateButtonClicked" } ) ; } else { sendAnalyticsEvent ( { eventCategory : "Donation" , eventAction : "DonateButtonClickedAgain" } ) ; } appState . addCommandResult ( c . input , < DonateResultView />); } ) ; cmd . command ( "track" , ( c ) => { sendAnalyticsEvent ( { eventCategory : 'General' , eventAction : 'AnalyticsTest' } ) ; } ) ; if ( appState . env !== 'prod' ) { cmd . command ( { canHandle : ( s ) => s . indexOf ( 'default' ) === 0 , handle : ( s ) => { const executeCommand = ( c ) => { console . log ( c ) ; if ( c . length === 0 ) { return "Default comand: " + localStorage . getItem ( STARTUP_COMMAND_KEY ) ; } else if ( c === 'clear' ) { localStorage . removeItem ( STARTUP_COMMAND_KEY ) ; return "Default startup command cleared" ; } localStorage . setItem ( STARTUP_COMMAND_KEY , c ) ; return `Default startup command saved: ${ c }` ; } ; const command = s . input . substring ( 7 ) . trim ( ) ; const result = executeCommand ( command ) ; appState . addCommandResult ( s . input , < TextResultView text = { result } / > ) ; } } ) ; } ; cmd . onError ( ( input , err ) => appState . addCommandResult ( input , < ErrorResultView errorMessage = { err . toString ( ) } / > ) ) ; } } ; export default shellModule ;