Commit c917c41f authored by zeroleak's avatar zeroleak
Browse files

add CLI restart button + show CLI startup progress

parent 01f65003
// @flow
import React, { Component } from 'react';
import { connect } from 'react-redux';
......@@ -15,6 +14,7 @@ class ConnectingPage extends Component<Props> {
super(props)
this.reconnect = this.reconnect.bind(this)
this.onRestartCli = this.onRestartCli.bind(this)
this.onResetConfig = this.onResetConfig.bind(this)
}
......@@ -29,17 +29,28 @@ class ConnectingPage extends Component<Props> {
cliService.fetchState()
}
onRestartCli() {
if (confirm('This will restart CLI. Are you sure?')) {
cliService.restart()
}
}
renderConnecting(cliUrlError) {
return (
<form className="form-signin text-center" onSubmit={(e) => {this.onSubmit();e.preventDefault()}}>
<h1 className="h3 mb-3 font-weight-normal">Connecting...</h1>
<h1 className="h3 mb-3 font-weight-normal">{cliService.getStatusIcon((icon,status)=><span>{icon} {status}</span>)}</h1>
<div><FontAwesomeIcon icon={Icons.faCloud} size='3x' color='#343a40'/></div><br/>
<p>Connecting to whirlpool-cli<br/>
<strong>{cliService.getCliUrl()}</strong></p>
{cliService.isCliLocal() && <div>{cliLocalService.getStatusIcon((icon,text)=><span>{icon} {text}<br/>(might take a minute to start... restart if longer)</span>)}<br/><br/></div>}
<div>whirlpool-cli @ <strong>{cliService.isCliLocal() ? 'standalone GUI' : cliService.getCliUrl()}</strong></div>
<br/>
{cliService.isCliLocal() && <div>
{cliLocalService.getStatusIcon((icon,text)=><span>{icon} {text}</span>)}<br/>
{(!cliService.isConnected() || cliService.isCliStatusStarting()) && <small className='text-muted'>Might take a minute to start... restart if longer.</small>}<br/>
</div>}
<br/>
{cliService.getCliMessage() && <Alert variant='info'>{cliService.getCliMessage()}</Alert>}
<button type='button' className='btn btn-primary' onClick={this.reconnect}><FontAwesomeIcon icon={Icons.faSync} /> Retry to connect</button>
{!cliService.isConnected() && <button type='button' className='btn btn-primary' onClick={this.reconnect}><FontAwesomeIcon icon={Icons.faSync} /> Retry to connect</button>}
{cliService.isConnected() && <button type='button' className='btn btn-danger' onClick={this.onRestartCli}>Restart CLI</button>}
{cliUrlError && <div>
<br/>
......
// @flow
import React, { Component } from 'react';
import './PremixPage.css';
import { Dropdown, DropdownButton } from 'react-bootstrap';
import { bindActionCreators } from 'redux';
import { walletActions } from '../actions/walletActions';
import { connect } from 'react-redux';
......
......@@ -8,7 +8,8 @@ import {
CLI_CONFIG_FILENAME,
CLI_LOG_ERROR_FILE,
CLI_LOG_FILE,
cliApiService, GUI_CONFIG_FILENAME,
cliApiService,
GUI_CONFIG_FILENAME,
GUI_LOG_FILE,
GUI_VERSION
} from '../const';
......@@ -26,6 +27,7 @@ export default class StatusPage extends Component<Props> {
super(props)
this.onResetConfig = this.onResetConfig.bind(this)
this.onRestartCli = this.onRestartCli.bind(this)
this.cliLogFile = CLI_LOG_FILE
this.cliLogErrorFile = CLI_LOG_ERROR_FILE
......@@ -38,6 +40,11 @@ export default class StatusPage extends Component<Props> {
}
}
onRestartCli() {
if (confirm('This will restart CLI. Are you sure?')) {
cliService.restart()
}
}
render() {
const cliStatusIcon = cliService.getStatusIcon((icon,text)=><div>{icon} {text}</div>)
......@@ -116,6 +123,9 @@ export default class StatusPage extends Component<Props> {
</div>
</Card.Header>
<Card.Body>
<div style={{'float':'right'}}>
<button type='button' className='btn btn-danger' onClick={this.onRestartCli}>Restart CLI</button>
</div>
<div className='row'>
<div className='col-sm-2'>
<strong>Status:</strong>
......
import * as React from 'react';
import { ipcRenderer } from 'electron';
import { ProgressBar } from 'react-bootstrap';
import { CLILOCAL_STATUS, IPC_CLILOCAL, cliApiService } from '../const';
import { cliApiService, CLILOCAL_STATUS, IPC_CLILOCAL } from '../const';
import cliService from './cliService';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import * as Icons from '@fortawesome/free-solid-svg-icons';
import moment from 'moment';
import utils from './utils';
class CliLocalService {
constructor() {
......@@ -88,26 +88,26 @@ class CliLocalService {
}
// error
if (cliLocalService.isStatusError()) {
const status = 'CLI error: '+infoError
const status = 'Local CLI error: '+infoError
return format(<FontAwesomeIcon icon={Icons.faCircle} color='red' title={status}/>, status)
}
if (cliLocalService.isStarted()) {
// started
const status = 'CLI running for '+moment.duration(new Date().getTime()-cliLocalService.getStartTime()).humanize()
const status = 'Local CLI was launched '+utils.durationElapsed(cliLocalService.getStartTime())+' ago'
return format(<FontAwesomeIcon icon={Icons.faPlay} color='green' title={status} size='xs'/>, status)
}
if (cliLocalService.isStatusUnknown()) {
// unknown
const status = 'CLI is initializing. '+infoError
const status = 'Local CLI is initializing. '+infoError
return format(<FontAwesomeIcon icon={Icons.faCircle} color='red' title={status} size='xs'/>, status)
}
if (!cliLocalService.isValid()) {
// invalid
const status = 'CLI executable is not valid. '+infoError
const status = 'Local CLI executable is not valid. '+infoError
return format(<FontAwesomeIcon icon={Icons.faCircle} color='red' title={status} size='xs'/>, status)
}
// valid but stopped
const status = 'CLI is not running. '+infoError
const status = 'Local CLI is not running. '+infoError
return format(<FontAwesomeIcon icon={Icons.faStop} color='orange' title={status} />, status)
}
......
......@@ -163,6 +163,17 @@ class CliService {
this.doResetGUIConfig()
}
restart() {
backendService.cli.restart()
// force refresh
this.updateState({
cli: undefined,
cliUrlError: undefined,
cliLocalState: undefined
})
}
doResetGUIConfig() {
// reset GUI
......@@ -273,6 +284,10 @@ class CliService {
return this.getNetwork() === 'test'
}
isCliStatusStarting() {
return this.isConnected() && this.state.cli.cliStatus === CLI_STATUS.STARTING
}
isCliStatusReady() {
return this.isConnected() && this.state.cli.cliStatus === CLI_STATUS.READY
}
......@@ -390,25 +405,34 @@ class CliService {
const status = 'Connected to CLI'
return format(<FontAwesomeIcon icon={Icons.faWifi} color='green' title={status} />, status)
}
if (cliService.isCliStatusStarting()) {
// connected & ready
const status = 'CLI is starting...'
return format(<FontAwesomeIcon icon={Icons.faWifi} color='lightgreen' title={status} />, status)
}
if (cliService.getCliUrlError()) {
// not connected
const status = 'Disconnected from CLI'
// error
const status = 'CLI error'
return format(<FontAwesomeIcon icon={Icons.faWifi} color='red' title={status} />, status)
}
// connected & initialization required
if (cliService.isCliStatusNotInitialized()) {
const status = 'Connected to CLI, initialization required'
const status = 'CLI initialization required'
return format(<FontAwesomeIcon icon={Icons.faWifi} color='orange' title={status}/>, status)
}
// connected & not ready
if (cliService.isConnected()) {
// ???
let cliMessage = cliService.getCliMessage()
if (!cliMessage) {
cliMessage = 'starting...'
cliMessage = 'not ready.'
}
const status = 'Connected to CLI, which is not ready: '+cliMessage
const status = 'Waiting for CLI: '+cliMessage
return format(<FontAwesomeIcon icon={Icons.faWifi} color='lightgreen' title={status}/>, status)
}
// not connected
const status = 'Connecting to CLI'
return format(<FontAwesomeIcon icon={Icons.faWifi} color='black' title={status} />, status)
}
getLoginStatusIcon(format) {
......
import ifNot from 'if-not-running';
import moment from 'moment';
import backendService from './backendService';
import { TX0_MIN_CONFIRMATIONS, WHIRLPOOL_ACCOUNTS } from './utils';
import utils, { TX0_MIN_CONFIRMATIONS, WHIRLPOOL_ACCOUNTS } from './utils';
import poolsService from './poolsService';
import walletService from './walletService';
......@@ -125,8 +124,7 @@ class MixService {
if (!utxo.lastActivityElapsed) {
return undefined
}
const fetchElapsed = new Date().getTime()-this.state.mix.fetchTime
return moment.duration(fetchElapsed + utxo.lastActivityElapsed).humanize()
return utils.durationElapsed(this.state.mix.fetchTime-utxo.lastActivityElapsed)
}
isStarted () {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment