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

fix: allow to delete host connection when dongle is not connected #135

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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