Update hub.go

This commit is contained in:
Felix Lange 2023-11-21 19:28:07 +01:00 committed by GitHub
parent c2b80fb781
commit 787c02cd50
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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 {