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 {
2626 return found ;
2727 }
2828
29- public RequestDevice = ( options : USBRequestDeviceOptions ) : Promise < USBDeviceFound > => {
29+ public RequestDevice = async ( options : USBRequestDeviceOptions ) : Promise < USBDeviceFound > => {
3030 function isEmpty ( obj ) {
3131 for ( var prop in obj ) {
3232 if ( Object . prototype . hasOwnProperty . call ( obj , prop ) ) {
@@ -59,15 +59,10 @@ export class USBManager {
5959 reqOptions = { filters : [ ] } ;
6060 }
6161
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 ;
7166 }
7267
7368 public OpenDevice = ( device : USBDeviceFound ) : Promise < USBDeviceFound > => {
Original file line number Diff line number Diff line change @@ -34,12 +34,18 @@ protected override Task OnAfterRenderAsync()
3434 return Task . CompletedTask ;
3535 }
3636
37- protected async Task Run ( )
37+ private async Task < USBDevice > GetDevice ( )
3838 {
3939 USBDevice device = await this . _usb . RequestDevice ( new USBDeviceRequestOptions
4040 {
4141 Filters = _filters
4242 } ) ;
43+ return device ;
44+ }
45+
46+ protected async Task Run ( )
47+ {
48+ USBDevice device = await this . GetDevice ( ) ;
4349
4450 if ( device != null )
4551 {
You can’t perform that action at this time.
0 commit comments