Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/api/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,14 @@ export const requestAutoConnectPort = async () => {
export const getAllBluetooth = async () => {
const response = (await invoke("get_all_bluetooth", {
request: {},
})) as { candidates: string[] };

return response.candidates;
})) as { candidates: Array<{ 0: string }> | string[] };

// Handle both formats: newtype struct { 0: string } and plain strings
return Array.isArray(response.candidates)
? response.candidates.map((candidate: any) =>
typeof candidate === "string" ? candidate : candidate[0],
)
: [];
};

export const getAllSerialPorts = async () => {
Expand Down
14 changes: 10 additions & 4 deletions src/features/device/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,17 @@ export const useDeviceApi = () => {
const TYPE = DeviceApiActions.GetAvailableBluetoothDevices;

await trackRequestOperation(TYPE, dispatch, async () => {
const bluetoothDevices = await backendConnectionApi.getAllBluetooth();
try {
const bluetoothDevices = await backendConnectionApi.getAllBluetooth();

dispatch(
deviceSliceActions.setAvailableBluetoothDevices(bluetoothDevices),
);
dispatch(
deviceSliceActions.setAvailableBluetoothDevices(bluetoothDevices),
);
} catch (e) {
// Handle BLE scanning errors gracefully
console.error("Failed to scan for Bluetooth devices:", e);
dispatch(deviceSliceActions.setAvailableBluetoothDevices([]));
}
});
};

Expand Down
4 changes: 4 additions & 0 deletions src/features/device/slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ export const deviceSlice = createSlice({
setAutoConnectPort: (state, action: PayloadAction<string | null>) => {
state.autoConnectPort = action.payload;
},

setAutoConnectBluetooth: (state, action: PayloadAction<string | null>) => {
state.autoConnectBluetooth = action.payload;
},
},
});

Expand Down