From 787c02cd502d40146e3577283865f5caa75fd2ea Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Tue, 21 Nov 2023 19:28:07 +0100 Subject: [PATCH] Update hub.go --- accounts/usbwallet/hub.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/accounts/usbwallet/hub.go b/accounts/usbwallet/hub.go index 2845d738a8..68167c0fcc 100644 --- a/accounts/usbwallet/hub.go +++ b/accounts/usbwallet/hub.go @@ -185,12 +185,8 @@ func (hub *Hub) refreshWallets() { hub.enumFails.Store(0) for _, info := range infos { - for _, id := range hub.productIDs { - // Windows and Macos use UsageID matching, Linux uses Interface matching - if info.ProductID == id && info.Path != "" && (slices.Contains(hub.usageIDs, info.UsagePage) || info.Interface == hub.endpointID) { - devices = append(devices, info) - break - } + if hub.matchDevice(info) { + devices = append(devices, info) } } if runtime.GOOS == "linux" { @@ -249,6 +245,13 @@ func (hub *Hub) refreshWallets() { } } +func (hub *Hub) matchDevice(info usb.DeviceInfo) bool { + // Windows and Macos use UsageID matching, Linux uses Interface matching + return slices.Contains(hub.productIDs, info.ProductID) && + info.Path != "" && + (slices.Contains(hub.usageIDs, info.UsagePage) || info.Interface == hub.endpointID) +} + // Subscribe implements accounts.Backend, creating an async subscription to // receive notifications on the addition or removal of USB wallets. func (hub *Hub) Subscribe(sink chan<- accounts.WalletEvent) event.Subscription {