Skip to content

Commit

Permalink
add more tracker connect checks to prevent dupes
Browse files Browse the repository at this point in the history
  • Loading branch information
JovannMC committed Apr 24, 2024
1 parent 152b4f2 commit a687202
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/devices/haritorax-wireless.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1054,8 +1054,12 @@ function listenToDeviceEvents() {
});

bluetooth.on("connect", (peripheral) => {
haritora.emit("connect", peripheral.advertisement.localName);
log(`Connected to ${peripheral.advertisement.localName}`);
const trackerName = peripheral.advertisement.localName;
if (trackerName && !activeDevices.includes(trackerName)) {
activeDevices.push(trackerName);
haritora.emit("connect", trackerName);
log(`Connected to ${peripheral.advertisement.localName}`);
}
});

bluetooth.on("disconnect", (peripheral) => {
Expand Down
2 changes: 1 addition & 1 deletion src/mode/bluetooth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export default class Bluetooth extends EventEmitter {
if (
localName &&
localName.startsWith("HaritoraX") &&
!activeDevices.find((device) => device[1] === peripheral)
(!activeDevices.find((device) => device[1] === peripheral) || !activeDevices.find((device) => device[0] === localName))
) {
log(`Found device: ${localName}`);
if (localName.startsWith("HaritoraX-"))
Expand Down

0 comments on commit a687202

Please sign in to comment.