@@ -178,14 +178,19 @@ export class DeviceList extends TypedEmitter<DeviceListEvents> {
178
178
*/
179
179
this . transport . on ( TRANSPORT . UPDATE , diff => {
180
180
diff . connected . forEach ( async descriptor => {
181
+ // creatingDevicesDescriptors is needed, so that if *during* creating of Device,
182
+ // other application acquires the device and changes the descriptor,
183
+ // the new unacquired device has correct descriptor
181
184
const path = descriptor . path . toString ( ) ;
185
+ this . creatingDevicesDescriptors [ path ] = descriptor ;
186
+
182
187
const priority = DataManager . getSettings ( 'priority' ) ;
183
188
const penalty = this . getAuthPenalty ( ) ;
184
189
185
190
if ( priority || penalty ) {
186
191
await resolveAfter ( 501 + penalty + 100 * priority , null ) . promise ;
187
192
}
188
- if ( descriptor . session == null ) {
193
+ if ( this . creatingDevicesDescriptors [ path ] . session == null ) {
189
194
await this . _createAndSaveDevice ( descriptor ) ;
190
195
} else {
191
196
const device = this . _createUnacquiredDevice ( descriptor ) ;
@@ -217,7 +222,7 @@ export class DeviceList extends TypedEmitter<DeviceListEvents> {
217
222
diff . releasedElsewhere . forEach ( async descriptor => {
218
223
const path = descriptor . path . toString ( ) ;
219
224
const device = this . devices [ path ] ;
220
- await resolveAfter ( 1000 , null ) . promise ;
225
+ await resolveAfter ( 2000 , null ) . promise ;
221
226
222
227
if ( device ) {
223
228
// after device was released in another window wait for a while (the other window might
@@ -269,6 +274,7 @@ export class DeviceList extends TypedEmitter<DeviceListEvents> {
269
274
// whenever descriptors change we need to update them so that we can use them
270
275
// in subsequent transport.acquire calls
271
276
diff . descriptors . forEach ( d => {
277
+ this . creatingDevicesDescriptors [ d . path ] = d ;
272
278
if ( this . devices [ d . path ] ) {
273
279
this . devices [ d . path ] . originalDescriptor = {
274
280
session : d . session ,
@@ -455,12 +461,7 @@ export class DeviceList extends TypedEmitter<DeviceListEvents> {
455
461
456
462
// main logic
457
463
private async handle ( descriptor : Descriptor ) {
458
- // creatingDevicesDescriptors is needed, so that if *during* creating of Device,
459
- // other application acquires the device and changes the descriptor,
460
- // the new unacquired device has correct descriptor
461
464
const path = descriptor . path . toString ( ) ;
462
- this . creatingDevicesDescriptors [ path ] = descriptor ;
463
-
464
465
try {
465
466
// "regular" device creation
466
467
await this . _takeAndCreateDevice ( descriptor ) ;
@@ -491,18 +492,21 @@ export class DeviceList extends TypedEmitter<DeviceListEvents> {
491
492
// or possibly there are 2 applications without common sessions background
492
493
error . message === TRANSPORT_ERROR . INTERFACE_UNABLE_TO_OPEN_DEVICE ||
493
494
// catch one of trezord LIBUSB_ERRORs
494
- error . message ?. indexOf ( ERRORS . LIBUSB_ERROR_MESSAGE ) >= 0 ||
495
+ error . message ?. indexOf ( ERRORS . LIBUSB_ERROR_MESSAGE ) >= 0
495
496
// we tried to initialize device (either automatically after enumeration or after user click)
496
497
// but it did not work out. this device is effectively unreadable and user should do something about it
497
- error . code === 'Device_InitializeFailed'
498
+ // error.code === 'Device_InitializeFailed'
498
499
) {
499
500
const device = this . _createUnreadableDevice (
500
501
this . creatingDevicesDescriptors [ path ] ,
501
502
error . message ,
502
503
) ;
503
504
this . devices [ path ] = device ;
504
505
this . emit ( DEVICE . CONNECT_UNACQUIRED , device . toMessageObject ( ) ) ;
505
- } else if ( error . code === 'Device_UsedElsewhere' ) {
506
+ } else if (
507
+ error . code === 'Device_UsedElsewhere' ||
508
+ error . message === TRANSPORT_ERROR . SESSION_NOT_FOUND
509
+ ) {
506
510
// most common error - someone else took the device at the same time
507
511
this . _handleUsedElsewhere ( descriptor ) ;
508
512
} else {
0 commit comments