Skip to content

Commit

Permalink
don't auto-select any devices at page boot
Browse files Browse the repository at this point in the history
  • Loading branch information
noahm committed Apr 16, 2024
1 parent c7e9652 commit e4dd4fc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
8 changes: 5 additions & 3 deletions ui/pad-coms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ export async function promptSelectDevice() {
return;
}

await open_smx_device(devices[0]);
await open_smx_device(devices[0], true);
}

export async function open_smx_device(dev: HIDDevice) {
export async function open_smx_device(dev: HIDDevice, autoSelect = false) {
if (!dev.opened) {
await dev.open();
}
Expand All @@ -34,11 +34,13 @@ export async function open_smx_device(dev: HIDDevice) {
[serial]: stage, // TODO: Is there a better way to handle this?
};
});
uiState.set(selectedStageSerial$, serial);
uiState.set(
nextStatusTextLine$,
`status: device opened: ${dev.productName}:P${stage.info?.player}:${stage.info?.serial}`,
);
if (autoSelect) {
uiState.set(selectedStageSerial$, serial);
}
}

/**
Expand Down
6 changes: 5 additions & 1 deletion ui/ui.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
import { StageTest } from "./stage/stage-test.tsx";
import { TypedSelect } from "./common/typed-select.tsx";

export function UI() {
function usePreviouslyPairedDevices() {
useEffect(() => {
// once, on load, get paired devices and attempt connection
if (browserSupported) {
Expand All @@ -27,6 +27,10 @@ export function UI() {
);
}
}, []);
}

export function UI() {
usePreviouslyPairedDevices();

return (
<>
Expand Down

0 comments on commit e4dd4fc

Please sign in to comment.