Commit 3febb2c 1 parent adcf850 commit 3febb2c Copy full SHA for 3febb2c
File tree 1 file changed +7
-0
lines changed
1 file changed +7
-0
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ const int USB_CLASS_CODE_VENDOR_SPECIFIC = 0xFF;
23
23
@JS ('navigator.usb' )
24
24
extension type _USB ._(JSObject _) implements JSObject {
25
25
external static JSObject requestDevice (_USBDeviceRequestOptions options);
26
+ external static set ondisconnect (JSFunction value);
26
27
}
27
28
28
29
@JS ()
@@ -60,6 +61,11 @@ class WebUSB {
60
61
return _device != null && getProperty (_device, 'opened' );
61
62
}
62
63
64
+ static void _onDisconnect () {
65
+ _device = null ;
66
+ log.info ('device is disconnected from WebUSB API' );
67
+ }
68
+
63
69
static const USB_PROBE_MAGIC = '_NFC_IM_' ;
64
70
65
71
/// Try to poll a WebUSB device according to our protocol.
@@ -76,6 +82,7 @@ class WebUSB {
76
82
promiseToFuture (callMethod (device, 'claimInterface' , [1 ])))
77
83
.timeout (Duration (milliseconds: timeout));
78
84
_device = device;
85
+ _USB .ondisconnect = _onDisconnect.toJS;
79
86
log.info ("WebUSB device opened" , _device);
80
87
} on TimeoutException catch (_) {
81
88
log.severe ("Polling tag timeout" );
You can’t perform that action at this time.
0 commit comments