Skip to content

Commit d952480

Browse files
authored
fix: useJsonRpc "any" issue
PR #743 didn't have all the files included in the commit. Mea culpa, many apologies.
1 parent 8e27cd6 commit d952480

27 files changed

+133
-133
lines changed

ui/src/components/JigglerSetting.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { useEffect, useMemo, useState } from "react";
22
import { LuExternalLink } from "react-icons/lu";
33

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

77
import { InputFieldWithLabel } from "./InputField";
88
import { SelectMenuBasic } from "./SelectMenuBasic";
@@ -34,7 +34,7 @@ export function JigglerSetting({
3434
const [timezones, setTimezones] = useState<string[]>([]);
3535

3636
useEffect(() => {
37-
send("getTimezones", {}, resp => {
37+
send("getTimezones", {}, (resp: JsonRpcResponse) => {
3838
if ("error" in resp) return;
3939
setTimezones(resp.result as string[]);
4040
});

ui/src/components/MacroBar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { useJsonRpc } from "@/hooks/useJsonRpc";
1010
export default function MacroBar() {
1111
const { macros, initialized, loadMacros, setSendFn } = useMacrosStore();
1212
const { executeMacro } = useKeyboard();
13-
const [send] = useJsonRpc();
13+
const { send } = useJsonRpc();
1414

1515
useEffect(() => {
1616
setSendFn(send);

ui/src/components/UsbDeviceSetting.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useCallback , useEffect, useState } from "react";
22

3-
import { useJsonRpc } from "../hooks/useJsonRpc";
3+
import { JsonRpcResponse, useJsonRpc } from "../hooks/useJsonRpc";
44
import notifications from "../notifications";
55
import { SettingsItem } from "../routes/devices.$id.settings";
66

@@ -59,15 +59,15 @@ const usbPresets = [
5959
];
6060

6161
export function UsbDeviceSetting() {
62-
const [send] = useJsonRpc();
62+
const { send } = useJsonRpc();
6363
const [loading, setLoading] = useState(false);
6464

6565
const [usbDeviceConfig, setUsbDeviceConfig] =
6666
useState<UsbDeviceConfig>(defaultUsbDeviceConfig);
6767
const [selectedPreset, setSelectedPreset] = useState<string>("default");
6868

6969
const syncUsbDeviceConfig = useCallback(() => {
70-
send("getUsbDevices", {}, resp => {
70+
send("getUsbDevices", {}, (resp: JsonRpcResponse) => {
7171
if ("error" in resp) {
7272
console.error("Failed to load USB devices:", resp.error);
7373
notifications.error(
@@ -97,7 +97,7 @@ export function UsbDeviceSetting() {
9797
const handleUsbConfigChange = useCallback(
9898
(devices: UsbDeviceConfig) => {
9999
setLoading(true);
100-
send("setUsbDevices", { devices }, async resp => {
100+
send("setUsbDevices", { devices }, async (resp: JsonRpcResponse) => {
101101
if ("error" in resp) {
102102
notifications.error(
103103
`Failed to set usb devices: ${resp.error.data || "Unknown error"}`,

ui/src/components/UsbInfoSetting.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Button } from "@components/Button";
44

55

66
import { UsbConfigState } from "../hooks/stores";
7-
import { useJsonRpc } from "../hooks/useJsonRpc";
7+
import { JsonRpcResponse, useJsonRpc } from "../hooks/useJsonRpc";
88
import notifications from "../notifications";
99
import { SettingsItem } from "../routes/devices.$id.settings";
1010

@@ -54,7 +54,7 @@ const usbConfigs = [
5454
type UsbConfigMap = Record<string, USBConfig>;
5555

5656
export function UsbInfoSetting() {
57-
const [send] = useJsonRpc();
57+
const { send } = useJsonRpc();
5858
const [loading, setLoading] = useState(false);
5959

6060
const [usbConfigProduct, setUsbConfigProduct] = useState("");
@@ -94,7 +94,7 @@ export function UsbInfoSetting() {
9494
);
9595

9696
const syncUsbConfigProduct = useCallback(() => {
97-
send("getUsbConfig", {}, resp => {
97+
send("getUsbConfig", {}, (resp: JsonRpcResponse) => {
9898
if ("error" in resp) {
9999
console.error("Failed to load USB Config:", resp.error);
100100
notifications.error(
@@ -114,7 +114,7 @@ export function UsbInfoSetting() {
114114
const handleUsbConfigChange = useCallback(
115115
(usbConfig: USBConfig) => {
116116
setLoading(true);
117-
send("setUsbConfig", { usbConfig }, async resp => {
117+
send("setUsbConfig", { usbConfig }, async (resp: JsonRpcResponse) => {
118118
if ("error" in resp) {
119119
notifications.error(
120120
`Failed to set usb config: ${resp.error.data || "Unknown error"}`,
@@ -137,7 +137,7 @@ export function UsbInfoSetting() {
137137
);
138138

139139
useEffect(() => {
140-
send("getDeviceID", {}, async resp => {
140+
send("getDeviceID", {}, async (resp: JsonRpcResponse) => {
141141
if ("error" in resp) {
142142
return notifications.error(
143143
`Failed to get device ID: ${resp.error.data || "Unknown error"}`,
@@ -205,10 +205,10 @@ function USBConfigDialog({
205205
product: "",
206206
});
207207

208-
const [send] = useJsonRpc();
208+
const { send } = useJsonRpc();
209209

210210
const syncUsbConfig = useCallback(() => {
211-
send("getUsbConfig", {}, resp => {
211+
send("getUsbConfig", {}, (resp: JsonRpcResponse) => {
212212
if ("error" in resp) {
213213
console.error("Failed to load USB Config:", resp.error);
214214
} else {

ui/src/components/WebRTCVideo.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export default function WebRTCVideo() {
7474
const [blockWheelEvent, setBlockWheelEvent] = useState(false);
7575

7676
// Misc states and hooks
77-
const [send] = useJsonRpc();
77+
const { send } = useJsonRpc();
7878

7979
// Video-related
8080
useResizeObserver({

ui/src/components/extensions/ATXPowerControl.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { SettingsPageHeader } from "@components/SettingsPageheader";
77
import notifications from "@/notifications";
88
import LoadingSpinner from "@/components/LoadingSpinner";
99

10-
import { useJsonRpc } from "../../hooks/useJsonRpc";
10+
import { JsonRpcResponse, useJsonRpc } from "../../hooks/useJsonRpc";
1111

1212
const LONG_PRESS_DURATION = 3000; // 3 seconds for long press
1313

@@ -23,15 +23,15 @@ export function ATXPowerControl() {
2323
> | null>(null);
2424
const [atxState, setAtxState] = useState<ATXState | null>(null);
2525

26-
const [send] = useJsonRpc(function onRequest(resp) {
26+
const { send } = useJsonRpc(function onRequest(resp) {
2727
if (resp.method === "atxState") {
2828
setAtxState(resp.params as ATXState);
2929
}
3030
});
3131

3232
// Request initial state
3333
useEffect(() => {
34-
send("getATXState", {}, resp => {
34+
send("getATXState", {}, (resp: JsonRpcResponse) => {
3535
if ("error" in resp) {
3636
notifications.error(
3737
`Failed to get ATX state: ${resp.error.data || "Unknown error"}`,
@@ -54,7 +54,7 @@ export function ATXPowerControl() {
5454
const timer = setTimeout(() => {
5555
// Send long press action
5656
console.log("Sending long press ATX power action");
57-
send("setATXPowerAction", { action: "power-long" }, resp => {
57+
send("setATXPowerAction", { action: "power-long" }, (resp: JsonRpcResponse) => {
5858
if ("error" in resp) {
5959
notifications.error(
6060
`Failed to send ATX power action: ${resp.error.data || "Unknown error"}`,
@@ -75,7 +75,7 @@ export function ATXPowerControl() {
7575

7676
// Send short press action
7777
console.log("Sending short press ATX power action");
78-
send("setATXPowerAction", { action: "power-short" }, resp => {
78+
send("setATXPowerAction", { action: "power-short" }, (resp: JsonRpcResponse) => {
7979
if ("error" in resp) {
8080
notifications.error(
8181
`Failed to send ATX power action: ${resp.error.data || "Unknown error"}`,
@@ -127,7 +127,7 @@ export function ATXPowerControl() {
127127
LeadingIcon={LuRotateCcw}
128128
text="Reset"
129129
onClick={() => {
130-
send("setATXPowerAction", { action: "reset" }, resp => {
130+
send("setATXPowerAction", { action: "reset" }, (resp: JsonRpcResponse) => {
131131
if ("error" in resp) {
132132
notifications.error(
133133
`Failed to send ATX power action: ${resp.error.data || "Unknown error"}`,

ui/src/components/extensions/DCPowerControl.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { useCallback, useEffect, useState } from "react";
44
import { Button } from "@components/Button";
55
import Card from "@components/Card";
66
import { SettingsPageHeader } from "@components/SettingsPageheader";
7-
import { useJsonRpc } from "@/hooks/useJsonRpc";
7+
import { JsonRpcResponse, useJsonRpc } from "@/hooks/useJsonRpc";
88
import notifications from "@/notifications";
99
import FieldLabel from "@components/FieldLabel";
1010
import LoadingSpinner from "@components/LoadingSpinner";
@@ -19,11 +19,11 @@ interface DCPowerState {
1919
}
2020

2121
export function DCPowerControl() {
22-
const [send] = useJsonRpc();
22+
const { send } = useJsonRpc();
2323
const [powerState, setPowerState] = useState<DCPowerState | null>(null);
2424

2525
const getDCPowerState = useCallback(() => {
26-
send("getDCPowerState", {}, resp => {
26+
send("getDCPowerState", {}, (resp: JsonRpcResponse) => {
2727
if ("error" in resp) {
2828
notifications.error(
2929
`Failed to get DC power state: ${resp.error.data || "Unknown error"}`,
@@ -35,7 +35,7 @@ export function DCPowerControl() {
3535
}, [send]);
3636

3737
const handlePowerToggle = (enabled: boolean) => {
38-
send("setDCPowerState", { enabled }, resp => {
38+
send("setDCPowerState", { enabled }, (resp: JsonRpcResponse) => {
3939
if ("error" in resp) {
4040
notifications.error(
4141
`Failed to set DC power state: ${resp.error.data || "Unknown error"}`,
@@ -47,7 +47,7 @@ export function DCPowerControl() {
4747
};
4848
const handleRestoreChange = (state: number) => {
4949
// const state = powerState?.restoreState === 0 ? 1 : powerState?.restoreState === 1 ? 2 : 0;
50-
send("setDCRestoreState", { state }, resp => {
50+
send("setDCRestoreState", { state }, (resp: JsonRpcResponse) => {
5151
if ("error" in resp) {
5252
notifications.error(
5353
`Failed to set DC power state: ${resp.error.data || "Unknown error"}`,

ui/src/components/extensions/SerialConsole.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { useEffect, useState } from "react";
44
import { Button } from "@components/Button";
55
import Card from "@components/Card";
66
import { SettingsPageHeader } from "@components/SettingsPageheader";
7-
import { useJsonRpc } from "@/hooks/useJsonRpc";
7+
import { JsonRpcResponse, useJsonRpc } from "@/hooks/useJsonRpc";
88
import notifications from "@/notifications";
99
import { useUiStore } from "@/hooks/stores";
1010
import { SelectMenuBasic } from "@components/SelectMenuBasic";
@@ -17,7 +17,7 @@ interface SerialSettings {
1717
}
1818

1919
export function SerialConsole() {
20-
const [send] = useJsonRpc();
20+
const { send } = useJsonRpc();
2121
const [settings, setSettings] = useState<SerialSettings>({
2222
baudRate: "9600",
2323
dataBits: "8",
@@ -26,7 +26,7 @@ export function SerialConsole() {
2626
});
2727

2828
useEffect(() => {
29-
send("getSerialSettings", {}, resp => {
29+
send("getSerialSettings", {}, (resp: JsonRpcResponse) => {
3030
if ("error" in resp) {
3131
notifications.error(
3232
`Failed to get serial settings: ${resp.error.data || "Unknown error"}`,
@@ -39,7 +39,7 @@ export function SerialConsole() {
3939

4040
const handleSettingChange = (setting: keyof SerialSettings, value: string) => {
4141
const newSettings = { ...settings, [setting]: value };
42-
send("setSerialSettings", { settings: newSettings }, resp => {
42+
send("setSerialSettings", { settings: newSettings }, (resp: JsonRpcResponse) => {
4343
if ("error" in resp) {
4444
notifications.error(
4545
`Failed to update serial settings: ${resp.error.data || "Unknown error"}`,

ui/src/components/popovers/ExtensionPopover.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useEffect, useState } from "react";
22
import { LuPower, LuTerminal, LuPlugZap } from "react-icons/lu";
33

4-
import { useJsonRpc } from "@/hooks/useJsonRpc";
4+
import { JsonRpcResponse, useJsonRpc } from "@/hooks/useJsonRpc";
55
import Card, { GridCard } from "@components/Card";
66
import { SettingsPageHeader } from "@components/SettingsPageheader";
77
import { ATXPowerControl } from "@components/extensions/ATXPowerControl";
@@ -39,12 +39,12 @@ const AVAILABLE_EXTENSIONS: Extension[] = [
3939
];
4040

4141
export default function ExtensionPopover() {
42-
const [send] = useJsonRpc();
42+
const { send } = useJsonRpc();
4343
const [activeExtension, setActiveExtension] = useState<Extension | null>(null);
4444

4545
// Load active extension on component mount
4646
useEffect(() => {
47-
send("getActiveExtension", {}, resp => {
47+
send("getActiveExtension", {}, (resp: JsonRpcResponse) => {
4848
if ("error" in resp) return;
4949
const extensionId = resp.result as string;
5050
if (extensionId) {
@@ -57,7 +57,7 @@ export default function ExtensionPopover() {
5757
}, [send]);
5858

5959
const handleSetActiveExtension = (extension: Extension | null) => {
60-
send("setActiveExtension", { extensionId: extension?.id || "" }, resp => {
60+
send("setActiveExtension", { extensionId: extension?.id || "" }, (resp: JsonRpcResponse) => {
6161
if ("error" in resp) {
6262
notifications.error(
6363
`Failed to set active extension: ${resp.error.data || "Unknown error"}`,

ui/src/components/popovers/MountPopover.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ import Card, { GridCard } from "@components/Card";
1616
import { formatters } from "@/utils";
1717
import { RemoteVirtualMediaState, useMountMediaStore, useRTCStore } from "@/hooks/stores";
1818
import { SettingsPageHeader } from "@components/SettingsPageheader";
19-
import { useJsonRpc } from "@/hooks/useJsonRpc";
19+
import { JsonRpcResponse, useJsonRpc } from "@/hooks/useJsonRpc";
2020
import { useDeviceUiNavigation } from "@/hooks/useAppNavigation";
2121
import notifications from "@/notifications";
2222

2323
const MountPopopover = forwardRef<HTMLDivElement, object>((_props, ref) => {
2424
const diskDataChannelStats = useRTCStore(state => state.diskDataChannelStats);
25-
const [send] = useJsonRpc();
25+
const { send } = useJsonRpc();
2626
const { remoteVirtualMediaState, setModalView, setRemoteVirtualMediaState } =
2727
useMountMediaStore();
2828

@@ -47,7 +47,7 @@ const MountPopopover = forwardRef<HTMLDivElement, object>((_props, ref) => {
4747
}, [diskDataChannelStats]);
4848

4949
const syncRemoteVirtualMediaState = useCallback(() => {
50-
send("getVirtualMediaState", {}, response => {
50+
send("getVirtualMediaState", {}, (response: JsonRpcResponse) => {
5151
if ("error" in response) {
5252
notifications.error(
5353
`Failed to get virtual media state: ${response.error.message}`,
@@ -59,7 +59,7 @@ const MountPopopover = forwardRef<HTMLDivElement, object>((_props, ref) => {
5959
}, [send, setRemoteVirtualMediaState]);
6060

6161
const handleUnmount = () => {
62-
send("unmountImage", {}, response => {
62+
send("unmountImage", {}, (response: JsonRpcResponse) => {
6363
if ("error" in response) {
6464
notifications.error(`Failed to unmount image: ${response.error.message}`);
6565
} else {

0 commit comments

Comments
 (0)