Skip to content
This repository has been archived by the owner on Dec 15, 2024. It is now read-only.

Commit

Permalink
fix: allow to delete host connection when dongle is not connected (#135)
Browse files Browse the repository at this point in the history
* fix: allow to delete host connection when dongle is not connected

* fix: check dongle device existence

* fix: ensure dongle is connected

* fix: don't delete bonds of the dongle when un-pairing

* Revert "fix: don't delete bonds of the dongle when un-pairing"

This reverts commit 686efc3.
  • Loading branch information
ert78gb authored Nov 21, 2024
1 parent ccde74a commit 22cd23c
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions packages/uhk-agent/src/services/device.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -713,11 +713,16 @@ export class DeviceService {

try {
await this.stopPollUhkDevice();
const dongleHid = await getCurrentUhkDongleHID();
let dongleUhkDevice: UhkHidDevice;
try {
dongleUhkDevice = new UhkHidDevice(this.logService, this.options, this.rootDir, dongleHid);
await dongleUhkDevice.deleteAllBonds();
if (isConnectedDongleAddress) {
const dongleHid = await getCurrentUhkDongleHID();
if (dongleHid) {
dongleUhkDevice = new UhkHidDevice(this.logService, this.options, this.rootDir, dongleHid);
await dongleUhkDevice.deleteAllBonds();
}
}

await this.device.deleteBond(convertBleStringToNumberArray(address));
this.logService.misc('[DeviceService] delete host connection success', { address });
await snooze(1000);
Expand Down Expand Up @@ -747,6 +752,10 @@ export class DeviceService {
try {
await this.stopPollUhkDevice();
const dongleHid = await getCurrentUhkDongleHID();
if (!dongleHid) {
throw new Error('Cannot find dongle!');
}

let dongleUhkDevice: UhkHidDevice;
try {
dongleUhkDevice = new UhkHidDevice(this.logService, this.options, this.rootDir, dongleHid);
Expand Down Expand Up @@ -1058,6 +1067,12 @@ export class DeviceService {
try {
await snooze(1000);
const uhkDeviceProduct = await getCurrentUhkDongleHID();

if (uhkDeviceProduct) {
this.logService.misc('[DeviceService] Dongle not found, skip reenumeration');
return;
}

uhkHidDevice = new UhkHidDevice(this.logService, this.options, this.rootDir, uhkDeviceProduct);
await uhkHidDevice.reenumerate({
device: UHK_DONGLE,
Expand Down

0 comments on commit 22cd23c

Please sign in to comment.