Skip to content

Commit

Permalink
fix: using usb event close to send a focus.close to the port handler
Browse files Browse the repository at this point in the history
This should solve the unexpected disconnections and clean the memory when needed the most
  • Loading branch information
AlexDygma committed Jul 11, 2023
1 parent fe35480 commit 78b0f5b
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/main/setup/configureUSB.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import { ipcMain } from "electron";
import { getDeviceList, WebUSB } from "usb";
import sendToRenderer from "../utils/sendToRenderer";
import Focus from "../../api/focus";

const dygmaVendorIDs = [0x35ef, 0x1209];

Expand All @@ -27,7 +28,7 @@ const webusb = new WebUSB({

type USBEvent = Event & { device: unknown };

export const onUSBDisconnect = (event: USBEvent) => {
export const onUSBDisconnect = async (event: USBEvent) => {
const { device } = event;
if (device) {
const vendorID = (device as any).vendorId;
Expand All @@ -37,6 +38,8 @@ export const onUSBDisconnect = (event: USBEvent) => {
console.log("VendorID", vendorID);
console.log("ProductID", productID);
sendToRenderer("usb-disconnected", vendorID, productID);
const focus = new Focus();
await focus.close();
}
}
};
Expand Down

0 comments on commit 78b0f5b

Please # to comment.