Skip to content

Commit 8f76e1f

Browse files
committed
feat: Factory Reset and Reboot wording rework. (jetkvm#529)
1 parent 488276f commit 8f76e1f

File tree

6 files changed

+95
-50
lines changed

6 files changed

+95
-50
lines changed

config.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,20 @@ func SaveConfig() error {
205205
return nil
206206
}
207207

208+
func RemoveConfig() error {
209+
configLock.Lock()
210+
defer configLock.Unlock()
211+
212+
logger.Trace().Str("path", configPath).Msg("Removing config")
213+
214+
err := os.Remove(configPath)
215+
if err != nil {
216+
return fmt.Errorf("failed to remove config file: %w", err)
217+
}
218+
219+
return nil
220+
}
221+
208222
func ensureConfigLoaded() {
209223
if config == nil {
210224
LoadConfig()

jsonrpc.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,24 @@ func rpcReboot(force bool) error {
192192
return nil
193193
}
194194

195+
func rpcFactoryReset() error {
196+
logger.Info().Msg("Got factory reset request from JSONRPC")
197+
198+
err := RemoveConfig()
199+
if err != nil {
200+
logger.Error().Err(err).Msg("failed to remove config")
201+
return err
202+
}
203+
204+
err = rpcReboot(true)
205+
if err != nil {
206+
logger.Error().Err(err).Msg("failed to reboot after config remove")
207+
return err
208+
}
209+
210+
return nil
211+
}
212+
195213
var streamFactor = 1.0
196214

197215
func rpcGetStreamQualityFactor() (float64, error) {
@@ -1038,6 +1056,7 @@ func rpcSetLocalLoopbackOnly(enabled bool) error {
10381056
var rpcHandlers = map[string]RPCHandler{
10391057
"ping": {Func: rpcPing},
10401058
"reboot": {Func: rpcReboot, Params: []string{"force"}},
1059+
"factoryReset": {Func: rpcFactoryReset},
10411060
"getDeviceID": {Func: rpcGetDeviceID},
10421061
"deregisterDevice": {Func: rpcDeregisterDevice},
10431062
"getCloudState": {Func: rpcGetCloudState},

ui/src/main.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ 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";
4545
import SettingsGeneralRebootRoute from "./routes/devices.$id.settings.general.reboot";
46+
import SettingsGeneralFactoryResetRoute from "./routes/devices.$id.settings.general.factory-reset";
4647
import SettingsGeneralUpdateRoute from "./routes/devices.$id.settings.general.update";
4748
import SettingsNetworkRoute from "./routes/devices.$id.settings.network";
4849
import SecurityAccessLocalAuthRoute from "./routes/devices.$id.settings.access.local-auth";
@@ -145,6 +146,10 @@ if (isOnDevice) {
145146
path: "reboot",
146147
element: <SettingsGeneralRebootRoute />,
147148
},
149+
{
150+
path: "factory-reset",
151+
element: <SettingsGeneralFactoryResetRoute />,
152+
},
148153
{
149154
path: "update",
150155
element: <SettingsGeneralUpdateRoute />,

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

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,18 +95,33 @@ export default function SettingsGeneralRoute() {
9595

9696
<div className="mt-2 flex items-center justify-between gap-x-2">
9797
<SettingsItem
98-
title="Reboot Device"
99-
description="Power cycle the JetKVM"
98+
title="Reboot"
99+
description="Reboot the JetKVM"
100100
/>
101101
<div>
102102
<Button
103103
size="SM"
104104
theme="light"
105-
text="Reboot Device"
105+
text="Reboot"
106106
onClick={() => navigateTo("./reboot")}
107107
/>
108108
</div>
109109
</div>
110+
111+
<div className="mt-2 flex items-center justify-between gap-x-2">
112+
<SettingsItem
113+
title="Factory Reset"
114+
description="Factory reset the JetKVM to the default configuration"
115+
/>
116+
<div>
117+
<Button
118+
size="SM"
119+
theme="light"
120+
text="Factory Reset"
121+
onClick={() => navigateTo("./factory-reset")}
122+
/>
123+
</div>
124+
</div>
110125
</div>
111126
</div>
112127
</div>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { useNavigate } from "react-router-dom";
2+
import { useCallback } from "react";
3+
4+
import { useJsonRpc } from "@/hooks/useJsonRpc";
5+
import { ConfirmDialog } from "@/components/ConfirmDialog";
6+
7+
export default function SettingsGeneralFactoryResetRoute() {
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("factoryReset", {});
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 (
20+
<ConfirmDialog
21+
open={true}
22+
onClose={() => navigate("..")}
23+
title="Factory Reset"
24+
description="Do you want to proceed with factory resetting the JetKVM?"
25+
variant="danger"
26+
onConfirm={onConfirmUpdate}
27+
/>
28+
);
29+
}

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

Lines changed: 10 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { useNavigate } from "react-router-dom";
22
import { useCallback } from "react";
33

44
import { useJsonRpc } from "@/hooks/useJsonRpc";
5-
import { Button } from "@components/Button";
5+
import { ConfirmDialog } from "@/components/ConfirmDialog";
66

77
export default function SettingsGeneralRebootRoute() {
88
const navigate = useNavigate();
@@ -16,51 +16,14 @@ export default function SettingsGeneralRebootRoute() {
1616
{
1717
/* TODO: Migrate to using URLs instead of the global state. To simplify the refactoring, we'll keep the global state for now. */
1818
}
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-
}) {
4919
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>
20+
<ConfirmDialog
21+
open={true}
22+
onClose={() => navigate("..")}
23+
title="Reboot JetKVM"
24+
description="Do you want to proceed with rebooting the JetKVM?"
25+
variant="danger"
26+
onConfirm={onConfirmUpdate}
27+
/>
6528
);
66-
}
29+
}

0 commit comments

Comments
 (0)