Skip to content

Commit

Permalink
chore: improve availability checker
Browse files Browse the repository at this point in the history
  • Loading branch information
septs committed Oct 24, 2024
1 parent 56b7ad7 commit 778fd35
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/backends/WebBLEBackend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ export class WebBLEBackend implements EventListenerObject, Backend {
}

static async getAvailability(bluetooth = navigator.bluetooth) {
if (!bluetooth) return false
if (!('getAvailability' in bluetooth)) return false
if (bluetooth === undefined || bluetooth === null) return false
if (typeof bluetooth.requestDevice !== 'function') return false
if (typeof bluetooth.getAvailability !== 'function') return true
return bluetooth.getAvailability()
}

Expand Down
4 changes: 3 additions & 1 deletion src/backends/WebUSBBackend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ export class WebUSBBackend implements Backend {
}

static async getAvailability(usb = navigator.usb) {
return usb !== undefined
if (usb === undefined || usb === null) return false
if (typeof usb.requestDevice !== 'function') return false
return true
}

static async open(device: USBDevice, options?: WebUSBBackend.Options): Promise<WebUSBBackend> {
Expand Down

0 comments on commit 778fd35

Please sign in to comment.