From 78b0f5b4a09e1c44028bef758a698cf95e50c65b Mon Sep 17 00:00:00 2001 From: Alejandro Parcet Date: Tue, 11 Jul 2023 14:50:40 +0200 Subject: [PATCH] fix: using usb event close to send a focus.close to the port handler This should solve the unexpected disconnections and clean the memory when needed the most --- src/main/setup/configureUSB.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/setup/configureUSB.ts b/src/main/setup/configureUSB.ts index 49eb5a260..fa635b0fe 100644 --- a/src/main/setup/configureUSB.ts +++ b/src/main/setup/configureUSB.ts @@ -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]; @@ -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; @@ -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(); } } };