Skip to content

Commit

Permalink
chore(useBluetoothAPI): applied suggested lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
michealroberts committed Jun 5, 2022
1 parent 2983c89 commit c0e0f3a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
23 changes: 12 additions & 11 deletions packages/core/useBluetooth/index.md
Expand Up @@ -19,14 +19,14 @@ N.B. This API is not available in Web Workers (not exposed via WorkerNavigator).
```ts
import { useBluetooth } from '@vueuse/core'

const {
const {
isSupported,
isConnected,
device,
requestDevice,
server
server,
} = useBluetooth({
acceptAllDevices: true
acceptAllDevices: true,
})
```

Expand All @@ -49,32 +49,32 @@ Here, we use the characteristicvaluechanged event listener to handle reading bat
```ts
import { pausableWatch, useBluetooth } from '@vueuse/core'

const {
const {
isSupported,
isConnected,
device,
requestDevice,
server
server,
} = useBluetooth({
acceptAllDevices: true,
optionalServices: [
"battery_service"
]
'battery_service',
],
})

const batteryPercent = ref<undefined | number>()

const isGettingBatteryLevels = ref(false)

const getBatteryLevels = async () => {
const getBatteryLevels = async() => {
isGettingBatteryLevels.value = true

// Get the battery service:
const batteryService = await server.getPrimaryService("battery_service")
const batteryService = await server.getPrimaryService('battery_service')

// Get the current battery level
const batteryLevelCharacteristic = await batteryService.getCharacteristic(
"battery_level"
'battery_level',
)

// Listen to when characteristic value changes on `characteristicvaluechanged` event:
Expand All @@ -89,7 +89,8 @@ const getBatteryLevels = async () => {
}

const { stop } = pausableWatch(isConnected, (newIsConnected) => {
if (!newIsConnected || !server.value || isGettingBatteryLevels.value) return
if (!newIsConnected || !server.value || isGettingBatteryLevels.value)
return
// Attempt to get the battery levels of the device:
getBatteryLevels()
// We only want to run this on the initial connection, as we will use a event listener to handle updates:
Expand Down
3 changes: 2 additions & 1 deletion packages/core/useBluetooth/index.ts
Expand Up @@ -63,7 +63,8 @@ export function useBluetooth(options?: UseBluetoothOptions) {

async function requestDevice(): Promise<void> {
// This is the function can only be called if Bluetooth API is supported:
if (!isSupported) return
if (!isSupported)
return

// Reset any errors we currently have:
error.value = null
Expand Down

0 comments on commit c0e0f3a

Please sign in to comment.