From cbb5ab765f9dad5f8ee786f4b2aa29066e253ce4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Farkas=20J=C3=B3zsef?= Date: Sat, 11 Feb 2017 23:48:50 +0100 Subject: [PATCH] Enable sending user configuration from every screen --- .../keymap/edit/keymap-edit.component.ts | 27 -------- electron/src/main-app/main-app.component.ts | 65 +++++++------------ 2 files changed, 23 insertions(+), 69 deletions(-) diff --git a/electron/src/components/keymap/edit/keymap-edit.component.ts b/electron/src/components/keymap/edit/keymap-edit.component.ts index 93333a9e..124f0e0a 100644 --- a/electron/src/components/keymap/edit/keymap-edit.component.ts +++ b/electron/src/components/keymap/edit/keymap-edit.component.ts @@ -17,8 +17,6 @@ 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', @@ -55,14 +53,6 @@ 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$ @@ -101,21 +91,4 @@ export class KeymapEditComponent extends SharedKeymapEditComponent { ); } - 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/electron/src/main-app/main-app.component.ts b/electron/src/main-app/main-app.component.ts index 91d1b110..7107f39f 100644 --- a/electron/src/main-app/main-app.component.ts +++ b/electron/src/main-app/main-app.component.ts @@ -1,16 +1,13 @@ import { Component, ViewEncapsulation, HostListener } from '@angular/core'; -// import { Observable } from 'rxjs/Observable'; +import { Store } from '@ngrx/store'; -// import { Store } from '@ngrx/store'; -// import { AppState } from '../store'; -// import { DataStorage } from '../store/storage'; -// import { getKeymapEntities, getMacroEntities } from '../store/reducers'; +import { AppState } from '../shared/store'; +import { getUserConfiguration } from '../shared/store/reducers/user-configuration'; -// import { UhkBuffer } from '../config-serializer/UhkBuffer'; -// import { UserConfiguration } from '../config-serializer/config-items/UserConfiguration'; +import { UhkBuffer } from '../shared/config-serializer/UhkBuffer'; -// import { UhkDeviceService } from '../services/uhk-device.service'; +import { UhkDeviceService } from '../services/uhk-device.service'; @Component({ selector: 'main-app', @@ -20,48 +17,32 @@ import { Component, ViewEncapsulation, HostListener } from '@angular/core'; }) export class MainAppComponent { - // private configuration$: Observable; - - constructor( - // private uhkDevice: UhkDeviceService, - // store: Store, - // dataStorage: DataStorage - ) { - // this.configuration$ = store.let(getKeymapEntities()) - // .combineLatest(store.let(getMacroEntities())) - // .map((pair) => { - // const config = new UserConfiguration(); - // Object.assign(config, dataStorage.getConfiguration()); - // config.keymaps = pair[0]; - // config.macros = pair[1]; - // return config; - // }); - } + constructor(private uhkDevice: UhkDeviceService, private store: Store) { } @HostListener('window:keydown.control.o', ['$event']) onCtrlO(event: KeyboardEvent): void { console.log('ctrl + o pressed'); event.preventDefault(); event.stopPropagation(); - this.sendConfiguration(); + this.sendUserConfiguration(); } - private sendConfiguration(): void { - // this.configuration$ - // .first() - // .map(configuration => { - // const uhkBuffer = new UhkBuffer(); - // configuration.toBinary(uhkBuffer); - // return uhkBuffer.getBufferContent(); - // }) - // .switchMap((buffer: Buffer) => this.uhkDevice.sendConfig(buffer)) - // .do(response => console.log('Sending config finished', response)) - // .switchMap(() => this.uhkDevice.applyConfig()) - // .subscribe( - // (response) => console.log('Applying config finished', response), - // error => console.error('Error during uploading config', error), - // () => console.log('Config 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') + ); } }