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

Commit

Permalink
fix: don't delete bonds of the dongle when un-pairing
Browse files Browse the repository at this point in the history
  • Loading branch information
ert78gb committed Nov 19, 2024
1 parent 9a70487 commit 0d6a586
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 36 deletions.
31 changes: 6 additions & 25 deletions packages/uhk-agent/src/services/device.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -662,35 +662,16 @@ export class DeviceService {
}

public async deleteHostConnection(event: Electron.IpcMainEvent, args: Array<any>): Promise<void> {
const {isConnectedDongleAddress, index, address} = args[0];
this.logService.misc('[DeviceService] delete host connection', { isConnectedDongleAddress, index, address });
const {index, address} = args[0];
this.logService.misc('[DeviceService] delete host connection', { index, address });

try {
await this.stopPollUhkDevice();
let dongleUhkDevice: UhkHidDevice;
try {
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);
event.sender.send(IpcEvents.device.deleteHostConnectionSuccess, {index, address});
}
finally {
if (dongleUhkDevice) {
dongleUhkDevice.close();
}
}
await this.device.deleteBond(convertBleStringToNumberArray(address));
this.logService.misc('[DeviceService] delete host connection success', { address });
await snooze(1000);
event.sender.send(IpcEvents.device.deleteHostConnectionSuccess, {index, address});
} catch (error) {
if (isConnectedDongleAddress) {
await this.forceReenumerateDongle();
}
await this.forceReenumerateDevice();
this.logService.misc('[DeviceService] delete host connection failed', { address, error });
event.sender.send(IpcEvents.device.deleteHostConnectionFailed, error.message);
Expand Down
3 changes: 1 addition & 2 deletions packages/uhk-web/src/app/services/device-renderer.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,8 @@ export class DeviceRendererService {
this.ipcRenderer.send(IpcEvents.device.changeKeyboardLayout, layout, hardwareConfiguration.toJsonObject());
}

deleteHostConnection(data: DeleteHostConnectionPayload, isConnectedDongleAddress: boolean): void {
deleteHostConnection(data: DeleteHostConnectionPayload): void {
this.ipcRenderer.send(IpcEvents.device.deleteHostConnection, {
isConnectedDongleAddress,
index: data.index,
address: data.hostConnection.address,
});
Expand Down
12 changes: 3 additions & 9 deletions packages/uhk-web/src/app/store/effects/dongle-pairing.effect.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { Injectable } from '@angular/core';
import { Actions, createEffect, ofType} from '@ngrx/effects';
import { Store } from '@ngrx/store';
import { map, tap, withLatestFrom } from 'rxjs/operators';
import { HostConnections } from 'uhk-common';
import { map, tap } from 'rxjs/operators';
import { NotificationType, runInElectron } from 'uhk-common';

import { DeviceRendererService } from '../../services/device-renderer.service';
Expand All @@ -16,19 +14,16 @@ import {
DonglePairingFailedAction,
DonglePairingSuccessAction,
} from '../actions/dongle-pairing.action';
import { AppState, getDongle } from '../index';

@Injectable()
export class DonglePairingEffect {

deleteHostConnection$ = createEffect(() => this.actions$
.pipe(
ofType<DeleteHostConnectionAction>(ActionTypes.DeleteHostConnection),
withLatestFrom(this.store.select(getDongle)),
map(([action, dongle ]) => {
map((action ) => {
if (runInElectron()) {
const isConnectedDongleAddress = action.payload.hostConnection.type === HostConnections.Dongle && dongle?.bleAddress === action.payload.hostConnection.address;
this.deviceRendererService.deleteHostConnection(action.payload, isConnectedDongleAddress);
this.deviceRendererService.deleteHostConnection(action.payload);
return new EmptyAction();
} else {
return new DeleteHostConnectionSuccessAction({
Expand Down Expand Up @@ -87,6 +82,5 @@ export class DonglePairingEffect {

constructor(private actions$: Actions,
private deviceRendererService: DeviceRendererService,
private store: Store<AppState>,
){}
}

0 comments on commit 0d6a586

Please sign in to comment.