Skip to content

Commit 5df46b2

Browse files
committed
Add power controls
1 parent 33f306d commit 5df46b2

File tree

1 file changed

+33
-3
lines changed

1 file changed

+33
-3
lines changed

resources/scripts/components/server/ServerConsole.tsx

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ export default () => {
3737
setCpu(stats.cpu_absolute);
3838
};
3939

40+
const sendPowerCommand = (command: 'start' | 'stop' | 'restart' | 'kill') => {
41+
instance && instance.send('set state', command);
42+
};
43+
4044
useEffect(() => {
4145
if (!connected || !instance) {
4246
return;
@@ -91,9 +95,35 @@ export default () => {
9195
</div>
9296
</div>
9397
<GreyBox className={'justify-center'}>
94-
<button className={'btn btn-secondary btn-xs mr-2'}>Start</button>
95-
<button className={'btn btn-secondary btn-xs mr-2'}>Restart</button>
96-
<button className={'btn btn-red btn-xs'}>Stop</button>
98+
<button
99+
className={'btn btn-secondary btn-xs mr-2'}
100+
disabled={status !== 'offline'}
101+
onClick={e => {
102+
e.preventDefault();
103+
sendPowerCommand('start');
104+
}}
105+
>
106+
Start
107+
</button>
108+
<button
109+
className={'btn btn-secondary btn-xs mr-2'}
110+
onClick={e => {
111+
e.preventDefault();
112+
sendPowerCommand('restart');
113+
}}
114+
>
115+
Restart
116+
</button>
117+
<button
118+
className={'btn btn-red btn-xs'}
119+
disabled={status === 'offline'}
120+
onClick={e => {
121+
e.preventDefault();
122+
sendPowerCommand(status === 'stopping' ? 'kill' : 'stop');
123+
}}
124+
>
125+
Stop
126+
</button>
97127
</GreyBox>
98128
</div>
99129
<React.Suspense

0 commit comments

Comments
 (0)