Skip to content

Commit 488276f

Browse files
authored
feat(ui): reboot device (jetkvm#421) (jetkvm#505)
1 parent 7267347 commit 488276f

File tree

3 files changed

+86
-0
lines changed

3 files changed

+86
-0
lines changed

ui/src/main.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import SettingsHardwareRoute from "./routes/devices.$id.settings.hardware";
4242
import SettingsVideoRoute from "./routes/devices.$id.settings.video";
4343
import SettingsAppearanceRoute from "./routes/devices.$id.settings.appearance";
4444
import * as SettingsGeneralIndexRoute from "./routes/devices.$id.settings.general._index";
45+
import SettingsGeneralRebootRoute from "./routes/devices.$id.settings.general.reboot";
4546
import SettingsGeneralUpdateRoute from "./routes/devices.$id.settings.general.update";
4647
import SettingsNetworkRoute from "./routes/devices.$id.settings.network";
4748
import SecurityAccessLocalAuthRoute from "./routes/devices.$id.settings.access.local-auth";
@@ -140,6 +141,10 @@ if (isOnDevice) {
140141
index: true,
141142
element: <SettingsGeneralIndexRoute.default />,
142143
},
144+
{
145+
path: "reboot",
146+
element: <SettingsGeneralRebootRoute />,
147+
},
143148
{
144149
path: "update",
145150
element: <SettingsGeneralUpdateRoute />,

ui/src/routes/devices.$id.settings.general._index.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,21 @@ export default function SettingsGeneralRoute() {
9292
/>
9393
</SettingsItem>
9494
</div>
95+
96+
<div className="mt-2 flex items-center justify-between gap-x-2">
97+
<SettingsItem
98+
title="Reboot Device"
99+
description="Power cycle the JetKVM"
100+
/>
101+
<div>
102+
<Button
103+
size="SM"
104+
theme="light"
105+
text="Reboot Device"
106+
onClick={() => navigateTo("./reboot")}
107+
/>
108+
</div>
109+
</div>
95110
</div>
96111
</div>
97112
</div>
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import { useNavigate } from "react-router-dom";
2+
import { useCallback } from "react";
3+
4+
import { useJsonRpc } from "@/hooks/useJsonRpc";
5+
import { Button } from "@components/Button";
6+
7+
export default function SettingsGeneralRebootRoute() {
8+
const navigate = useNavigate();
9+
const [send] = useJsonRpc();
10+
11+
const onConfirmUpdate = useCallback(() => {
12+
// This is where we send the RPC to the golang binary
13+
send("reboot", {force: true});
14+
}, [send]);
15+
16+
{
17+
/* TODO: Migrate to using URLs instead of the global state. To simplify the refactoring, we'll keep the global state for now. */
18+
}
19+
return <Dialog onClose={() => navigate("..")} onConfirmUpdate={onConfirmUpdate} />;
20+
}
21+
22+
export function Dialog({
23+
onClose,
24+
onConfirmUpdate,
25+
}: {
26+
onClose: () => void;
27+
onConfirmUpdate: () => void;
28+
}) {
29+
30+
return (
31+
<div className="pointer-events-auto relative mx-auto text-left">
32+
<div>
33+
<ConfirmationBox
34+
onYes={onConfirmUpdate}
35+
onNo={onClose}
36+
/>
37+
</div>
38+
</div>
39+
);
40+
}
41+
42+
function ConfirmationBox({
43+
onYes,
44+
onNo,
45+
}: {
46+
onYes: () => void;
47+
onNo: () => void;
48+
}) {
49+
return (
50+
<div className="flex flex-col items-start justify-start space-y-4 text-left">
51+
<div className="text-left">
52+
<p className="text-base font-semibold text-black dark:text-white">
53+
Reboot JetKVM
54+
</p>
55+
<p className="text-sm text-slate-600 dark:text-slate-300">
56+
Do you want to proceed with rebooting the system?
57+
</p>
58+
59+
<div className="mt-4 flex gap-x-2">
60+
<Button size="SM" theme="light" text="Yes" onClick={onYes} />
61+
<Button size="SM" theme="blank" text="No" onClick={onNo} />
62+
</div>
63+
</div>
64+
</div>
65+
);
66+
}

0 commit comments

Comments
 (0)