Add power controls

This commit is contained in:
Dane Everitt 2019-09-17 23:12:38 -07:00
parent 33f306d40b
commit 5df46b23d2
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53

View file

@ -37,6 +37,10 @@ export default () => {
setCpu(stats.cpu_absolute);
};
const sendPowerCommand = (command: 'start' | 'stop' | 'restart' | 'kill') => {
instance && instance.send('set state', command);
};
useEffect(() => {
if (!connected || !instance) {
return;
@ -91,9 +95,35 @@ export default () => {
</div>
</div>
<GreyBox className={'justify-center'}>
<button className={'btn btn-secondary btn-xs mr-2'}>Start</button>
<button className={'btn btn-secondary btn-xs mr-2'}>Restart</button>
<button className={'btn btn-red btn-xs'}>Stop</button>
<button
className={'btn btn-secondary btn-xs mr-2'}
disabled={status !== 'offline'}
onClick={e => {
e.preventDefault();
sendPowerCommand('start');
}}
>
Start
</button>
<button
className={'btn btn-secondary btn-xs mr-2'}
onClick={e => {
e.preventDefault();
sendPowerCommand('restart');
}}
>
Restart
</button>
<button
className={'btn btn-red btn-xs'}
disabled={status === 'offline'}
onClick={e => {
e.preventDefault();
sendPowerCommand(status === 'stopping' ? 'kill' : 'stop');
}}
>
Stop
</button>
</GreyBox>
</div>
<React.Suspense