-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommands-runner.tsx
More file actions
70 lines (64 loc) 路 1.88 KB
/
Copy pathcommands-runner.tsx
File metadata and controls
70 lines (64 loc) 路 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import * as React from 'react';
import { Button, ButtonProps, Spinner } from '@blueprintjs/core';
import { observer } from 'mobx-react';
import { AppState } from '../state';
interface RunnerProps {
appState: AppState;
}
/**
* The runner component is responsible for actually launching the engine. It also renders the button that does so.
*/
export const Runner = observer(
class Runner extends React.Component<RunnerProps> {
public render() {
const { engineStatus, engineEnv } = this.props.appState;
const props: ButtonProps = { disabled: false };
switch (engineStatus) {
case 'initialization': {
props.text = 'Stop';
try {
window.ElectronFiddle.startEngine(engineEnv);
} catch (err) {
this.props.appState.pushError(err.message, err);
}
props.icon = 'stop';
break;
}
case 'stopped': {
props.text = 'Run';
props.onClick = async () => {
try {
await window.ElectronFiddle.startEngine(engineEnv);
} catch (err) {
this.props.appState.pushError(err.message, err);
}
};
props.icon = 'play';
break;
}
case 'remote':
case 'ready': {
props.text = 'Stop';
props.icon = 'stop';
props.onClick = () => {
window.ElectronFiddle.stopEngine();
};
break;
}
case 'starting': {
props.text = 'Starting';
props.icon = <Spinner size={16} />;
props.onClick = () => {
window.ElectronFiddle.stopEngine();
};
break;
}
default: {
props.text = 'Checking status';
props.icon = <Spinner size={16} />;
}
}
return <Button id="button-run" {...props} type={undefined} />;
}
},
);