File tree Expand file tree Collapse file tree 1 file changed +7
-0
lines changed
Expand file tree Collapse file tree 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;
2323@JS ('navigator.usb' )
2424extension type _USB ._(JSObject _) implements JSObject {
2525 external static JSObject requestDevice (_USBDeviceRequestOptions options);
26+ external static set ondisconnect (JSFunction value);
2627}
2728
2829@JS ()
@@ -60,6 +61,11 @@ class WebUSB {
6061 return _device != null && getProperty (_device, 'opened' );
6162 }
6263
64+ static void _onDisconnect () {
65+ _device = null ;
66+ log.info ('device is disconnected from WebUSB API' );
67+ }
68+
6369 static const USB_PROBE_MAGIC = '_NFC_IM_' ;
6470
6571 /// Try to poll a WebUSB device according to our protocol.
@@ -76,6 +82,7 @@ class WebUSB {
7682 promiseToFuture (callMethod (device, 'claimInterface' , [1 ])))
7783 .timeout (Duration (milliseconds: timeout));
7884 _device = device;
85+ _USB .ondisconnect = _onDisconnect.toJS;
7986 log.info ("WebUSB device opened" , _device);
8087 } on TimeoutException catch (_) {
8188 log.severe ("Polling tag timeout" );
You can’t perform that action at this time.
0 commit comments