From 4193cd0d1efd89fc1a2c95873ac8bc87a3428432 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B3zsef=20Farkas?= Date: Sat, 12 Aug 2017 02:23:53 +0200 Subject: [PATCH] Save config on shortcuts (#386) Closes #383 --- electron/src/main-app/main-app.component.ts | 33 +++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/electron/src/main-app/main-app.component.ts b/electron/src/main-app/main-app.component.ts index 521fa9cd..16f26995 100644 --- a/electron/src/main-app/main-app.component.ts +++ b/electron/src/main-app/main-app.component.ts @@ -2,9 +2,13 @@ import { Component, ViewEncapsulation, HostListener } from '@angular/core'; import { Router } from '@angular/router'; import { Store } from '@ngrx/store'; +import { saveAs } from 'file-saver'; import 'rxjs/add/operator/distinctUntilChanged'; +import 'rxjs/add/operator/first'; import 'rxjs/add/operator/ignoreElements'; +import 'rxjs/add/operator/let'; +import 'rxjs/add/operator/map'; import 'rxjs/add/operator/takeWhile'; import { AppState } from '../shared/store'; @@ -42,6 +46,35 @@ export class MainAppComponent { this.sendUserConfiguration(); } + @HostListener('window:keydown.alt.j', ['$event']) + onAltJ(event: KeyboardEvent): void { + event.preventDefault(); + event.stopPropagation(); + this.store + .let(getUserConfiguration()) + .first() + .subscribe(userConfiguration => { + const asString = JSON.stringify(userConfiguration.toJsonObject()); + const asBlob = new Blob([asString], { type: 'text/plain' }); + saveAs(asBlob, 'UserConfiguration.json'); + }); + } + + @HostListener('window:keydown.alt.b', ['$event']) + onAltB(event: KeyboardEvent): void { + event.preventDefault(); + event.stopPropagation(); + this.store + .let(getUserConfiguration()) + .first() + .map(userConfiguration => { + const uhkBuffer = new UhkBuffer(); + userConfiguration.toBinary(uhkBuffer); + return new Blob([uhkBuffer.getBufferContent()]); + }) + .subscribe(blob => saveAs(blob, 'UserConfiguration.bin')); + } + private sendUserConfiguration(): void { this.store .let(getUserConfiguration())