File tree Expand file tree Collapse file tree 2 files changed +12
-11
lines changed
src/Blazor.Extensions.WebUSB.JS/src
test/Blazor.Extensions.WebUSB.Test/Pages Expand file tree Collapse file tree 2 files changed +12
-11
lines changed Original file line number Diff line number Diff line change @@ -26,7 +26,7 @@ export class USBManager {
26
26
return found ;
27
27
}
28
28
29
- public RequestDevice = ( options : USBRequestDeviceOptions ) : Promise < USBDeviceFound > => {
29
+ public RequestDevice = async ( options : USBRequestDeviceOptions ) : Promise < USBDeviceFound > => {
30
30
function isEmpty ( obj ) {
31
31
for ( var prop in obj ) {
32
32
if ( Object . prototype . hasOwnProperty . call ( obj , prop ) ) {
@@ -59,15 +59,10 @@ export class USBManager {
59
59
reqOptions = { filters : [ ] } ;
60
60
}
61
61
62
- return new Promise ( ( resolve , reject ) => {
63
- this . usb . requestDevice ( reqOptions )
64
- . then ( d => {
65
- let usbDevice = ParseUSBDevice ( d ) ;
66
- this . _foundDevices . push ( d ) ;
67
- resolve ( usbDevice ) ;
68
- } )
69
- . catch ( err => reject ( err ) ) ;
70
- } ) ;
62
+ let authorizedDevice = await this . usb . requestDevice ( reqOptions ) ;
63
+ let usbDevice = ParseUSBDevice ( authorizedDevice ) ;
64
+ this . _foundDevices . push ( authorizedDevice ) ;
65
+ return usbDevice ;
71
66
}
72
67
73
68
public OpenDevice = ( device : USBDeviceFound ) : Promise < USBDeviceFound > => {
Original file line number Diff line number Diff line change @@ -34,12 +34,18 @@ protected override Task OnAfterRenderAsync()
34
34
return Task . CompletedTask ;
35
35
}
36
36
37
- protected async Task Run ( )
37
+ private async Task < USBDevice > GetDevice ( )
38
38
{
39
39
USBDevice device = await this . _usb . RequestDevice ( new USBDeviceRequestOptions
40
40
{
41
41
Filters = _filters
42
42
} ) ;
43
+ return device ;
44
+ }
45
+
46
+ protected async Task Run ( )
47
+ {
48
+ USBDevice device = await this . GetDevice ( ) ;
43
49
44
50
if ( device != null )
45
51
{
You can’t perform that action at this time.
0 commit comments