Skip to content

Commit

Permalink
Fix bluetooth isDeviceAvailable()
Browse files Browse the repository at this point in the history
  • Loading branch information
JovannMC committed Jul 24, 2024
1 parent a594093 commit c36b5be
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/HaritoraX.ts
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ export default class HaritoraX extends EventEmitter {
async getAvailableDevices(): Promise<string[]> {
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()) {
Expand Down
26 changes: 14 additions & 12 deletions src/mode/bluetooth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
});
}

Expand Down

0 comments on commit c36b5be

Please sign in to comment.