From 0d95b20e70803e72c75564952a9eadfcd5fe4061 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Farkas=20J=C3=B3zsef?= Date: Fri, 10 Feb 2017 19:26:03 +0100 Subject: [PATCH] Send configuration with ctrl + o Missing request of #213 --- .../keymap/edit/keymap-edit.component.ts | 28 +++++++++++++++++++ .../keymap/edit/keymap-edit.component.ts | 2 +- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/electron/src/components/keymap/edit/keymap-edit.component.ts b/electron/src/components/keymap/edit/keymap-edit.component.ts index 1cece636..93333a9e 100644 --- a/electron/src/components/keymap/edit/keymap-edit.component.ts +++ b/electron/src/components/keymap/edit/keymap-edit.component.ts @@ -17,6 +17,8 @@ import { KeymapEditComponent as SharedKeymapEditComponent } from '../../../share import { UhkDeviceService } from '../../../services/uhk-device.service'; +import { getUserConfiguration } from '../../../shared/store/reducers/user-configuration'; + @Component({ selector: 'keymap-edit', templateUrl: '../../../shared/components/keymap/edit/keymap-edit.component.html', @@ -53,6 +55,14 @@ export class KeymapEditComponent extends SharedKeymapEditComponent { this.sendKeymap(); } + @HostListener('window:keydown.control.o', ['$event']) + onCtrlO(event: KeyboardEvent): void { + console.log('ctrl + o pressed'); + event.preventDefault(); + event.stopPropagation(); + this.sendUserConfiguration(); + } + private sendLayer(): void { const currentLayer: number = this.wrap.getSelectedLayer(); this.keymap$ @@ -90,4 +100,22 @@ export class KeymapEditComponent extends SharedKeymapEditComponent { () => console.log('Keymap has been sucessfully uploaded') ); } + + private sendUserConfiguration(): void { + this.store + .let(getUserConfiguration()) + .map(userConfiguration => { + const uhkBuffer = new UhkBuffer(); + userConfiguration.toBinary(uhkBuffer); + return uhkBuffer.getBufferContent(); + }) + .switchMap((buffer: Buffer) => this.uhkDevice.sendConfig(buffer)) + .do(response => console.log('Sending user configuration finished', response)) + .switchMap(() => this.uhkDevice.applyConfig()) + .subscribe( + (response) => console.log('Applying user configuration finished', response), + error => console.error('Error during uploading user configuration', error), + () => console.log('User configuration has been sucessfully uploaded') + ); + } } diff --git a/shared/src/components/keymap/edit/keymap-edit.component.ts b/shared/src/components/keymap/edit/keymap-edit.component.ts index 09a063ec..b9317969 100644 --- a/shared/src/components/keymap/edit/keymap-edit.component.ts +++ b/shared/src/components/keymap/edit/keymap-edit.component.ts @@ -27,7 +27,7 @@ export class KeymapEditComponent { private deletable$: Observable; constructor( - private store: Store, + protected store: Store, private route: ActivatedRoute ) { this.keymap$ = route