Skip to content

Commit

Permalink
Attempt cache of bluetooth device selection
Browse files Browse the repository at this point in the history
  • Loading branch information
garrettmflynn committed Jun 23, 2024
1 parent f76b6bd commit 61f19f9
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions packages/plugins/devices/ble/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@ export const desktop = {

// Enable Web Bluetooth
let selectBluetoothCallback;
let toSelectNext;

this.on(`select`, (
_evt, //: IpcMainEvent,
value //: string
) => {
if (typeof selectBluetoothCallback === 'function') selectBluetoothCallback(value)
if (typeof selectBluetoothCallback === 'function') selectBluetoothCallback(value) // Select the device
else toSelectNext = value // Save the device to select later
selectBluetoothCallback = null
});

Expand All @@ -48,11 +50,16 @@ export const desktop = {
win.webContents.on('select-bluetooth-device', (event, devices, callback) => {

event.preventDefault()

// If a device was saved to select later, select it now
if (toSelectNext) {
callback(toSelectNext)
toSelectNext = null
return
}

if (!selectBluetoothCallback) this.send(`open`, devices); // Initial request always starts at zero

this.send(`update`, devices);

selectBluetoothCallback = callback

})
Expand Down

0 comments on commit 61f19f9

Please sign in to comment.