2023-04-05 13:42:20 +00:00
|
|
|
async function testIt () {
|
2021-09-23 11:00:11 +00:00
|
|
|
const device = await navigator.bluetooth.requestDevice({
|
|
|
|
acceptAllDevices: true
|
|
|
|
})
|
|
|
|
document.getElementById('device-name').innerHTML = device.name || `ID: ${device.id}`
|
|
|
|
}
|
|
|
|
|
2023-04-05 13:42:20 +00:00
|
|
|
document.getElementById('clickme').addEventListener('click', testIt)
|
2022-09-26 14:19:58 +00:00
|
|
|
|
2023-04-24 14:35:14 +00:00
|
|
|
function cancelRequest () {
|
2023-03-27 13:31:15 +00:00
|
|
|
window.electronAPI.cancelBluetoothRequest()
|
|
|
|
}
|
|
|
|
|
|
|
|
document.getElementById('cancel').addEventListener('click', cancelRequest)
|
|
|
|
|
2022-09-26 14:19:58 +00:00
|
|
|
window.electronAPI.bluetoothPairingRequest((event, details) => {
|
|
|
|
const response = {}
|
2023-02-01 11:59:16 +00:00
|
|
|
|
2022-09-26 14:19:58 +00:00
|
|
|
switch (details.pairingKind) {
|
|
|
|
case 'confirm': {
|
2023-04-24 14:35:14 +00:00
|
|
|
response.confirmed = window.confirm(`Do you want to connect to device ${details.deviceId}?`)
|
2022-09-26 14:19:58 +00:00
|
|
|
break
|
|
|
|
}
|
|
|
|
case 'confirmPin': {
|
2023-04-24 14:35:14 +00:00
|
|
|
response.confirmed = window.confirm(`Does the pin ${details.pin} match the pin displayed on device ${details.deviceId}?`)
|
2022-09-26 14:19:58 +00:00
|
|
|
break
|
|
|
|
}
|
|
|
|
case 'providePin': {
|
2023-04-24 14:35:14 +00:00
|
|
|
const pin = window.prompt(`Please provide a pin for ${details.deviceId}.`)
|
2022-09-26 14:19:58 +00:00
|
|
|
if (pin) {
|
|
|
|
response.pin = pin
|
|
|
|
response.confirmed = true
|
|
|
|
} else {
|
|
|
|
response.confirmed = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
window.electronAPI.bluetoothPairingResponse(response)
|
2023-04-05 13:42:20 +00:00
|
|
|
})
|