diff --git a/src/HaritoraX.ts b/src/HaritoraX.ts index 40961a1..b51f861 100644 --- a/src/HaritoraX.ts +++ b/src/HaritoraX.ts @@ -773,7 +773,7 @@ export default class HaritoraX extends EventEmitter { async getAvailableDevices(): Promise { let availableDevices: string[] = []; - let com = new COM("wireless"); + let com = new COM("wireless"); // variable doesn't matter, just need to initialize it to get the available devices let bluetooth = new Bluetooth(); if (await com.isDeviceAvailable()) { diff --git a/src/mode/bluetooth.ts b/src/mode/bluetooth.ts index da0394f..de92baa 100644 --- a/src/mode/bluetooth.ts +++ b/src/mode/bluetooth.ts @@ -73,18 +73,20 @@ export default class Bluetooth extends EventEmitter { } }); - if (noble._state === "poweredOn" && !found) { - noble.startScanning([], true); - - setTimeout(() => { - if (!found) { - noble.stopScanning(); - resolve(false); - } - }, 3000); - } else if (noble._state !== "poweredOn") { - resolve(false); - } + noble.on("stateChange", (state) => { + if (state === "poweredOn" && !found) { + noble.startScanning([], true); + + setTimeout(() => { + if (!found) { + noble.stopScanning(); + resolve(false); + } + }, 3000); + } else if (noble._state !== "poweredOn") { + resolve(false); + } + }); }); }