Skip to content

Commit

Permalink
Fix port being permanently open
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielBaulig committed Feb 16, 2024
1 parent f30d5dc commit af52499
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions src/ui/components/SerialConnectionCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,21 @@ export default function SerialConnectionCard({port, onRemove, open}) {
const { name } = improvState;

useEffect(() => {
if (!port.opened) {
port.open({baudRate: useImprovSerial.baudRate});
}
return () => improv.close();
(async () => {
if (!port.opened && !open) {
// If the port isn't open yet and the card won't render
// opened anyway briefly open the port to read vendorId
// and productId
await port.open({baudRate: useImprovSerial.baudRate})
await port.close();
}
})();
return async () => {
await improv.close();
if (port.opened) {
await port.close();
}
};
}, [port]);

const title = name || (vendorId && productId && `usb-${vendorId}-${productId}`) || 'unidentified serial device';
Expand All @@ -104,7 +115,12 @@ export default function SerialConnectionCard({port, onRemove, open}) {
glyph={<Icon size={0.8} path={mdiUsb} />}
menu={menu}
onBeginOpening={() => improv.initialize()}
onDoneClosing={() => improv.close()}
onDoneClosing={async () => {
await improv.close();
if (port.opened) {
await port.close();
}
}}
>
<Improv {...improvState} improv={improv} />
</DrawerCard>;
Expand Down

0 comments on commit af52499

Please sign in to comment.