refactor: ngrx-store use enum ActionTypes and Action classes everywhere (#919)

This commit is contained in:
Róbert Kiss
2019-02-22 19:00:17 +01:00
committed by László Monda
parent de71f6f88c
commit 7a2c8cb2e4
46 changed files with 1026 additions and 978 deletions

23
package-lock.json generated
View File

@@ -2149,10 +2149,13 @@
"dev": true "dev": true
}, },
"@types/jquery": { "@types/jquery": {
"version": "3.3.1", "version": "3.3.29",
"resolved": "https://registry.npmjs.org/@types/jquery/-/jquery-3.3.1.tgz", "resolved": "https://registry.npmjs.org/@types/jquery/-/jquery-3.3.29.tgz",
"integrity": "sha512-N3h+rzN518yl2xKrW0o6KKdNmWZ+OwG6SoM5TBEQFF0tTv5wXPEsoOuYQ2Kt3/89XbcSZUJLdjiT/2c3BR/ApQ==", "integrity": "sha512-FhJvBninYD36v3k6c+bVk1DSZwh7B5Dpb/Pyk3HKVsiohn0nhbefZZ+3JXbWQhFyt0MxSl2jRDdGQPHeOHFXrQ==",
"dev": true "dev": true,
"requires": {
"@types/sizzle": "*"
}
}, },
"@types/jsonfile": { "@types/jsonfile": {
"version": "4.0.1", "version": "4.0.1",
@@ -2197,6 +2200,12 @@
"integrity": "sha512-41qEJgBH/TWgo5NFSvBCJ1qkoi3Q6ONSF2avrHq1LVEZfYpdHmj0y9SuTK+u9ZhG1sYQKBL1AWXKyLWP4RaUoQ==", "integrity": "sha512-41qEJgBH/TWgo5NFSvBCJ1qkoi3Q6ONSF2avrHq1LVEZfYpdHmj0y9SuTK+u9ZhG1sYQKBL1AWXKyLWP4RaUoQ==",
"dev": true "dev": true
}, },
"@types/sizzle": {
"version": "2.3.2",
"resolved": "https://registry.npmjs.org/@types/sizzle/-/sizzle-2.3.2.tgz",
"integrity": "sha512-7EJYyKTL7tFR8+gDbB6Wwz/arpGa0Mywk1TJbNzKzHtzbwVmY4HR9WqS5VV7dsBUKQmPNr192jHr/VpBluj/hg==",
"dev": true
},
"@types/usb": { "@types/usb": {
"version": "1.1.3", "version": "1.1.3",
"resolved": "https://registry.npmjs.org/@types/usb/-/usb-1.1.3.tgz", "resolved": "https://registry.npmjs.org/@types/usb/-/usb-1.1.3.tgz",
@@ -16763,9 +16772,9 @@
"dev": true "dev": true
}, },
"typescript": { "typescript": {
"version": "2.6.2", "version": "2.8.4",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-2.6.2.tgz", "resolved": "https://registry.npmjs.org/typescript/-/typescript-2.8.4.tgz",
"integrity": "sha1-PFtv1/beCRQmkCfwPAlGdY92c6Q=", "integrity": "sha512-IIU5cN1mR5J3z9jjdESJbnxikTrEz3lzAw/D0Tf45jHpBp55nY31UkUvmVHoffCfKHTqJs3fCLPDxknQTTFegQ==",
"dev": true "dev": true
}, },
"uglify-js": { "uglify-js": {

View File

@@ -23,7 +23,7 @@
"@types/electron-settings": "3.0.0", "@types/electron-settings": "3.0.0",
"@types/fs-extra": "5.0.1", "@types/fs-extra": "5.0.1",
"@types/jasmine": "2.8.8", "@types/jasmine": "2.8.8",
"@types/jquery": "3.3.1", "@types/jquery": "3.3.29",
"@types/jsonfile": "4.0.1", "@types/jsonfile": "4.0.1",
"@types/lodash": "4.14.121", "@types/lodash": "4.14.121",
"@types/node": "8.0.53", "@types/node": "8.0.53",
@@ -74,7 +74,7 @@
"ts-loader": "2.3.1", "ts-loader": "2.3.1",
"ts-node": "7.0.1", "ts-node": "7.0.1",
"tslint": "5.9.1", "tslint": "5.9.1",
"typescript": "2.6.2", "typescript": "2.8.4",
"webpack": "3.12.0" "webpack": "3.12.0"
}, },
"pre-commit": [ "pre-commit": [

View File

@@ -15,28 +15,6 @@ export function capitalizeFirstLetter(text: string): string {
return text.charAt(0).toUpperCase() + text.slice(1); return text.charAt(0).toUpperCase() + text.slice(1);
} }
/**
* This function coerces a string into a string literal type.
* Using tagged union types in TypeScript 2.0, this enables
* powerful typechecking of our reducers.
*
* Since every action label passes through this function it
* is a good place to ensure all of our action labels
* are unique.
*/
const typeCache: { [label: string]: boolean } = {};
export function type<T>(label: T | ''): T {
if (typeCache[<string>label]) {
throw new Error(`Action type "${label}" is not unique"`);
}
typeCache[<string>label] = true;
return <T>label;
}
export function runInElectron() { export function runInElectron() {
return window && (<any>window).process && (<any>window).process.type; return window && (<any>window).process && (<any>window).process.type;
} }

View File

@@ -343,12 +343,6 @@
"@types/jasmine": "*" "@types/jasmine": "*"
} }
}, },
"@types/jquery": {
"version": "3.2.9",
"resolved": "https://registry.npmjs.org/@types/jquery/-/jquery-3.2.9.tgz",
"integrity": "sha512-AmYGadmTv+Xh6re2CH5ruyvV3znvtJbhxyT00JQAGFP2U+xgqhf+C2xfjdP/GgK5d9YmSif/UYs2ssMl4gW6fw==",
"dev": true
},
"@types/node": { "@types/node": {
"version": "9.6.2", "version": "9.6.2",
"resolved": "https://registry.npmjs.org/@types/node/-/node-9.6.2.tgz", "resolved": "https://registry.npmjs.org/@types/node/-/node-9.6.2.tgz",
@@ -9318,12 +9312,6 @@
"integrity": "sha1-kl0mAdOaxIXgkc8NpcbmlNw9yv8=", "integrity": "sha1-kl0mAdOaxIXgkc8NpcbmlNw9yv8=",
"dev": true "dev": true
}, },
"reselect": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/reselect/-/reselect-3.0.1.tgz",
"integrity": "sha1-79qpjqdFEyTQkrKyFjpqHXqaIUc=",
"dev": true
},
"resolve": { "resolve": {
"version": "1.8.1", "version": "1.8.1",
"resolved": "https://registry.npmjs.org/resolve/-/resolve-1.8.1.tgz", "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.8.1.tgz",

View File

@@ -42,7 +42,6 @@
"@types/file-saver": "0.0.1", "@types/file-saver": "0.0.1",
"@types/jasmine": "2.8.8", "@types/jasmine": "2.8.8",
"@types/jasminewd2": "2.0.3", "@types/jasminewd2": "2.0.3",
"@types/jquery": "3.2.9",
"@types/usb": "1.1.3", "@types/usb": "1.1.3",
"angular-confirmation-popover": "3.2.0", "angular-confirmation-popover": "3.2.0",
"angular-notifier": "2.0.0", "angular-notifier": "2.0.0",
@@ -71,11 +70,9 @@
"nouislider": "^11.1.0", "nouislider": "^11.1.0",
"postcss-url": "^7.1.2", "postcss-url": "^7.1.2",
"protractor": "5.4.0", "protractor": "5.4.0",
"reselect": "3.0.1",
"rxjs": "5.5.8", "rxjs": "5.5.8",
"semver": "5.6.0", "semver": "5.6.0",
"ts-keycode-enum": "^1.0.6", "ts-keycode-enum": "^1.0.6",
"typescript": "2.6.2",
"uhk-common": "1.0.0", "uhk-common": "1.0.0",
"xml-loader": "1.2.1", "xml-loader": "1.2.1",
"zone.js": "0.8.26", "zone.js": "0.8.26",

View File

@@ -2,7 +2,6 @@ import { Component, OnInit, OnDestroy } from '@angular/core';
import { Store } from '@ngrx/store'; import { Store } from '@ngrx/store';
import { AppState, getUserConfiguration } from '../../../store'; import { AppState, getUserConfiguration } from '../../../store';
import { SetUserConfigurationValueAction } from '../../../store/actions/user-config'; import { SetUserConfigurationValueAction } from '../../../store/actions/user-config';
import { DefaultUserConfigurationService } from '../../../services/default-user-configuration.service';
import { SliderPips, SliderProps } from '../../slider-wrapper/slider-wrapper.component'; import { SliderPips, SliderProps } from '../../slider-wrapper/slider-wrapper.component';
import { Subscription } from 'rxjs/Subscription'; import { Subscription } from 'rxjs/Subscription';
import { UserConfiguration } from 'uhk-common'; import { UserConfiguration } from 'uhk-common';
@@ -117,7 +116,8 @@ export class MouseSpeedComponent implements OnInit, OnDestroy {
private userConfig$: Store<UserConfiguration>; private userConfig$: Store<UserConfiguration>;
private userConfigSubscription: Subscription; private userConfigSubscription: Subscription;
constructor(private store: Store<AppState>, private defaultUserConfigurationService: DefaultUserConfigurationService) {} constructor(private store: Store<AppState>) {
}
ngOnInit(): void { ngOnInit(): void {
this.userConfig$ = this.store.select(getUserConfiguration); this.userConfig$ = this.store.select(getUserConfiguration);
@@ -132,7 +132,9 @@ export class MouseSpeedComponent implements OnInit, OnDestroy {
} }
ngOnDestroy(): void { ngOnDestroy(): void {
this.userConfigSubscription.unsubscribe(); if (this.userConfigSubscription) {
this.userConfigSubscription.unsubscribe();
}
} }
onSetPropertyValue(propertyName: string, value: number): void { onSetPropertyValue(propertyName: string, value: number): void {
@@ -143,6 +145,6 @@ export class MouseSpeedComponent implements OnInit, OnDestroy {
} }
resetToDefault() { resetToDefault() {
this.store.dispatch(new ResetMouseSpeedSettingsAction()); this.store.dispatch(new ResetMouseSpeedSettingsAction());
} }
} }

View File

@@ -2,12 +2,11 @@ import { ChangeDetectionStrategy, Component } from '@angular/core';
import { Store } from '@ngrx/store'; import { Store } from '@ngrx/store';
import { Keymap } from 'uhk-common'; import { Keymap } from 'uhk-common';
import { BehaviorSubject } from 'rxjs/BehaviorSubject'; import { BehaviorSubject, Observable } from 'rxjs';
import { Observable } from 'rxjs/Observable';
import { combineLatest, publishReplay, refCount } from 'rxjs/operators'; import { combineLatest, publishReplay, refCount } from 'rxjs/operators';
import { AppState } from '../../../store'; import { AppState } from '../../../store';
import { KeymapActions } from '../../../store/actions'; import { AddKeymapAction } from '../../../store/actions/keymap';
@Component({ @Component({
selector: 'keymap-add', selector: 'keymap-add',
@@ -42,6 +41,6 @@ export class KeymapAddComponent {
} }
addKeymap(keymap: Keymap) { addKeymap(keymap: Keymap) {
this.store.dispatch(KeymapActions.addKeymap(keymap)); this.store.dispatch(new AddKeymapAction(keymap));
} }
} }

View File

@@ -2,16 +2,13 @@ import { Injectable } from '@angular/core';
import { CanActivate, Router } from '@angular/router'; import { CanActivate, Router } from '@angular/router';
import { Keymap } from 'uhk-common'; import { Keymap } from 'uhk-common';
import { Observable } from 'rxjs/Observable'; import { Observable } from 'rxjs';
import { of } from 'rxjs/observable/of'; import { of } from 'rxjs/observable/of';
import { switchMap, tap } from 'rxjs/operators'; import { switchMap, tap } from 'rxjs/operators';
import 'rxjs/add/operator/let';
import { Store } from '@ngrx/store'; import { Store } from '@ngrx/store';
import { AppState } from '../../../store'; import { AppState, getDefaultKeymap } from '../../../store';
import { getKeymaps } from '../../../store/reducers/user-configuration';
@Injectable() @Injectable()
export class KeymapEditGuard implements CanActivate { export class KeymapEditGuard implements CanActivate {
@@ -20,10 +17,9 @@ export class KeymapEditGuard implements CanActivate {
canActivate(): Observable<boolean> { canActivate(): Observable<boolean> {
return this.store return this.store
.let(getKeymaps()) .select(getDefaultKeymap)
.pipe( .pipe(
tap((keymaps: Keymap[]) => { tap((defaultKeymap: Keymap) => {
const defaultKeymap = keymaps.find(keymap => keymap.isDefault);
if (defaultKeymap) { if (defaultKeymap) {
this.router.navigate(['/keymap', defaultKeymap.abbreviation]); this.router.navigate(['/keymap', defaultKeymap.abbreviation]);
} }

View File

@@ -1,18 +1,23 @@
import { ChangeDetectionStrategy, Component, HostListener } from '@angular/core'; import { ChangeDetectionStrategy, Component, HostListener, OnDestroy } from '@angular/core';
import { ActivatedRoute } from '@angular/router'; import { ActivatedRoute } from '@angular/router';
import { Store } from '@ngrx/store'; import { Store } from '@ngrx/store';
import { Keymap } from 'uhk-common'; import { Keymap } from 'uhk-common';
import { Observable } from 'rxjs/Observable'; import { Observable, Subscription } from 'rxjs';
import { combineLatest, first, map, pluck, publishReplay, refCount, switchMap } from 'rxjs/operators'; import { combineLatest, first, map, pluck, switchMap } from 'rxjs/operators';
import 'rxjs/add/operator/let';
import { saveAs } from 'file-saver'; import { saveAs } from 'file-saver';
import { layerDoubleTapSupported, AppState, getKeyboardLayout } from '../../../store'; import {
import { getKeymap, getKeymaps, getUserConfiguration } from '../../../store/reducers/user-configuration'; getUserConfiguration,
getSelectedKeymap,
isKeymapDeletable,
layerDoubleTapSupported,
AppState,
getKeyboardLayout
} from '../../../store';
import { KeyboardLayout } from '../../../keyboard/keyboard-layout.enum'; import { KeyboardLayout } from '../../../keyboard/keyboard-layout.enum';
import { KeymapActions } from '../../../store/actions'; import { EditDescriptionAction, SelectKeymapAction } from '../../../store/actions/keymap';
import { ChangeKeymapDescription } from '../../../models/ChangeKeymapDescription'; import { ChangeKeymapDescription } from '../../../models/ChangeKeymapDescription';
@Component({ @Component({
@@ -24,7 +29,7 @@ import { ChangeKeymapDescription } from '../../../models/ChangeKeymapDescription
'class': 'container-fluid' 'class': 'container-fluid'
} }
}) })
export class KeymapEditComponent { export class KeymapEditComponent implements OnDestroy {
keyboardSplit: boolean; keyboardSplit: boolean;
@@ -33,26 +38,29 @@ export class KeymapEditComponent {
keyboardLayout$: Observable<KeyboardLayout>; keyboardLayout$: Observable<KeyboardLayout>;
allowLayerDoubleTap$: Observable<boolean>; allowLayerDoubleTap$: Observable<boolean>;
private routeSubscription: Subscription;
constructor(protected store: Store<AppState>, constructor(protected store: Store<AppState>,
route: ActivatedRoute) { route: ActivatedRoute) {
this.keymap$ = route this.routeSubscription = route
.params .params
.pipe( .pipe(
pluck<{}, string>('abbr'), pluck<{}, string>('abbr')
switchMap((abbr: string) => store.let(getKeymap(abbr))), )
publishReplay(1), .subscribe(abbr => store.dispatch(new SelectKeymapAction(abbr)));
refCount()
);
this.deletable$ = store.let(getKeymaps()) this.keymap$ = store.select(getSelectedKeymap);
.pipe(
map((keymaps: Keymap[]) => keymaps.length > 1) this.deletable$ = store.select(isKeymapDeletable);
);
this.keyboardLayout$ = store.select(getKeyboardLayout); this.keyboardLayout$ = store.select(getKeyboardLayout);
this.allowLayerDoubleTap$ = store.select(layerDoubleTapSupported); this.allowLayerDoubleTap$ = store.select(layerDoubleTapSupported);
} }
ngOnDestroy(): void {
this.routeSubscription.unsubscribe();
}
downloadKeymap() { downloadKeymap() {
const exportableJSON$: Observable<string> = this.keymap$ const exportableJSON$: Observable<string> = this.keymap$
.pipe( .pipe(
@@ -79,12 +87,12 @@ export class KeymapEditComponent {
} }
descriptionChanged(event: ChangeKeymapDescription): void { descriptionChanged(event: ChangeKeymapDescription): void {
this.store.dispatch(new KeymapActions.EditDescriptionAction(event)); this.store.dispatch(new EditDescriptionAction(event));
} }
private toExportableJSON(keymap: Keymap): Observable<any> { private toExportableJSON(keymap: Keymap): Observable<any> {
return this.store return this.store
.let(getUserConfiguration()) .select(getUserConfiguration)
.pipe( .pipe(
first(), first(),
map(userConfiguration => { map(userConfiguration => {

View File

@@ -16,7 +16,13 @@ import { Keymap } from 'uhk-common';
import { Store } from '@ngrx/store'; import { Store } from '@ngrx/store';
import { AppState } from '../../../store'; import { AppState } from '../../../store';
import { KeymapActions } from '../../../store/actions'; import {
DuplicateKeymapAction,
EditKeymapAbbreviationAction,
EditKeymapNameAction,
RemoveKeymapAction,
SetDefaultKeymapAction
} from '../../../store/actions/keymap';
import * as util from '../../../util'; import * as util from '../../../util';
const DEFAULT_TRASH_TITLE = '<span class="text-nowrap">Delete keymap</span>'; const DEFAULT_TRASH_TITLE = '<span class="text-nowrap">Delete keymap</span>';
@@ -59,18 +65,18 @@ export class KeymapHeaderComponent implements OnChanges {
setDefault() { setDefault() {
if (!this.keymap.isDefault) { if (!this.keymap.isDefault) {
this.store.dispatch(KeymapActions.setDefault(this.keymap.abbreviation)); this.store.dispatch(new SetDefaultKeymapAction(this.keymap.abbreviation));
} }
} }
removeKeymap() { removeKeymap() {
if (this.deletable) { if (this.deletable) {
this.store.dispatch(KeymapActions.removeKeymap(this.keymap.abbreviation)); this.store.dispatch(new RemoveKeymapAction(this.keymap.abbreviation));
} }
} }
duplicateKeymap() { duplicateKeymap() {
this.store.dispatch(KeymapActions.duplicateKeymap(this.keymap)); this.store.dispatch(new DuplicateKeymapAction(this.keymap));
} }
editKeymapName(name: string) { editKeymapName(name: string) {
@@ -79,7 +85,7 @@ export class KeymapHeaderComponent implements OnChanges {
return; return;
} }
this.store.dispatch(KeymapActions.editKeymapName(this.keymap.abbreviation, name)); this.store.dispatch(new EditKeymapNameAction({ abbr: this.keymap.abbreviation, name }));
} }
editKeymapAbbr(newAbbr: string) { editKeymapAbbr(newAbbr: string) {
@@ -91,7 +97,11 @@ export class KeymapHeaderComponent implements OnChanges {
} }
newAbbr = newAbbr.toUpperCase(); newAbbr = newAbbr.toUpperCase();
this.store.dispatch(KeymapActions.editKeymapAbbr(this.keymap.name, this.keymap.abbreviation, newAbbr)); this.store.dispatch(new EditKeymapAbbreviationAction({
name: this.keymap.name,
abbr: this.keymap.abbreviation,
newAbbr
}));
} }
setKeymapTitle(): void { setKeymapTitle(): void {

View File

@@ -3,13 +3,17 @@ import { ActivatedRoute } from '@angular/router';
import { Store } from '@ngrx/store'; import { Store } from '@ngrx/store';
import { Macro, MacroAction } from 'uhk-common'; import { Macro, MacroAction } from 'uhk-common';
import { Observable } from 'rxjs/Observable'; import { Observable, Subscription } from 'rxjs';
import { Subscription } from 'rxjs/Subscription';
import { pluck, switchMap } from 'rxjs/operators';
import { MacroActions } from '../../../store/actions'; import {
import { AppState, macroPlaybackSupported } from '../../../store'; AddMacroActionAction,
import { getMacro } from '../../../store/reducers/user-configuration'; DeleteMacroActionAction,
ReorderMacroActionAction,
SaveMacroActionAction,
SelectMacroAction
} from '../../../store/actions/macro';
import { AppState, getSelectedMacro, macroPlaybackSupported } from '../../../store';
import { pluck } from 'rxjs/operators';
@Component({ @Component({
selector: 'macro-edit', selector: 'macro-edit',
@@ -25,18 +29,20 @@ export class MacroEditComponent implements OnDestroy {
macroId: number; macroId: number;
macroPlaybackSupported$: Observable<boolean>; macroPlaybackSupported$: Observable<boolean>;
private subscription: Subscription; private selectedMacroSubscription: Subscription;
private routeSubscription: Subscription;
constructor(private store: Store<AppState>, public route: ActivatedRoute) { constructor(private store: Store<AppState>,
this.subscription = route public route: ActivatedRoute) {
this.routeSubscription = route
.params .params
.pipe( .pipe(
pluck<{}, string>('id'), pluck<{}, string>('id')
switchMap((id: string) => {
this.macroId = +id;
return store.let(getMacro(this.macroId));
})
) )
.subscribe(id => store.dispatch(new SelectMacroAction(+id)));
this.selectedMacroSubscription = store.select(getSelectedMacro)
.subscribe((macro: Macro) => { .subscribe((macro: Macro) => {
this.macro = macro; this.macro = macro;
}); });
@@ -46,22 +52,23 @@ export class MacroEditComponent implements OnDestroy {
} }
ngOnDestroy() { ngOnDestroy() {
this.subscription.unsubscribe(); this.selectedMacroSubscription.unsubscribe();
this.routeSubscription.unsubscribe();
} }
addAction(macroId: number, action: MacroAction) { addAction(macroId: number, action: MacroAction) {
this.store.dispatch(MacroActions.addMacroAction(macroId, action)); this.store.dispatch(new AddMacroActionAction({ id: macroId, action }));
} }
editAction(macroId: number, index: number, action: MacroAction) { editAction(macroId: number, index: number, action: MacroAction) {
this.store.dispatch(MacroActions.saveMacroAction(macroId, index, action)); this.store.dispatch(new SaveMacroActionAction({ id: macroId, index, action }));
} }
deleteAction(macroId: number, index: number, action: MacroAction) { deleteAction(macroId: number, index: number, action: MacroAction) {
this.store.dispatch(MacroActions.deleteMacroAction(macroId, index, action)); this.store.dispatch(new DeleteMacroActionAction({ id: macroId, index, action }));
} }
reorderAction(macroId: number, oldIndex: number, newIndex: number) { reorderAction(macroId: number, oldIndex: number, newIndex: number) {
this.store.dispatch(MacroActions.reorderMacroAction(macroId, oldIndex, newIndex)); this.store.dispatch(new ReorderMacroActionAction({ id: macroId, oldIndex, newIndex }));
} }
} }

View File

@@ -13,7 +13,7 @@ import {
import { Store } from '@ngrx/store'; import { Store } from '@ngrx/store';
import { Macro } from 'uhk-common'; import { Macro } from 'uhk-common';
import { MacroActions } from '../../../store/actions'; import { DuplicateMacroAction, EditMacroNameAction, RemoveMacroAction } from '../../../store/actions/macro';
import { AppState } from '../../../store'; import { AppState } from '../../../store';
import * as util from '../../../util'; import * as util from '../../../util';
@@ -51,11 +51,11 @@ export class MacroHeaderComponent implements AfterViewInit, OnChanges {
} }
removeMacro() { removeMacro() {
this.store.dispatch(MacroActions.removeMacro(this.macro.id)); this.store.dispatch(new RemoveMacroAction(this.macro.id));
} }
duplicateMacro() { duplicateMacro() {
this.store.dispatch(MacroActions.duplicateMacro(this.macro)); this.store.dispatch(new DuplicateMacroAction(this.macro));
} }
editMacroName(name: string) { editMacroName(name: string) {
@@ -64,7 +64,7 @@ export class MacroHeaderComponent implements AfterViewInit, OnChanges {
return; return;
} }
this.store.dispatch(MacroActions.editMacroName(this.macro.id, name)); this.store.dispatch(new EditMacroNameAction({ id: this.macro.id, name }));
} }
calculateHeaderTextWidth(text): void { calculateHeaderTextWidth(text): void {

View File

@@ -8,8 +8,7 @@ import 'rxjs/add/operator/let';
import { Store } from '@ngrx/store'; import { Store } from '@ngrx/store';
import { AppState } from '../../../store/index'; import { AppState, getMacros } from '../../../store';
import { getMacros } from '../../../store/reducers/user-configuration';
@Injectable() @Injectable()
export class MacroNotFoundGuard implements CanActivate { export class MacroNotFoundGuard implements CanActivate {
@@ -18,7 +17,7 @@ export class MacroNotFoundGuard implements CanActivate {
canActivate(): Observable<boolean> { canActivate(): Observable<boolean> {
return this.store return this.store
.let(getMacros()) .select(getMacros)
.pipe( .pipe(
map((macros: Macro[]) => { map((macros: Macro[]) => {
const hasMacros = macros.length > 0; const hasMacros = macros.length > 0;

View File

@@ -31,8 +31,7 @@ import {
import { Tab } from './tab'; import { Tab } from './tab';
import { AppState, macroPlaybackSupported } from '../../store'; import { AppState, getKeymaps, macroPlaybackSupported } from '../../store';
import { getKeymaps } from '../../store/reducers/user-configuration';
import { KeyActionRemap } from '../../models/key-action-remap'; import { KeyActionRemap } from '../../models/key-action-remap';
import { RemapInfo } from '../../models/remap-info'; import { RemapInfo } from '../../models/remap-info';
@@ -153,7 +152,7 @@ export class PopoverComponent implements OnChanges {
constructor(private store: Store<AppState>, constructor(private store: Store<AppState>,
private cdRef: ChangeDetectorRef) { private cdRef: ChangeDetectorRef) {
this.animationState = 'closed'; this.animationState = 'closed';
this.keymaps$ = store.let(getKeymaps()) this.keymaps$ = store.select(getKeymaps)
.pipe( .pipe(
combineLatest(this.currentKeymap$), combineLatest(this.currentKeymap$),
map(([keymaps, currentKeymap]: [Keymap[], Keymap]) => map(([keymaps, currentKeymap]: [Keymap[], Keymap]) =>

View File

@@ -5,8 +5,7 @@ import { KeyAction, Macro, PlayMacroAction } from 'uhk-common';
import { Tab } from '../tab'; import { Tab } from '../tab';
import { AppState } from '../../../../store'; import { AppState, getMacros } from '../../../../store';
import { getMacros } from '../../../../store/reducers/user-configuration';
import { SelectOptionData } from '../../../../models/select-option-data'; import { SelectOptionData } from '../../../../models/select-option-data';
@Component({ @Component({
@@ -26,7 +25,7 @@ export class MacroTabComponent extends Tab implements OnInit, OnChanges, OnDestr
constructor(store: Store<AppState>) { constructor(store: Store<AppState>) {
super(); super();
this.subscription = store.let(getMacros()) this.subscription = store.select(getMacros)
.subscribe((macros: Macro[]) => this.macros = macros); .subscribe((macros: Macro[]) => this.macros = macros);
this.macroOptions = []; this.macroOptions = [];
this.selectedMacroIndex = 0; this.selectedMacroIndex = 0;

View File

@@ -14,7 +14,7 @@ import { Store } from '@ngrx/store';
import { Subscription } from 'rxjs/Subscription'; import { Subscription } from 'rxjs/Subscription';
import { AppState, getSideMenuPageState } from '../../store'; import { AppState, getSideMenuPageState } from '../../store';
import { MacroActions } from '../../store/actions'; import { AddMacroAction } from '../../store/actions/macro';
import { RenameUserConfigurationAction } from '../../store/actions/user-config'; import { RenameUserConfigurationAction } from '../../store/actions/user-config';
import { SideMenuPageState } from '../../models/side-menu-page-state'; import { SideMenuPageState } from '../../models/side-menu-page-state';
@@ -92,7 +92,7 @@ export class SideMenuComponent implements OnInit, OnDestroy {
} }
addMacro() { addMacro() {
this.store.dispatch(MacroActions.addMacro()); this.store.dispatch(new AddMacroAction());
} }
editDeviceName(name: string): void { editDeviceName(name: string): void {

View File

@@ -26,8 +26,7 @@ import {
import { CaptureService } from '../../../../services/capture.service'; import { CaptureService } from '../../../../services/capture.service';
import { MapperService } from '../../../../services/mapper.service'; import { MapperService } from '../../../../services/mapper.service';
import { AppState } from '../../../../store'; import { AppState, getMacros } from '../../../../store';
import { getMacros } from '../../../../store/reducers/user-configuration';
import { SvgKeyCaptureEvent, SvgKeyClickEvent } from '../../../../models/svg-key-events'; import { SvgKeyCaptureEvent, SvgKeyClickEvent } from '../../../../models/svg-key-events';
import { OperatingSystem } from '../../../../models/operating-system'; import { OperatingSystem } from '../../../../models/operating-system';
import { KeyModifierModel } from '../../../../models/key-modifier-model'; import { KeyModifierModel } from '../../../../models/key-modifier-model';
@@ -114,7 +113,7 @@ export class SvgKeyboardKeyComponent implements OnInit, OnChanges, OnDestroy {
private element: ElementRef, private element: ElementRef,
private captureService: CaptureService private captureService: CaptureService
) { ) {
this.subscription = store.let(getMacros()) this.subscription = store.select(getMacros)
.subscribe((macros: Macro[]) => this.macros = macros); .subscribe((macros: Macro[]) => this.macros = macros);
this.reset(); this.reset();

View File

@@ -36,8 +36,8 @@ import {
} from 'uhk-common'; } from 'uhk-common';
import { MapperService } from '../../../services/mapper.service'; import { MapperService } from '../../../services/mapper.service';
import { AppState } from '../../../store'; import { AppState, getKeymaps, getMacros } from '../../../store';
import { KeymapActions } from '../../../store/actions'; import { SaveKeyAction } from '../../../store/actions/keymap';
import { PopoverComponent } from '../../popover'; import { PopoverComponent } from '../../popover';
import { KeyboardLayout } from '../../../keyboard/keyboard-layout.enum'; import { KeyboardLayout } from '../../../keyboard/keyboard-layout.enum';
import { ChangeKeymapDescription } from '../../../models/ChangeKeymapDescription'; import { ChangeKeymapDescription } from '../../../models/ChangeKeymapDescription';
@@ -71,7 +71,7 @@ export class SvgKeyboardWrapComponent implements OnInit, OnChanges {
@Output() descriptionChanged = new EventEmitter<ChangeKeymapDescription>(); @Output() descriptionChanged = new EventEmitter<ChangeKeymapDescription>();
@ViewChild(PopoverComponent, {read: ElementRef}) popover: ElementRef; @ViewChild(PopoverComponent, { read: ElementRef }) popover: ElementRef;
popoverShown: boolean; popoverShown: boolean;
keyEditConfig: { moduleId: number, keyId: number }; keyEditConfig: { moduleId: number, keyId: number };
@@ -185,27 +185,29 @@ export class SvgKeyboardWrapComponent implements OnInit, OnChanges {
keystrokeAction.modifierMask = mapLeftRigthModifierToKeyActionModifier(event.captured.left, event.captured.right); keystrokeAction.modifierMask = mapLeftRigthModifierToKeyActionModifier(event.captured.left, event.captured.right);
this.store.dispatch( this.store.dispatch(
KeymapActions.saveKey( new SaveKeyAction({
this.keymap, keymap: this.keymap,
this.currentLayer, layer: this.currentLayer,
event.moduleId, module: event.moduleId,
event.keyId, key: event.keyId,
{ keyAction: {
remapOnAllKeymap: event.shiftPressed, remapOnAllKeymap: event.shiftPressed,
remapOnAllLayer: event.altPressed, remapOnAllLayer: event.altPressed,
action: keystrokeAction action: keystrokeAction
}) }
})
); );
} }
onRemap(keyAction: KeyActionRemap): void { onRemap(keyAction: KeyActionRemap): void {
this.store.dispatch( this.store.dispatch(
KeymapActions.saveKey( new SaveKeyAction({
this.keymap, keymap: this.keymap,
this.currentLayer, layer: this.currentLayer,
this.keyEditConfig.moduleId, module: this.keyEditConfig.moduleId,
this.keyEditConfig.keyId, key: this.keyEditConfig.keyId,
keyAction) keyAction
})
); );
this.hidePopover(); this.hidePopover();
} }
@@ -318,7 +320,7 @@ export class SvgKeyboardWrapComponent implements OnInit, OnChanges {
} else if (keyAction instanceof PlayMacroAction) { } else if (keyAction instanceof PlayMacroAction) {
const playMacroAction: PlayMacroAction = keyAction; const playMacroAction: PlayMacroAction = keyAction;
return this.store return this.store
.select(appState => appState.userConfiguration.macros) .select(getMacros)
.pipe( .pipe(
map(macroState => macroState.find(macro => { map(macroState => macroState.find(macro => {
return macro.id === playMacroAction.macroId; return macro.id === playMacroAction.macroId;
@@ -340,7 +342,7 @@ export class SvgKeyboardWrapComponent implements OnInit, OnChanges {
} else if (keyAction instanceof SwitchKeymapAction) { } else if (keyAction instanceof SwitchKeymapAction) {
const switchKeymapAction: SwitchKeymapAction = keyAction; const switchKeymapAction: SwitchKeymapAction = keyAction;
return this.store return this.store
.select(appState => appState.userConfiguration.keymaps) .select(getKeymaps)
.pipe( .pipe(
map(keymaps => keymaps.find(keymap => keymap.abbreviation === switchKeymapAction.keymapAbbreviation).name), map(keymaps => keymaps.find(keymap => keymap.abbreviation === switchKeymapAction.keymapAbbreviation).name),
map(keymapName => { map(keymapName => {

View File

@@ -1,4 +1,4 @@
///<reference path="../../../../node_modules/@types/jquery/index.d.ts"/> ///<reference path="../../../../../../node_modules/@types/jquery/index.d.ts"/>
import { AfterContentInit, Directive, ElementRef, HostBinding, Input, OnChanges, SimpleChanges } from '@angular/core'; import { AfterContentInit, Directive, ElementRef, HostBinding, Input, OnChanges, SimpleChanges } from '@angular/core';
import { DomSanitizer } from '@angular/platform-browser'; import { DomSanitizer } from '@angular/platform-browser';

View File

@@ -1,44 +1,41 @@
import { Action } from '@ngrx/store'; import { Action } from '@ngrx/store';
import { type } from 'uhk-common';
import { UpdateInfo } from '../../models/update-info'; import { UpdateInfo } from '../../models/update-info';
const PREFIX = '[app-update] '; export enum ActionTypes {
UpdateAvailable = '[app-update] update available',
// tslint:disable-next-line:variable-name UpdateApp = '[app-update] update app',
export const ActionTypes = { DoNotUpdateApp = '[app-update] do not update app',
UPDATE_AVAILABLE: type(PREFIX + 'update available'), UpdateDownloaded = '[app-update] update downloaded',
UPDATE_APP: type(PREFIX + 'update app'), Updating = '[app-update] updating',
DO_NOT_UPDATE_APP: type(PREFIX + 'do not update app'), UpdateError = '[app-update] error'
UPDATE_DOWNLOADED: type(PREFIX + 'update downloaded'), }
UPDATING: type(PREFIX + 'updating'),
UPDATE_ERROR: type(PREFIX + 'error')
};
export class UpdateAvailableAction implements Action { export class UpdateAvailableAction implements Action {
type = ActionTypes.UPDATE_AVAILABLE; type = ActionTypes.UpdateAvailable;
} }
export class UpdateAppAction implements Action { export class UpdateAppAction implements Action {
type = ActionTypes.UPDATE_APP; type = ActionTypes.UpdateApp;
} }
export class DoNotUpdateAppAction implements Action { export class DoNotUpdateAppAction implements Action {
type = ActionTypes.DO_NOT_UPDATE_APP; type = ActionTypes.DoNotUpdateApp;
} }
export class UpdateDownloadedAction implements Action { export class UpdateDownloadedAction implements Action {
type = ActionTypes.UPDATE_DOWNLOADED; type = ActionTypes.UpdateDownloaded;
constructor(public payload: UpdateInfo) { constructor(public payload: UpdateInfo) {
} }
} }
export class UpdatingAction implements Action { export class UpdatingAction implements Action {
type = ActionTypes.UPDATING; type = ActionTypes.Updating;
} }
export class UpdateErrorAction implements Action { export class UpdateErrorAction implements Action {
type = ActionTypes.UPDATE_ERROR; type = ActionTypes.UpdateError;
constructor(public payload: any) {} constructor(public payload: any) {}
} }

View File

@@ -1,121 +1,118 @@
import { Action } from '@ngrx/store'; import { Action } from '@ngrx/store';
import { AppStartInfo, HardwareConfiguration, Notification, type } from 'uhk-common'; import { AppStartInfo, HardwareConfiguration, Notification } from 'uhk-common';
import { ElectronLogEntry } from '../../models/xterm-log'; import { ElectronLogEntry } from '../../models/xterm-log';
const PREFIX = '[app] '; export enum ActionTypes {
AppBootstrapped = '[app] bootstrapped',
AppStarted = '[app] started',
AppShowNotification = '[app] show notification',
ApplyAppStartInfo = '[app] apply command line args',
AppProcessStartInfo = '[app] process start info',
UndoLast = '[app] undo last action',
UndoLastSuccess = '[app] undo last action success',
DismissUndoNotification = '[app] dismiss notification action',
LoadHardwareConfigurationSuccess = '[app] load hardware configuration success',
ElectronMainLogReceived = '[app] Electron main log received',
OpenUrlInNewWindow = '[app] Open URL in new Window',
PrivilegeWhatWillThisDo = '[app] What will this do clicked',
SetupPermissionError = '[app] Setup permission error',
LoadAppStartInfo = '[app] Load app start info',
StartKeypressCapturing = '[app] Start keypress capturing',
StopKeypressCapturing = '[app] Stop keypress capturing'
}
// tslint:disable-next-line:variable-name export class AppBootstrappedAction implements Action {
export const ActionTypes = { type = ActionTypes.AppBootstrapped;
APP_BOOTSRAPPED: type(PREFIX + 'bootstrapped'),
APP_STARTED: type(PREFIX + 'started'),
APP_SHOW_NOTIFICATION: type(PREFIX + 'show notification'),
APPLY_APP_START_INFO: type(PREFIX + 'apply command line args'),
APP_PROCESS_START_INFO: type(PREFIX + 'process start info'),
UNDO_LAST: type(PREFIX + 'undo last action'),
UNDO_LAST_SUCCESS: type(PREFIX + 'undo last action success'),
DISMISS_UNDO_NOTIFICATION: type(PREFIX + 'dismiss notification action'),
LOAD_HARDWARE_CONFIGURATION_SUCCESS: type(PREFIX + 'load hardware configuration success'),
ELECTRON_MAIN_LOG_RECEIVED: type(PREFIX + 'Electron main log received'),
OPEN_URL_IN_NEW_WINDOW: type(PREFIX + 'Open URL in new Window'),
PRIVILEGE_WHAT_WILL_THIS_DO: type(PREFIX + 'What will this do clicked'),
SETUP_PERMISSION_ERROR: type(PREFIX + 'Setup permission error'),
LOAD_APP_START_INFO: type(PREFIX + 'Load app start info'),
START_KEYPRESS_CAPTURING: type(PREFIX + 'Start keypress capturing'),
STOP_KEYPRESS_CAPTURING: type(PREFIX + 'Stop keypress capturing')
};
export class AppBootsrappedAction implements Action {
type = ActionTypes.APP_BOOTSRAPPED;
} }
export class AppStartedAction implements Action { export class AppStartedAction implements Action {
type = ActionTypes.APP_STARTED; type = ActionTypes.AppStarted;
} }
export class ShowNotificationAction implements Action { export class ShowNotificationAction implements Action {
type = ActionTypes.APP_SHOW_NOTIFICATION; type = ActionTypes.AppShowNotification;
constructor(public payload: Notification) { constructor(public payload: Notification) {
} }
} }
export class ApplyAppStartInfoAction implements Action { export class ApplyAppStartInfoAction implements Action {
type = ActionTypes.APPLY_APP_START_INFO; type = ActionTypes.ApplyAppStartInfo;
constructor(public payload: AppStartInfo) { constructor(public payload: AppStartInfo) {
} }
} }
export class ProcessAppStartInfoAction implements Action { export class ProcessAppStartInfoAction implements Action {
type = ActionTypes.APP_PROCESS_START_INFO; type = ActionTypes.AppProcessStartInfo;
constructor(public payload: AppStartInfo) { constructor(public payload: AppStartInfo) {
} }
} }
export class UndoLastAction implements Action { export class UndoLastAction implements Action {
type = ActionTypes.UNDO_LAST; type = ActionTypes.UndoLast;
constructor(public payload: any) { constructor(public payload: any) {
} }
} }
export class UndoLastSuccessAction implements Action { export class UndoLastSuccessAction implements Action {
type = ActionTypes.UNDO_LAST_SUCCESS; type = ActionTypes.UndoLastSuccess;
} }
export class DismissUndoNotificationAction implements Action { export class DismissUndoNotificationAction implements Action {
type = ActionTypes.DISMISS_UNDO_NOTIFICATION; type = ActionTypes.DismissUndoNotification;
} }
export class LoadHardwareConfigurationSuccessAction implements Action { export class LoadHardwareConfigurationSuccessAction implements Action {
type = ActionTypes.LOAD_HARDWARE_CONFIGURATION_SUCCESS; type = ActionTypes.LoadHardwareConfigurationSuccess;
constructor(public payload: HardwareConfiguration) { constructor(public payload: HardwareConfiguration) {
} }
} }
export class ElectronMainLogReceivedAction implements Action { export class ElectronMainLogReceivedAction implements Action {
type = ActionTypes.ELECTRON_MAIN_LOG_RECEIVED; type = ActionTypes.ElectronMainLogReceived;
constructor(public payload: ElectronLogEntry) { constructor(public payload: ElectronLogEntry) {
} }
} }
export class OpenUrlInNewWindowAction implements Action { export class OpenUrlInNewWindowAction implements Action {
type = ActionTypes.OPEN_URL_IN_NEW_WINDOW; type = ActionTypes.OpenUrlInNewWindow;
constructor(public payload: string) { constructor(public payload: string) {
} }
} }
export class PrivilegeWhatWillThisDoAction implements Action { export class PrivilegeWhatWillThisDoAction implements Action {
type = ActionTypes.PRIVILEGE_WHAT_WILL_THIS_DO; type = ActionTypes.PrivilegeWhatWillThisDo;
} }
export class SetupPermissionErrorAction implements Action { export class SetupPermissionErrorAction implements Action {
type = ActionTypes.SETUP_PERMISSION_ERROR; type = ActionTypes.SetupPermissionError;
constructor(public payload: string) { constructor(public payload: string) {
} }
} }
export class LoadAppStartInfoAction implements Action { export class LoadAppStartInfoAction implements Action {
type = ActionTypes.LOAD_APP_START_INFO; type = ActionTypes.LoadAppStartInfo;
} }
export class StartKeypressCapturingAction implements Action { export class StartKeypressCapturingAction implements Action {
type = ActionTypes.START_KEYPRESS_CAPTURING; type = ActionTypes.StartKeypressCapturing;
} }
export class StopKeypressCapturingAction implements Action { export class StopKeypressCapturingAction implements Action {
type = ActionTypes.STOP_KEYPRESS_CAPTURING; type = ActionTypes.StopKeypressCapturing;
} }
export type Actions export type Actions
= AppStartedAction = AppStartedAction
| AppBootsrappedAction | AppBootstrappedAction
| ShowNotificationAction | ShowNotificationAction
| ApplyAppStartInfoAction | ApplyAppStartInfoAction
| ProcessAppStartInfoAction | ProcessAppStartInfoAction

View File

@@ -1,68 +1,65 @@
import { Action } from '@ngrx/store'; import { Action } from '@ngrx/store';
import { AutoUpdateSettings, type } from 'uhk-common'; import { AutoUpdateSettings } from 'uhk-common';
const PREFIX = '[app-update-config] '; export enum ActionTypes {
ToggleCheckForUpdateOnStartup = '[app-update-config] Check for update on startup',
// tslint:disable-next-line:variable-name CheckForUpdateNow = '[app-update-config] Check for update now',
export const ActionTypes = { CheckForUpdateSuccess = '[app-update-config] Check for update success',
TOGGLE_CHECK_FOR_UPDATE_ON_STARTUP: type(PREFIX + 'Check for update on startup'), CheckForUpdateFailed = '[app-update-config] Check for update failed',
CHECK_FOR_UPDATE_NOW: type(PREFIX + 'Check for update now'), TogglePreReleaseFlag = '[app-update-config] Toggle pre release update flag',
CHECK_FOR_UPDATE_SUCCESS: type(PREFIX + 'Check for update success'), LoadAutoUpdateSettings = '[app-update-config] Load auto update settings',
CHECK_FOR_UPDATE_FAILED: type(PREFIX + 'Check for update faild'), LoadAutoUpdateSettingSuccess = '[app-update-config] Load auto update settings success',
TOGGLE_PRE_RELEASE_FLAG: type(PREFIX + 'Toggle pre release update flag'), SaveAutoUpdateSettingSuccess = '[app-update-config] Save auto update settings success'
LOAD_AUTO_UPDATE_SETTINGS: type(PREFIX + 'Load auto update settings'), }
LOAD_AUTO_UPDATE_SETTINGS_SUCCESS: type(PREFIX + 'Load auto update settings success'),
SAVE_AUTO_UPDATE_SETTINGS_SUCCESS: type(PREFIX + 'Save auto update settings success')
};
export class ToggleCheckForUpdateOnStartupAction implements Action { export class ToggleCheckForUpdateOnStartupAction implements Action {
type = ActionTypes.TOGGLE_CHECK_FOR_UPDATE_ON_STARTUP; type = ActionTypes.ToggleCheckForUpdateOnStartup;
constructor(public payload: boolean) { constructor(public payload: boolean) {
} }
} }
export class CheckForUpdateNowAction implements Action { export class CheckForUpdateNowAction implements Action {
type = ActionTypes.CHECK_FOR_UPDATE_NOW; type = ActionTypes.CheckForUpdateNow;
constructor(public payload?: boolean) { constructor(public payload?: boolean) {
} }
} }
export class CheckForUpdateSuccessAction implements Action { export class CheckForUpdateSuccessAction implements Action {
type = ActionTypes.CHECK_FOR_UPDATE_SUCCESS; type = ActionTypes.CheckForUpdateSuccess;
constructor(public payload?: string) { constructor(public payload?: string) {
} }
} }
export class CheckForUpdateFailedAction implements Action { export class CheckForUpdateFailedAction implements Action {
type = ActionTypes.CHECK_FOR_UPDATE_FAILED; type = ActionTypes.CheckForUpdateFailed;
constructor(public payload: any) { constructor(public payload: any) {
} }
} }
export class TogglePreReleaseFlagAction implements Action { export class TogglePreReleaseFlagAction implements Action {
type = ActionTypes.TOGGLE_PRE_RELEASE_FLAG; type = ActionTypes.TogglePreReleaseFlag;
constructor(public payload: boolean) { constructor(public payload: boolean) {
} }
} }
export class LoadAutoUpdateSettingsAction implements Action { export class LoadAutoUpdateSettingsAction implements Action {
type = ActionTypes.LOAD_AUTO_UPDATE_SETTINGS_SUCCESS; type = ActionTypes.LoadAutoUpdateSettingSuccess;
} }
export class LoadAutoUpdateSettingsSuccessAction implements Action { export class LoadAutoUpdateSettingsSuccessAction implements Action {
type = ActionTypes.LOAD_AUTO_UPDATE_SETTINGS_SUCCESS; type = ActionTypes.LoadAutoUpdateSettingSuccess;
constructor(public payload: AutoUpdateSettings) { constructor(public payload: AutoUpdateSettings) {
} }
} }
export class SaveAutoUpdateSettingsSuccessAction implements Action { export class SaveAutoUpdateSettingsSuccessAction implements Action {
type = ActionTypes.SAVE_AUTO_UPDATE_SETTINGS_SUCCESS; type = ActionTypes.SaveAutoUpdateSettingSuccess;
} }
export type Actions export type Actions

View File

@@ -1,35 +1,30 @@
import { Action } from '@ngrx/store'; import { Action } from '@ngrx/store';
import { type } from 'uhk-common';
import { UHKContributor } from '../../models/uhk-contributor'; import { UHKContributor } from '../../models/uhk-contributor';
const PREFIX = '[contributors] '; export enum ActionTypes {
GetAgentContributors = '[contributors] Get',
// tslint:disable-next-line:variable-name FetchAgentContributors = '[contributors] Fetch',
export const ActionTypes = { AgentContributorsAvailable = '[contributors] Available',
GET_AGENT_CONTRIBUTORS: type(PREFIX + 'Get'), AgentContributorsNotAvailable = '[contributors] Not available'
FETCH_AGENT_CONTRIBUTORS: type(PREFIX + 'Fetch'), }
AGENT_CONTRIBUTORS_AVAILABLE: type(PREFIX + 'Available'),
AGENT_CONTRIBUTORS_NOT_AVAILABLE: type(PREFIX + 'Not available')
};
export class GetAgentContributorsAction implements Action { export class GetAgentContributorsAction implements Action {
type = ActionTypes.GET_AGENT_CONTRIBUTORS; type = ActionTypes.GetAgentContributors;
} }
export class FetchAgentContributorsAction implements Action { export class FetchAgentContributorsAction implements Action {
type = ActionTypes.FETCH_AGENT_CONTRIBUTORS; type = ActionTypes.FetchAgentContributors;
} }
export class AgentContributorsAvailableAction implements Action { export class AgentContributorsAvailableAction implements Action {
type = ActionTypes.AGENT_CONTRIBUTORS_AVAILABLE; type = ActionTypes.AgentContributorsAvailable;
constructor(public payload: UHKContributor[]) { constructor(public payload: UHKContributor[]) {
} }
} }
export class AgentContributorsNotAvailableAction implements Action { export class AgentContributorsNotAvailableAction implements Action {
type = ActionTypes.AGENT_CONTRIBUTORS_NOT_AVAILABLE; type = ActionTypes.AgentContributorsNotAvailable;
constructor(public payload: Error) { constructor(public payload: Error) {
console.error(payload); console.error(payload);

View File

@@ -1,158 +1,154 @@
import { Action } from '@ngrx/store'; import { Action } from '@ngrx/store';
import { DeviceConnectionState, FirmwareUpgradeIpcResponse, HardwareModules, IpcResponse, type } from 'uhk-common'; import { DeviceConnectionState, FirmwareUpgradeIpcResponse, HardwareModules, IpcResponse } from 'uhk-common';
import { FirmwareUpgradeError } from '../../models/firmware-upgrade-error'; import { FirmwareUpgradeError } from '../../models/firmware-upgrade-error';
const PREFIX = '[device] '; export enum ActionTypes {
SetPrivilegeOnLinux = '[device] set privilege on linux',
// tslint:disable-next-line:variable-name SetPrivilegeOnLinuxReply = '[device] set privilege on linux reply',
export const ActionTypes = { ConnectionStateChanged = '[device] connection state changed',
SET_PRIVILEGE_ON_LINUX: type(PREFIX + 'set privilege on linux'), SaveConfiguration = '[device] save configuration',
SET_PRIVILEGE_ON_LINUX_REPLY: type(PREFIX + 'set privilege on linux reply'), SaveConfigurationReply = '[device] save configuration reply',
CONNECTION_STATE_CHANGED: type(PREFIX + 'connection state changed'), SavingConfiguration = '[device] saving configuration',
SAVE_CONFIGURATION: type(PREFIX + 'save configuration'), ShowSaveToKeyboardButton = '[device] show save to keyboard button',
SAVE_CONFIGURATION_REPLY: type(PREFIX + 'save configuration reply'), SaveToKeyboardSuccess = '[device] save to keyboard success',
SAVING_CONFIGURATION: type(PREFIX + 'saving configuration'), SaveToKeyboardFailed = '[device] save to keyboard failed',
SHOW_SAVE_TO_KEYBOARD_BUTTON: type(PREFIX + 'show save to keyboard button'), HideSaveToKeyboardButton = '[device] hide save to keyboard button',
SAVE_TO_KEYBOARD_SUCCESS: type(PREFIX + 'save to keyboard success'), ResetUserConfiguration = '[device] reset user configuration',
SAVE_TO_KEYBOARD_FAILED: type(PREFIX + 'save to keyboard failed'), ResetMouseSpeedSettings = '[device] reset mouse speed settings',
HIDE_SAVE_TO_KEYBOARD_BUTTON: type(PREFIX + 'hide save to keyboard button'), UpdateFirmware = '[device] update firmware',
RESET_USER_CONFIGURATION: type(PREFIX + 'reset user configuration'), UpdateFirmwareWith = '[device] update firmware with',
RESET_MOUSE_SPEED_SETTINGS: type(PREFIX + 'reset mouse speed settings'), UpdateFirmwareReply = '[device] update firmware reply',
UPDATE_FIRMWARE: type(PREFIX + 'update firmware'), UpdateFirmwareSuccess = '[device] update firmware success',
UPDATE_FIRMWARE_WITH: type(PREFIX + 'update firmware with'), UpdateFirmwareFailed = '[device] update firmware failed',
UPDATE_FIRMWARE_REPLY: type(PREFIX + 'update firmware reply'), ModulesInfoLoaded = '[device] module info loaded',
UPDATE_FIRMWARE_SUCCESS: type(PREFIX + 'update firmware success'), HasBackupUserConfiguration = '[device] Store backup user configuration',
UPDATE_FIRMWARE_FAILED: type(PREFIX + 'update firmware failed'), RestoreConfigurationFromBackup = '[device] Restore configuration from backup',
UPDATE_FIRMWARE_OK_BUTTON: type(PREFIX + 'update firmware ok button click'), RestoreConfigurationFromBackupSuccess = '[device] Restore configuration from backup success',
MODULES_INFO_LOADED: type(PREFIX + 'module info loaded'), RecoveryDevice = '[device] Recovery device',
HAS_BACKUP_USER_CONFIGURATION: type(PREFIX + 'Store backup user configuration'), EnableUsbStackTest = '[device] USB stack test',
RESTORE_CONFIGURATION_FROM_BACKUP: type(PREFIX + 'Restore configuration from backup'), StartConnectionPoller = '[device] Start connection poller'
RESTORE_CONFIGURATION_FROM_BACKUP_SUCCESS: type(PREFIX + 'Restore configuration from backup success'), }
RECOVERY_DEVICE: type(PREFIX + 'Recovery device'),
ENABLE_USB_STACK_TEST: type(PREFIX + 'USB stack test'),
START_CONNECTION_POLLER: type(PREFIX + 'Start connection poller')
};
export class SetPrivilegeOnLinuxAction implements Action { export class SetPrivilegeOnLinuxAction implements Action {
type = ActionTypes.SET_PRIVILEGE_ON_LINUX; type = ActionTypes.SetPrivilegeOnLinux;
} }
export class SetPrivilegeOnLinuxReplyAction implements Action { export class SetPrivilegeOnLinuxReplyAction implements Action {
type = ActionTypes.SET_PRIVILEGE_ON_LINUX_REPLY; type = ActionTypes.SetPrivilegeOnLinuxReply;
constructor(public payload: IpcResponse) { constructor(public payload: IpcResponse) {
} }
} }
export class ConnectionStateChangedAction implements Action { export class ConnectionStateChangedAction implements Action {
type = ActionTypes.CONNECTION_STATE_CHANGED; type = ActionTypes.ConnectionStateChanged;
constructor(public payload: DeviceConnectionState) { constructor(public payload: DeviceConnectionState) {
} }
} }
export class SaveConfigurationAction implements Action { export class SaveConfigurationAction implements Action {
type = ActionTypes.SAVE_CONFIGURATION; type = ActionTypes.SaveConfiguration;
constructor() { constructor() {
} }
} }
export class SaveConfigurationReplyAction implements Action { export class SaveConfigurationReplyAction implements Action {
type = ActionTypes.SAVE_CONFIGURATION_REPLY; type = ActionTypes.SaveConfigurationReply;
constructor(public payload: IpcResponse) { constructor(public payload: IpcResponse) {
} }
} }
export class ShowSaveToKeyboardButtonAction implements Action { export class ShowSaveToKeyboardButtonAction implements Action {
type = ActionTypes.SHOW_SAVE_TO_KEYBOARD_BUTTON; type = ActionTypes.ShowSaveToKeyboardButton;
} }
export class SaveToKeyboardSuccessAction implements Action { export class SaveToKeyboardSuccessAction implements Action {
type = ActionTypes.SAVE_TO_KEYBOARD_SUCCESS; type = ActionTypes.SaveToKeyboardSuccess;
} }
export class SaveToKeyboardSuccessFailed implements Action { export class SaveToKeyboardSuccessFailed implements Action {
type = ActionTypes.SAVE_TO_KEYBOARD_FAILED; type = ActionTypes.SaveToKeyboardFailed;
} }
export class HideSaveToKeyboardButton implements Action { export class HideSaveToKeyboardButton implements Action {
type = ActionTypes.HIDE_SAVE_TO_KEYBOARD_BUTTON; type = ActionTypes.HideSaveToKeyboardButton;
} }
export class ResetUserConfigurationAction implements Action { export class ResetUserConfigurationAction implements Action {
type = ActionTypes.RESET_USER_CONFIGURATION; type = ActionTypes.ResetUserConfiguration;
} }
export class UpdateFirmwareAction implements Action { export class UpdateFirmwareAction implements Action {
type = ActionTypes.UPDATE_FIRMWARE; type = ActionTypes.UpdateFirmware;
} }
export class UpdateFirmwareWithAction implements Action { export class UpdateFirmwareWithAction implements Action {
type = ActionTypes.UPDATE_FIRMWARE_WITH; type = ActionTypes.UpdateFirmwareWith;
constructor(public payload: Array<number>) { constructor(public payload: Array<number>) {
} }
} }
export class UpdateFirmwareReplyAction implements Action { export class UpdateFirmwareReplyAction implements Action {
type = ActionTypes.UPDATE_FIRMWARE_REPLY; type = ActionTypes.UpdateFirmwareReply;
constructor(public payload: FirmwareUpgradeIpcResponse) { constructor(public payload: FirmwareUpgradeIpcResponse) {
} }
} }
export class UpdateFirmwareSuccessAction implements Action { export class UpdateFirmwareSuccessAction implements Action {
type = ActionTypes.UPDATE_FIRMWARE_SUCCESS; type = ActionTypes.UpdateFirmwareSuccess;
constructor(public payload: HardwareModules) { constructor(public payload: HardwareModules) {
} }
} }
export class UpdateFirmwareFailedAction implements Action { export class UpdateFirmwareFailedAction implements Action {
type = ActionTypes.UPDATE_FIRMWARE_FAILED; type = ActionTypes.UpdateFirmwareFailed;
constructor(public payload: FirmwareUpgradeError) { constructor(public payload: FirmwareUpgradeError) {
} }
} }
export class ResetMouseSpeedSettingsAction implements Action { export class ResetMouseSpeedSettingsAction implements Action {
type = ActionTypes.RESET_MOUSE_SPEED_SETTINGS; type = ActionTypes.ResetMouseSpeedSettings;
} }
export class HardwareModulesLoadedAction implements Action { export class HardwareModulesLoadedAction implements Action {
type = ActionTypes.MODULES_INFO_LOADED; type = ActionTypes.ModulesInfoLoaded;
constructor(public payload: HardwareModules) { constructor(public payload: HardwareModules) {
} }
} }
export class RestoreUserConfigurationFromBackupAction implements Action { export class RestoreUserConfigurationFromBackupAction implements Action {
type = ActionTypes.RESTORE_CONFIGURATION_FROM_BACKUP; type = ActionTypes.RestoreConfigurationFromBackup;
} }
export class HasBackupUserConfigurationAction implements Action { export class HasBackupUserConfigurationAction implements Action {
type = ActionTypes.HAS_BACKUP_USER_CONFIGURATION; type = ActionTypes.HasBackupUserConfiguration;
constructor(public payload: boolean) { constructor(public payload: boolean) {
} }
} }
export class RestoreUserConfigurationFromBackupSuccessAction implements Action { export class RestoreUserConfigurationFromBackupSuccessAction implements Action {
type = ActionTypes.RESTORE_CONFIGURATION_FROM_BACKUP_SUCCESS; type = ActionTypes.RestoreConfigurationFromBackupSuccess;
} }
export class RecoveryDeviceAction implements Action { export class RecoveryDeviceAction implements Action {
type = ActionTypes.RECOVERY_DEVICE; type = ActionTypes.RecoveryDevice;
} }
export class EnableUsbStackTestAction implements Action { export class EnableUsbStackTestAction implements Action {
type = ActionTypes.ENABLE_USB_STACK_TEST; type = ActionTypes.EnableUsbStackTest;
} }
export class StartConnectionPollerAction implements Action { export class StartConnectionPollerAction implements Action {
type = ActionTypes.START_CONNECTION_POLLER; type = ActionTypes.StartConnectionPoller;
} }
export type Actions export type Actions

View File

@@ -1,2 +0,0 @@
export * from './keymap';
export * from './macro';

View File

@@ -1,199 +1,139 @@
import { Action } from '@ngrx/store'; import { Action } from '@ngrx/store';
import { Keymap, Macro } from 'uhk-common'; import { Keymap } from 'uhk-common';
import { UndoUserConfigData } from '../../models/undo-user-config-data';
import { ChangeKeymapDescription } from '../../models/ChangeKeymapDescription'; import { ChangeKeymapDescription } from '../../models/ChangeKeymapDescription';
import { KeyActionRemap } from '../../models/key-action-remap'; import { KeyActionRemap } from '../../models/key-action-remap';
import { UndoUserConfigData } from '../../models/undo-user-config-data';
export type KeymapAction = export enum ActionTypes {
KeymapActions.AddKeymapAction | Add = '[Keymap] Add keymap',
KeymapActions.DuplicateKeymapAction | Duplicate = '[Keymap] Duplicate keymap',
KeymapActions.EditKeymapNameAction | EditAbbr = '[Keymap] Edit keymap abbreviation',
KeymapActions.EditKeymapAbbreviationAction | EditName = '[Keymap] Edit keymap title',
KeymapActions.LoadKeymapSuccessAction | SaveKey = '[Keymap] Save key action',
KeymapActions.SetDefaultAction | SetDefault = '[Keymap] Set default option',
KeymapActions.RemoveKeymapAction | Remove = '[Keymap] Remove keymap',
KeymapActions.SaveKeyAction | CheckMacro = '[Keymap] Check deleted macro',
KeymapActions.CheckMacroAction | LoadKeymaps = '[Keymap] Load keymaps',
KeymapActions.EditDescriptionAction; LoadKeymapsSuccess = '[Keymap] Load keymaps success',
EditDescription = '[Keymap] Edit description',
UndoLastAction = '[Keymap] Undo last action',
Select = '[Keymap] Select keymap action'
}
export namespace KeymapActions { export class AddKeymapAction implements Action {
export const ADD = '[Keymap] Add keymap'; type = ActionTypes.Add;
export type AddKeymapAction = { constructor(public payload: Keymap) {
type: typeof ADD,
payload: Keymap
};
export const DUPLICATE = '[Keymap] Duplicate keymap';
export type DuplicateKeymapAction = {
type: typeof DUPLICATE,
payload: Keymap
};
export const EDIT_ABBR = '[Keymap] Edit keymap abbreviation';
export type EditKeymapAbbreviationAction = {
type: typeof EDIT_ABBR,
payload: {
abbr: string;
newAbbr: string;
name: string;
}
};
export const EDIT_NAME = '[Keymap] Edit keymap title';
export type EditKeymapNameAction = {
type: typeof EDIT_NAME,
payload: {
abbr: string;
name: string;
}
};
export const SAVE_KEY = '[Keymap] Save key action';
export type SaveKeyAction = {
type: typeof SAVE_KEY,
payload: {
keymap: Keymap;
layer: number;
module: number;
key: number;
keyAction: KeyActionRemap;
}
};
export const SET_DEFAULT = '[Keymap] Set default option';
export type SetDefaultAction = {
type: typeof SET_DEFAULT,
payload: string
};
export const REMOVE = '[Keymap] Remove keymap';
export type RemoveKeymapAction = {
type: typeof REMOVE,
payload: string
};
export const CHECK_MACRO = '[Keymap] Check deleted macro';
export type CheckMacroAction = {
type: typeof CHECK_MACRO,
payload: Macro
};
export const LOAD_KEYMAPS = '[Keymap] Load keymaps';
export const LOAD_KEYMAPS_SUCCESS = '[Keymap] Load keymaps success';
export type LoadKeymapSuccessAction = {
type: typeof LOAD_KEYMAPS_SUCCESS,
payload: Keymap[]
};
export const UNDO_LAST_ACTION = '[Keymap] Undo last action';
export type UndoLastAction = {
type: typeof UNDO_LAST_ACTION,
payload: UndoUserConfigData
};
export const EDIT_DESCRIPTION = '[Keymap] Edit description';
export class EditDescriptionAction {
type = EDIT_DESCRIPTION;
constructor(public payload: ChangeKeymapDescription) {
}
}
export function loadKeymaps(): Action {
return {
type: KeymapActions.LOAD_KEYMAPS
};
}
export function loadKeymapsSuccess(keymaps: Keymap[]): LoadKeymapSuccessAction {
return {
type: KeymapActions.LOAD_KEYMAPS_SUCCESS,
payload: keymaps
};
}
export function addKeymap(item: Keymap): AddKeymapAction {
return {
type: KeymapActions.ADD,
payload: item
};
}
export function setDefault(abbr: string): SetDefaultAction {
return {
type: KeymapActions.SET_DEFAULT,
payload: abbr
};
}
export function removeKeymap(abbr: string): RemoveKeymapAction {
return {
type: KeymapActions.REMOVE,
payload: abbr
};
}
export function duplicateKeymap(keymap: Keymap): DuplicateKeymapAction {
return {
type: KeymapActions.DUPLICATE,
payload: keymap
};
}
export function editKeymapName(abbr: string, name: string): EditKeymapNameAction {
return {
type: KeymapActions.EDIT_NAME,
payload: {
abbr: abbr,
name: name
}
};
}
export function editKeymapAbbr(name: string, abbr: string, newAbbr: string): EditKeymapAbbreviationAction {
return {
type: KeymapActions.EDIT_ABBR,
payload: {
name,
abbr,
newAbbr
}
};
}
export function saveKey(keymap: Keymap,
layer: number,
module: number,
key: number,
keyAction: KeyActionRemap): SaveKeyAction {
return {
type: KeymapActions.SAVE_KEY,
payload: {
keymap,
layer,
module,
key,
keyAction
}
};
}
export function checkMacro(macro: Macro): CheckMacroAction {
return {
type: KeymapActions.CHECK_MACRO,
payload: macro
};
} }
} }
export class DuplicateKeymapAction implements Action {
type = ActionTypes.Duplicate;
constructor(public payload: Keymap) {
}
}
export class EditKeymapAbbreviationAction implements Action {
type = ActionTypes.EditAbbr;
constructor(public payload: {
abbr: string;
newAbbr: string;
name: string;
}) {
}
}
export class EditKeymapNameAction implements Action {
type = ActionTypes.EditName;
constructor(public payload: {
abbr: string;
name: string;
}) {
}
}
export class SaveKeyAction implements Action {
type = ActionTypes.SaveKey;
constructor(public payload: {
keymap: Keymap;
layer: number;
module: number;
key: number;
keyAction: KeyActionRemap;
}) {
}
}
export class SetDefaultKeymapAction implements Action {
type = ActionTypes.SetDefault;
constructor(public payload: string) {
}
}
export class RemoveKeymapAction implements Action {
type = ActionTypes.Remove;
constructor(public payload: string) {
}
}
export class CheckMacroAction implements Action {
type = ActionTypes.CheckMacro;
constructor(public payload: number) {
}
}
export class LoadKeymapsAction implements Action {
type = ActionTypes.LoadKeymaps;
}
export class LoadKeymapSuccessAction implements Action {
type = ActionTypes.LoadKeymapsSuccess;
constructor(public payload: Keymap[]) {
}
}
export class EditDescriptionAction implements Action {
type = ActionTypes.EditDescription;
constructor(public payload: ChangeKeymapDescription) {
}
}
export class UndoLastAction implements Action {
type = ActionTypes.UndoLastAction;
constructor(public payload: UndoUserConfigData) {
}
}
export class SelectKeymapAction implements Action {
type = ActionTypes.Select;
constructor(public payload: string) {
}
}
export type Actions
= AddKeymapAction
| DuplicateKeymapAction
| EditKeymapAbbreviationAction
| EditKeymapNameAction
| SaveKeyAction
| SetDefaultKeymapAction
| RemoveKeymapAction
| CheckMacroAction
| LoadKeymapsAction
| LoadKeymapSuccessAction
| EditDescriptionAction
| UndoLastAction
| SelectKeymapAction
;

View File

@@ -1,91 +1,87 @@
import { Action } from '@ngrx/store'; import { Action } from '@ngrx/store';
import { Macro, MacroAction as ConfigItemMacroAction } from 'uhk-common'; import { Macro, MacroAction as ConfigItemMacroAction } from 'uhk-common';
export type MacroAction = Action & { payload?: any }; export enum ActionTypes {
Duplicate = '[Macro] Duplicate macro',
EditName = '[Macro] Edit macro title',
Remove = '[Macro] Remove macro',
Add = '[Macro] Add macro',
Select = '[Macro] Select macro',
export namespace MacroActions { AddAction = '[Macro] Add macro action',
export const PREFIX = '[Macro] '; SaveAction = '[Macro] Save macro action',
DeleteAction = '[Macro] Delete macro action',
ReorderAction = '[Macro] Reorder macro action'
}
export const DUPLICATE = MacroActions.PREFIX + 'Duplicate macro'; export class DuplicateMacroAction implements Action {
export const EDIT_NAME = MacroActions.PREFIX + 'Edit macro title'; type = ActionTypes.Duplicate;
export const REMOVE = MacroActions.PREFIX + 'Remove macro';
export const ADD = MacroActions.PREFIX + 'Add macro';
export const ADD_ACTION = MacroActions.PREFIX + 'Add macro action'; constructor(public payload: Macro) {
export const SAVE_ACTION = MacroActions.PREFIX + 'Save macro action';
export const DELETE_ACTION = MacroActions.PREFIX + 'Delete macro action';
export const REORDER_ACTION = MacroActions.PREFIX + 'Reorder macro action';
export function addMacro(): MacroAction {
return {
type: MacroActions.ADD
};
}
export function removeMacro(macroId: number): MacroAction {
return {
type: MacroActions.REMOVE,
payload: macroId
};
}
export function duplicateMacro(macro: Macro): MacroAction {
return {
type: MacroActions.DUPLICATE,
payload: macro
};
}
export function editMacroName(id: number, name: string): MacroAction {
return {
type: MacroActions.EDIT_NAME,
payload: {
id: id,
name: name
}
};
}
export function addMacroAction(id: number, action: ConfigItemMacroAction): MacroAction {
return {
type: MacroActions.ADD_ACTION,
payload: {
id: id,
action: action
}
};
}
export function saveMacroAction(id: number, index: number, action: ConfigItemMacroAction): MacroAction {
return {
type: MacroActions.SAVE_ACTION,
payload: {
id: id,
index: index,
action: action
}
};
}
export function deleteMacroAction(id: number, index: number, action: ConfigItemMacroAction): MacroAction {
return {
type: MacroActions.DELETE_ACTION,
payload: {
id: id,
index: index,
action: action
}
};
}
export function reorderMacroAction(id: number, oldIndex: number, newIndex: number): MacroAction {
return {
type: MacroActions.REORDER_ACTION,
payload: {
id: id,
oldIndex: oldIndex,
newIndex: newIndex
}
};
} }
} }
export class AddMacroAction implements Action {
type = ActionTypes.Add;
}
export class RemoveMacroAction implements Action {
type = ActionTypes.Remove;
constructor(public payload: number) {
}
}
export class EditMacroNameAction implements Action {
type = ActionTypes.EditName;
constructor(public payload: { id: number, name: string }) {
}
}
export class SelectMacroAction implements Action {
type = ActionTypes.Select;
constructor(public payload: number) {
}
}
export class AddMacroActionAction implements Action {
type = ActionTypes.AddAction;
constructor(public payload: { id: number, action: ConfigItemMacroAction }) {
}
}
export class SaveMacroActionAction implements Action {
type = ActionTypes.SaveAction;
constructor(public payload: { id: number, index: number, action: ConfigItemMacroAction }) {
}
}
export class DeleteMacroActionAction implements Action {
type = ActionTypes.DeleteAction;
constructor(public payload: { id: number, index: number, action: ConfigItemMacroAction }) {
}
}
export class ReorderMacroActionAction implements Action {
type = ActionTypes.ReorderAction;
constructor(public payload: { id: number, oldIndex: number, newIndex: number }) {
}
}
export type Actions
= DuplicateMacroAction
| AddMacroAction
| RemoveMacroAction
| EditMacroNameAction
| SelectMacroAction
| AddMacroActionAction
| SaveMacroActionAction
| DeleteMacroActionAction
| ReorderMacroActionAction
;

View File

@@ -1,93 +1,90 @@
import { Action } from '@ngrx/store'; import { Action } from '@ngrx/store';
import { type, UserConfiguration, ConfigurationReply } from 'uhk-common'; import { UserConfiguration, ConfigurationReply } from 'uhk-common';
import { UserConfigurationValue } from '../../models/user-configuration-value'; import { UserConfigurationValue } from '../../models/user-configuration-value';
import { UploadFileData } from '../../models/upload-file-data'; import { UploadFileData } from '../../models/upload-file-data';
const PREFIX = '[user-config] '; export enum ActionTypes {
LoadUserConfig = '[user-config] Load User Config',
// tslint:disable-next-line:variable-name LoadConfigFromDevice = '[user-config] Load User Config from Device',
export const ActionTypes = { LoadConfigFromDeviceReply = '[user-config] Load User Config from Device reply',
LOAD_USER_CONFIG: type(PREFIX + 'Load User Config'), LoadUserConfigSuccess = '[user-config] Load User Config Success',
LOAD_CONFIG_FROM_DEVICE: type(PREFIX + 'Load User Config from Device'), SaveUserConfigSuccess = '[user-config] Save User Config Success',
LOAD_CONFIG_FROM_DEVICE_REPLY: type(PREFIX + 'Load User Config from Device reply'), SaveUserConfigInJsonFile = '[user-config] Save User Config in JSON file',
LOAD_USER_CONFIG_SUCCESS: type(PREFIX + 'Load User Config Success'), SaveUserConfigInBinFile = '[user-config] Save User Config in binary file',
SAVE_USER_CONFIG_SUCCESS: type(PREFIX + 'Save User Config Success'), LoadResetUserConfiguration = '[user-config] Load reset user configuration',
SAVE_USER_CONFIG_IN_JSON_FILE: type(PREFIX + 'Save User Config in JSON file'), RenameUserConfiguration = '[user-config] Rename user configuration',
SAVE_USER_CONFIG_IN_BIN_FILE: type(PREFIX + 'Save User Config in binary file'), SetUserConfigurationValue = '[user-config] Set user configuration value',
LOAD_RESET_USER_CONFIGURATION: type(PREFIX + 'Load reset user configuration'), LoadUserConfigurationFromFile = '[user-config] Load user configuration from file',
RENAME_USER_CONFIGURATION: type(PREFIX + 'Rename user configuration'), ApplyUserConfigurationFromFile = '[user-config] Apply user configuration from file'
SET_USER_CONFIGURATION_VALUE: type(PREFIX + 'Set user configuration value'), }
LOAD_USER_CONFIGURATION_FROM_FILE: type(PREFIX + 'Load user configuration from file'),
APPLY_USER_CONFIGURATION_FROM_FILE: type(PREFIX + 'Apply user configuration from file')
};
export class LoadUserConfigAction implements Action { export class LoadUserConfigAction implements Action {
type = ActionTypes.LOAD_USER_CONFIG; type = ActionTypes.LoadUserConfig;
} }
export class LoadConfigFromDeviceAction implements Action { export class LoadConfigFromDeviceAction implements Action {
type = ActionTypes.LOAD_CONFIG_FROM_DEVICE; type = ActionTypes.LoadConfigFromDevice;
} }
export class LoadConfigFromDeviceReplyAction implements Action { export class LoadConfigFromDeviceReplyAction implements Action {
type = ActionTypes.LOAD_CONFIG_FROM_DEVICE_REPLY; type = ActionTypes.LoadConfigFromDeviceReply;
constructor(public payload: ConfigurationReply) { constructor(public payload: ConfigurationReply) {
} }
} }
export class LoadUserConfigSuccessAction implements Action { export class LoadUserConfigSuccessAction implements Action {
type = ActionTypes.LOAD_USER_CONFIG_SUCCESS; type = ActionTypes.LoadUserConfigSuccess;
constructor(public payload: UserConfiguration) { constructor(public payload: UserConfiguration) {
} }
} }
export class SaveUserConfigSuccessAction implements Action { export class SaveUserConfigSuccessAction implements Action {
type = ActionTypes.SAVE_USER_CONFIG_SUCCESS; type = ActionTypes.SaveUserConfigSuccess;
constructor(public payload: UserConfiguration) { constructor(public payload: UserConfiguration) {
} }
} }
export class SaveUserConfigInJsonFileAction implements Action { export class SaveUserConfigInJsonFileAction implements Action {
type = ActionTypes.SAVE_USER_CONFIG_IN_JSON_FILE; type = ActionTypes.SaveUserConfigInJsonFile;
} }
export class SaveUserConfigInBinaryFileAction implements Action { export class SaveUserConfigInBinaryFileAction implements Action {
type = ActionTypes.SAVE_USER_CONFIG_IN_BIN_FILE; type = ActionTypes.SaveUserConfigInBinFile;
} }
export class LoadResetUserConfigurationAction implements Action { export class LoadResetUserConfigurationAction implements Action {
type = ActionTypes.LOAD_RESET_USER_CONFIGURATION; type = ActionTypes.LoadResetUserConfiguration;
constructor(public payload: UserConfiguration) { constructor(public payload: UserConfiguration) {
} }
} }
export class RenameUserConfigurationAction implements Action { export class RenameUserConfigurationAction implements Action {
type = ActionTypes.RENAME_USER_CONFIGURATION; type = ActionTypes.RenameUserConfiguration;
constructor(public payload: string) { constructor(public payload: string) {
} }
} }
export class SetUserConfigurationValueAction implements Action { export class SetUserConfigurationValueAction implements Action {
type = ActionTypes.SET_USER_CONFIGURATION_VALUE; type = ActionTypes.SetUserConfigurationValue;
constructor(public payload: UserConfigurationValue) { constructor(public payload: UserConfigurationValue) {
} }
} }
export class LoadUserConfigurationFromFileAction implements Action { export class LoadUserConfigurationFromFileAction implements Action {
type = ActionTypes.LOAD_USER_CONFIGURATION_FROM_FILE; type = ActionTypes.LoadUserConfigurationFromFile;
constructor(public payload: UploadFileData) { constructor(public payload: UploadFileData) {
} }
} }
export class ApplyUserConfigurationFromFileAction implements Action { export class ApplyUserConfigurationFromFileAction implements Action {
type = ActionTypes.APPLY_USER_CONFIGURATION_FROM_FILE; type = ActionTypes.ApplyUserConfigurationFromFile;
constructor(public payload: UserConfiguration) { constructor(public payload: UserConfiguration) {
} }

View File

@@ -15,7 +15,7 @@ import { AppUpdateRendererService } from '../../services/app-update-renderer.ser
export class AppUpdateEffect { export class AppUpdateEffect {
@Effect({ dispatch: false }) @Effect({ dispatch: false })
appStart$: Observable<Action> = this.actions$ appStart$: Observable<Action> = this.actions$
.ofType(ActionTypes.UPDATE_APP) .ofType(ActionTypes.UpdateApp)
.pipe( .pipe(
first(), first(),
tap(() => { tap(() => {
@@ -24,7 +24,7 @@ export class AppUpdateEffect {
); );
@Effect({ dispatch: false }) checkForUpdate$ = this.actions$ @Effect({ dispatch: false }) checkForUpdate$ = this.actions$
.ofType<CheckForUpdateNowAction>(AutoUpdateActionTypes.CHECK_FOR_UPDATE_NOW) .ofType<CheckForUpdateNowAction>(AutoUpdateActionTypes.CheckForUpdateNow)
.pipe( .pipe(
map(action => action.payload), map(action => action.payload),
tap((allowPrerelease: boolean) => { tap((allowPrerelease: boolean) => {
@@ -34,7 +34,7 @@ export class AppUpdateEffect {
); );
@Effect() handleError$: Observable<Action> = this.actions$ @Effect() handleError$: Observable<Action> = this.actions$
.ofType<UpdateErrorAction>(ActionTypes.UPDATE_ERROR) .ofType<UpdateErrorAction>(ActionTypes.UpdateError)
.pipe( .pipe(
map(action => action.payload), map(action => action.payload),
map((message: string) => { map((message: string) => {

View File

@@ -26,7 +26,7 @@ export class ApplicationEffects {
@Effect() @Effect()
appStart$: Observable<Action> = this.actions$ appStart$: Observable<Action> = this.actions$
.ofType(ActionTypes.APP_BOOTSRAPPED) .ofType(ActionTypes.AppBootstrapped)
.pipe( .pipe(
startWith(new AppStartedAction()), startWith(new AppStartedAction()),
tap(() => { tap(() => {
@@ -39,14 +39,14 @@ export class ApplicationEffects {
@Effect({dispatch: false}) @Effect({dispatch: false})
appStartInfo$: Observable<Action> = this.actions$ appStartInfo$: Observable<Action> = this.actions$
.ofType(ActionTypes.LOAD_APP_START_INFO) .ofType(ActionTypes.LoadAppStartInfo)
.do(() => { .do(() => {
this.appRendererService.getAppStartInfo(); this.appRendererService.getAppStartInfo();
}); });
@Effect({dispatch: false}) @Effect({dispatch: false})
showNotification$: Observable<Action> = this.actions$ showNotification$: Observable<Action> = this.actions$
.ofType<ShowNotificationAction>(ActionTypes.APP_SHOW_NOTIFICATION) .ofType<ShowNotificationAction>(ActionTypes.AppShowNotification)
.pipe( .pipe(
map(action => action.payload), map(action => action.payload),
tap((notification: Notification) => { tap((notification: Notification) => {
@@ -59,7 +59,7 @@ export class ApplicationEffects {
@Effect() @Effect()
processStartInfo$: Observable<Action> = this.actions$ processStartInfo$: Observable<Action> = this.actions$
.ofType<ProcessAppStartInfoAction>(ActionTypes.APP_PROCESS_START_INFO) .ofType<ProcessAppStartInfoAction>(ActionTypes.AppProcessStartInfo)
.map(action => action.payload) .map(action => action.payload)
.mergeMap((appInfo: AppStartInfo) => { .mergeMap((appInfo: AppStartInfo) => {
this.logService.debug('[AppEffect][processStartInfo] payload:', appInfo); this.logService.debug('[AppEffect][processStartInfo] payload:', appInfo);
@@ -70,12 +70,12 @@ export class ApplicationEffects {
}); });
@Effect() undoLastNotification$: Observable<Action> = this.actions$ @Effect() undoLastNotification$: Observable<Action> = this.actions$
.ofType<UndoLastAction>(ActionTypes.UNDO_LAST) .ofType<UndoLastAction>(ActionTypes.UndoLast)
.map(action => action.payload) .map(action => action.payload)
.mergeMap((action: Action) => [action, new DismissUndoNotificationAction()]); .mergeMap((action: Action) => [action, new DismissUndoNotificationAction()]);
@Effect({dispatch: false}) openUrlInNewWindow$ = this.actions$ @Effect({dispatch: false}) openUrlInNewWindow$ = this.actions$
.ofType<OpenUrlInNewWindowAction>(ActionTypes.OPEN_URL_IN_NEW_WINDOW) .ofType<OpenUrlInNewWindowAction>(ActionTypes.OpenUrlInNewWindow)
.pipe( .pipe(
withLatestFrom(this.store.select(runningInElectron)), withLatestFrom(this.store.select(runningInElectron)),
tap(([action, inElectron]) => { tap(([action, inElectron]) => {

View File

@@ -21,7 +21,7 @@ import { ShowNotificationAction } from '../actions/app';
@Injectable() @Injectable()
export class AutoUpdateSettingsEffects { export class AutoUpdateSettingsEffects {
@Effect() loadUserConfig$: Observable<Action> = this.actions$ @Effect() loadUserConfig$: Observable<Action> = this.actions$
.ofType(ActionTypes.LOAD_AUTO_UPDATE_SETTINGS) .ofType(ActionTypes.LoadAutoUpdateSettings)
.pipe( .pipe(
startWith(new LoadAutoUpdateSettingsAction()), startWith(new LoadAutoUpdateSettingsAction()),
switchMap(() => { switchMap(() => {
@@ -34,7 +34,7 @@ export class AutoUpdateSettingsEffects {
); );
@Effect() saveAutoUpdateConfig$: Observable<Action> = this.actions$ @Effect() saveAutoUpdateConfig$: Observable<Action> = this.actions$
.ofType(ActionTypes.TOGGLE_CHECK_FOR_UPDATE_ON_STARTUP, ActionTypes.TOGGLE_PRE_RELEASE_FLAG) .ofType(ActionTypes.ToggleCheckForUpdateOnStartup, ActionTypes.TogglePreReleaseFlag)
.pipe( .pipe(
withLatestFrom(this.store.select(getAutoUpdateSettings)), withLatestFrom(this.store.select(getAutoUpdateSettings)),
map(([action, config]) => { map(([action, config]) => {
@@ -44,7 +44,7 @@ export class AutoUpdateSettingsEffects {
); );
@Effect() sendNotification$: Observable<Action> = this.actions$ @Effect() sendNotification$: Observable<Action> = this.actions$
.ofType(ActionTypes.CHECK_FOR_UPDATE_FAILED, ActionTypes.CHECK_FOR_UPDATE_SUCCESS) .ofType(ActionTypes.CheckForUpdateFailed, ActionTypes.CheckForUpdateSuccess)
.pipe( .pipe(
map(toPayload), map(toPayload),
map((message: string) => { map((message: string) => {

View File

@@ -23,7 +23,7 @@ import {
@Injectable() @Injectable()
export class ContributorsEffect { export class ContributorsEffect {
@Effect() getContributors$: Observable<Action> = this.actions$ @Effect() getContributors$: Observable<Action> = this.actions$
.ofType<GetAgentContributorsAction>(ActionTypes.GET_AGENT_CONTRIBUTORS) .ofType<GetAgentContributorsAction>(ActionTypes.GetAgentContributors)
.pipe( .pipe(
withLatestFrom(this.store.select(contributors)), withLatestFrom(this.store.select(contributors)),
map(([action, state]) => { map(([action, state]) => {
@@ -35,7 +35,7 @@ export class ContributorsEffect {
); );
@Effect() fetchContributors$: Observable<Action> = this.actions$ @Effect() fetchContributors$: Observable<Action> = this.actions$
.ofType<FetchAgentContributorsAction>(ActionTypes.FETCH_AGENT_CONTRIBUTORS) .ofType<FetchAgentContributorsAction>(ActionTypes.FetchAgentContributors)
.pipe( .pipe(
mergeMap(() => this.http.get<UHKContributor[]>(Constants.AGENT_CONTRIBUTORS_GITHUB_API_URL)), mergeMap(() => this.http.get<UHKContributor[]>(Constants.AGENT_CONTRIBUTORS_GITHUB_API_URL)),
switchMap((response: UHKContributor[]) => { switchMap((response: UHKContributor[]) => {

View File

@@ -52,7 +52,7 @@ import { getVersions } from '../../util';
export class DeviceEffects { export class DeviceEffects {
@Effect() @Effect()
deviceConnectionStateChange$: Observable<Action> = this.actions$ deviceConnectionStateChange$: Observable<Action> = this.actions$
.ofType<ConnectionStateChangedAction>(ActionTypes.CONNECTION_STATE_CHANGED) .ofType<ConnectionStateChangedAction>(ActionTypes.ConnectionStateChanged)
.pipe( .pipe(
withLatestFrom(this.store.select(getRouterState), this.store.select(deviceConnected)), withLatestFrom(this.store.select(getRouterState), this.store.select(deviceConnected)),
tap(([action, route]) => { tap(([action, route]) => {
@@ -93,7 +93,7 @@ export class DeviceEffects {
@Effect({ dispatch: false }) @Effect({ dispatch: false })
setPrivilegeOnLinux$: Observable<Action> = this.actions$ setPrivilegeOnLinux$: Observable<Action> = this.actions$
.ofType(ActionTypes.SET_PRIVILEGE_ON_LINUX) .ofType(ActionTypes.SetPrivilegeOnLinux)
.pipe( .pipe(
tap(() => { tap(() => {
this.deviceRendererService.setPrivilegeOnLinux(); this.deviceRendererService.setPrivilegeOnLinux();
@@ -102,7 +102,7 @@ export class DeviceEffects {
@Effect() @Effect()
setPrivilegeOnLinuxReply$: Observable<Action> = this.actions$ setPrivilegeOnLinuxReply$: Observable<Action> = this.actions$
.ofType<SetPrivilegeOnLinuxReplyAction>(ActionTypes.SET_PRIVILEGE_ON_LINUX_REPLY) .ofType<SetPrivilegeOnLinuxReplyAction>(ActionTypes.SetPrivilegeOnLinuxReply)
.pipe( .pipe(
map(action => action.payload), map(action => action.payload),
switchMap((response: any): any => { switchMap((response: any): any => {
@@ -117,18 +117,21 @@ export class DeviceEffects {
@Effect({ dispatch: false }) @Effect({ dispatch: false })
saveConfiguration$: Observable<Action> = this.actions$ saveConfiguration$: Observable<Action> = this.actions$
.ofType(ActionTypes.SAVE_CONFIGURATION) .ofType(ActionTypes.SaveConfiguration)
.pipe( .pipe(
withLatestFrom(this.store), withLatestFrom(this.store),
tap(([action, state]) => { tap(([action, state]) => {
setTimeout(() => this.sendUserConfigToKeyboard(state.userConfiguration, state.app.hardwareConfig), 100); setTimeout(() => this.sendUserConfigToKeyboard(
state.userConfiguration.userConfiguration,
state.app.hardwareConfig),
100);
}), }),
switchMap(() => empty()) switchMap(() => empty())
); );
@Effect() @Effect()
saveConfigurationReply$: Observable<Action> = this.actions$ saveConfigurationReply$: Observable<Action> = this.actions$
.ofType<SaveConfigurationReplyAction>(ActionTypes.SAVE_CONFIGURATION_REPLY) .ofType<SaveConfigurationReplyAction>(ActionTypes.SaveConfigurationReply)
.pipe( .pipe(
map(action => action.payload), map(action => action.payload),
mergeMap((response: IpcResponse) => { mergeMap((response: IpcResponse) => {
@@ -150,7 +153,7 @@ export class DeviceEffects {
@Effect() @Effect()
autoHideSaveToKeyboardButton$: Observable<Action> = this.actions$ autoHideSaveToKeyboardButton$: Observable<Action> = this.actions$
.ofType(ActionTypes.SAVE_TO_KEYBOARD_SUCCESS) .ofType(ActionTypes.SaveToKeyboardSuccess)
.pipe( .pipe(
withLatestFrom(this.store), withLatestFrom(this.store),
switchMap(([action, state]) => timer(1000) switchMap(([action, state]) => timer(1000)
@@ -169,7 +172,7 @@ export class DeviceEffects {
@Effect() @Effect()
resetMouseSpeedSettings$: Observable<Action> = this.actions$ resetMouseSpeedSettings$: Observable<Action> = this.actions$
.ofType(ActionTypes.RESET_MOUSE_SPEED_SETTINGS) .ofType(ActionTypes.ResetMouseSpeedSettings)
.pipe( .pipe(
switchMap(() => { switchMap(() => {
const config = this.defaultUserConfigurationService.getDefault(); const config = this.defaultUserConfigurationService.getDefault();
@@ -194,7 +197,7 @@ export class DeviceEffects {
); );
@Effect() resetUserConfiguration$: Observable<Action> = this.actions$ @Effect() resetUserConfiguration$: Observable<Action> = this.actions$
.ofType(ActionTypes.RESET_USER_CONFIGURATION) .ofType(ActionTypes.ResetUserConfiguration)
.pipe( .pipe(
switchMap(() => { switchMap(() => {
const config = this.defaultUserConfigurationService.getDefault(); const config = this.defaultUserConfigurationService.getDefault();
@@ -205,8 +208,8 @@ export class DeviceEffects {
@Effect() saveResetUserConfigurationToDevice$ = this.actions$ @Effect() saveResetUserConfigurationToDevice$ = this.actions$
.ofType<ApplyUserConfigurationFromFileAction .ofType<ApplyUserConfigurationFromFileAction
| LoadResetUserConfigurationAction>( | LoadResetUserConfigurationAction>(
UserConfigActions.LOAD_RESET_USER_CONFIGURATION, UserConfigActions.LoadResetUserConfiguration,
UserConfigActions.APPLY_USER_CONFIGURATION_FROM_FILE) UserConfigActions.ApplyUserConfigurationFromFile)
.pipe( .pipe(
map(action => action.payload), map(action => action.payload),
switchMap((config: UserConfiguration) => { switchMap((config: UserConfiguration) => {
@@ -217,7 +220,7 @@ export class DeviceEffects {
); );
@Effect({ dispatch: false }) updateFirmware$ = this.actions$ @Effect({ dispatch: false }) updateFirmware$ = this.actions$
.ofType<UpdateFirmwareAction>(ActionTypes.UPDATE_FIRMWARE) .ofType<UpdateFirmwareAction>(ActionTypes.UpdateFirmware)
.pipe( .pipe(
tap(() => this.deviceRendererService.updateFirmware({ tap(() => this.deviceRendererService.updateFirmware({
versionInformation: getVersions() versionInformation: getVersions()
@@ -225,7 +228,7 @@ export class DeviceEffects {
); );
@Effect({ dispatch: false }) updateFirmwareWith$ = this.actions$ @Effect({ dispatch: false }) updateFirmwareWith$ = this.actions$
.ofType<UpdateFirmwareWithAction>(ActionTypes.UPDATE_FIRMWARE_WITH) .ofType<UpdateFirmwareWithAction>(ActionTypes.UpdateFirmwareWith)
.pipe( .pipe(
map(action => action.payload), map(action => action.payload),
tap(data => this.deviceRendererService.updateFirmware({ tap(data => this.deviceRendererService.updateFirmware({
@@ -235,7 +238,7 @@ export class DeviceEffects {
); );
@Effect() updateFirmwareReply$ = this.actions$ @Effect() updateFirmwareReply$ = this.actions$
.ofType<UpdateFirmwareReplyAction>(ActionTypes.UPDATE_FIRMWARE_REPLY) .ofType<UpdateFirmwareReplyAction>(ActionTypes.UpdateFirmwareReply)
.pipe( .pipe(
map(action => action.payload), map(action => action.payload),
switchMap((response: FirmwareUpgradeIpcResponse) switchMap((response: FirmwareUpgradeIpcResponse)
@@ -253,25 +256,25 @@ export class DeviceEffects {
); );
@Effect() restoreUserConfiguration$ = this.actions$ @Effect() restoreUserConfiguration$ = this.actions$
.ofType<ResetUserConfigurationAction>(ActionTypes.RESTORE_CONFIGURATION_FROM_BACKUP) .ofType<ResetUserConfigurationAction>(ActionTypes.RestoreConfigurationFromBackup)
.pipe( .pipe(
map(() => new SaveConfigurationAction()) map(() => new SaveConfigurationAction())
); );
@Effect({ dispatch: false }) recoveryDevice$ = this.actions$ @Effect({ dispatch: false }) recoveryDevice$ = this.actions$
.ofType<RecoveryDeviceAction>(ActionTypes.RECOVERY_DEVICE) .ofType<RecoveryDeviceAction>(ActionTypes.RecoveryDevice)
.pipe( .pipe(
tap(() => this.deviceRendererService.recoveryDevice()) tap(() => this.deviceRendererService.recoveryDevice())
); );
@Effect({ dispatch: false }) enableUsbStackTest$ = this.actions$ @Effect({ dispatch: false }) enableUsbStackTest$ = this.actions$
.ofType<EnableUsbStackTestAction>(ActionTypes.ENABLE_USB_STACK_TEST) .ofType<EnableUsbStackTestAction>(ActionTypes.EnableUsbStackTest)
.pipe( .pipe(
tap(() => this.deviceRendererService.enableUsbStackTest()) tap(() => this.deviceRendererService.enableUsbStackTest())
); );
@Effect({ dispatch: false }) startConnectionPoller$ = this.actions$ @Effect({ dispatch: false }) startConnectionPoller$ = this.actions$
.ofType(ActionTypes.START_CONNECTION_POLLER) .ofType(ActionTypes.StartConnectionPoller)
.pipe( .pipe(
tap(() => this.deviceRendererService.startConnectionPoller()) tap(() => this.deviceRendererService.startConnectionPoller())
); );

View File

@@ -9,30 +9,29 @@ import { map, pairwise, startWith, switchMap, tap, withLatestFrom } from 'rxjs/o
import { Keymap } from 'uhk-common'; import { Keymap } from 'uhk-common';
import { findNewItem } from '../../util'; import { findNewItem } from '../../util';
import { KeymapActions } from '../actions'; import * as Keymaps from '../actions/keymap';
import { AppState } from '../index'; import { AppState, getKeymaps } from '../index';
import { getKeymaps } from '../reducers/user-configuration';
@Injectable() @Injectable()
export class KeymapEffects { export class KeymapEffects {
@Effect() loadKeymaps$: Observable<Action> = this.actions$ @Effect() loadKeymaps$: Observable<Action> = this.actions$
.ofType(KeymapActions.LOAD_KEYMAPS) .ofType(Keymaps.ActionTypes.LoadKeymaps)
.pipe( .pipe(
startWith(KeymapActions.loadKeymaps()), startWith(new Keymaps.LoadKeymapsAction()),
switchMap(() => { switchMap(() => {
const presetsRequireContext = (<any>require).context('../../../res/presets', false, /.json$/); const presetsRequireContext = (<any>require).context('../../../res/presets', false, /.json$/);
const uhkPresets = presetsRequireContext.keys().map(presetsRequireContext) // load the presets into an array const uhkPresets = presetsRequireContext.keys().map(presetsRequireContext) // load the presets into an array
.map((keymap: any) => new Keymap().fromJsonObject(keymap)); .map((keymap: any) => new Keymap().fromJsonObject(keymap));
return of(KeymapActions.loadKeymapsSuccess(uhkPresets)); return of(new Keymaps.LoadKeymapSuccessAction(uhkPresets));
}) })
); );
@Effect({ dispatch: false }) addOrDuplicate$: any = this.actions$ @Effect({ dispatch: false }) addOrDuplicate$: any = this.actions$
.ofType(KeymapActions.ADD, KeymapActions.DUPLICATE) .ofType(Keymaps.ActionTypes.Add, Keymaps.ActionTypes.Duplicate)
.pipe( .pipe(
withLatestFrom(this.store.let(getKeymaps()) withLatestFrom(this.store.select(getKeymaps)
.pipe( .pipe(
pairwise() pairwise()
) )
@@ -45,10 +44,10 @@ export class KeymapEffects {
); );
@Effect({ dispatch: false }) remove$: any = this.actions$ @Effect({ dispatch: false }) remove$: any = this.actions$
.ofType(KeymapActions.REMOVE) .ofType(Keymaps.ActionTypes.Remove)
.pipe( .pipe(
withLatestFrom(this.store), withLatestFrom(this.store.select(getKeymaps)),
map(latest => latest[1].userConfiguration.keymaps), map(latest => latest[1]),
tap(keymaps => { tap(keymaps => {
if (keymaps.length === 0) { if (keymaps.length === 0) {
this.router.navigate(['/keymap/add']); this.router.navigate(['/keymap/add']);
@@ -60,11 +59,11 @@ export class KeymapEffects {
); );
@Effect({ dispatch: false }) editAbbr$: any = this.actions$ @Effect({ dispatch: false }) editAbbr$: any = this.actions$
.ofType(KeymapActions.EDIT_ABBR) .ofType(Keymaps.ActionTypes.EditAbbr)
.pipe( .pipe(
withLatestFrom(this.store), withLatestFrom(this.store.select(getKeymaps)),
tap(([action, store]: [KeymapActions.EditKeymapAbbreviationAction, AppState]) => { tap(([action, keymaps]: [Keymaps.EditKeymapAbbreviationAction, Keymap[]]) => {
for (const keymap of store.userConfiguration.keymaps) { for (const keymap of keymaps) {
if (keymap.name === action.payload.name && keymap.abbreviation === action.payload.newAbbr) { if (keymap.name === action.payload.name && keymap.abbreviation === action.payload.newAbbr) {
this.router.navigate(['/keymap', action.payload.newAbbr]); this.router.navigate(['/keymap', action.payload.newAbbr]);
return; return;

View File

@@ -6,20 +6,20 @@ import { Store, Action } from '@ngrx/store';
import { map, pairwise, tap, withLatestFrom } from 'rxjs/operators'; import { map, pairwise, tap, withLatestFrom } from 'rxjs/operators';
import { Macro } from 'uhk-common'; import { Macro } from 'uhk-common';
import { KeymapActions, MacroAction, MacroActions } from '../actions'; import * as Keymaps from '../actions/keymap';
import { AppState } from '../index'; import * as Macros from '../actions/macro';
import { getMacros } from '../reducers/user-configuration'; import { AppState, getMacros } from '..';
import { findNewItem } from '../../util'; import { findNewItem } from '../../util';
@Injectable() @Injectable()
export class MacroEffects { export class MacroEffects {
@Effect({ dispatch: false }) remove$: any = this.actions$ @Effect({ dispatch: false }) remove$: any = this.actions$
.ofType<MacroAction>(MacroActions.REMOVE) .ofType<Macros.RemoveMacroAction>(Macros.ActionTypes.Remove)
.pipe( .pipe(
tap(action => this.store.dispatch(KeymapActions.checkMacro(action.payload))), tap(action => this.store.dispatch(new Keymaps.CheckMacroAction(action.payload))),
withLatestFrom(this.store), withLatestFrom(this.store.select(getMacros)),
map(([action, state]) => state.userConfiguration.macros), map(([action, macros]) => macros),
tap(macros => { tap(macros => {
if (macros.length === 0) { if (macros.length === 0) {
return this.router.navigate(['/macro']); return this.router.navigate(['/macro']);
@@ -31,9 +31,9 @@ export class MacroEffects {
); );
@Effect({ dispatch: false }) addOrDuplicate$: any = this.actions$ @Effect({ dispatch: false }) addOrDuplicate$: any = this.actions$
.ofType<MacroAction>(MacroActions.ADD, MacroActions.DUPLICATE) .ofType(Macros.ActionTypes.Add, Macros.ActionTypes.Duplicate)
.pipe( .pipe(
withLatestFrom(this.store.let(getMacros()) withLatestFrom(this.store.select(getMacros)
.pipe( .pipe(
pairwise() pairwise()
) )
@@ -42,7 +42,7 @@ export class MacroEffects {
tap(([action, prevMacros, newMacros]: [Action, Macro[], Macro[]]) => { tap(([action, prevMacros, newMacros]: [Action, Macro[], Macro[]]) => {
const newMacro = findNewItem(prevMacros, newMacros); const newMacro = findNewItem(prevMacros, newMacros);
const commands = ['/macro', newMacro.id]; const commands = ['/macro', newMacro.id];
if (action.type === MacroActions.ADD) { if (action.type === Macros.ActionTypes.Add) {
commands.push('new'); commands.push('new');
} }
this.router.navigate(commands); this.router.navigate(commands);

View File

@@ -31,7 +31,8 @@ import {
import { DataStorageRepositoryService } from '../../services/datastorage-repository.service'; import { DataStorageRepositoryService } from '../../services/datastorage-repository.service';
import { DefaultUserConfigurationService } from '../../services/default-user-configuration.service'; import { DefaultUserConfigurationService } from '../../services/default-user-configuration.service';
import { AppState, getPrevUserConfiguration, getRouterState, getUserConfiguration } from '../index'; import { AppState, getPrevUserConfiguration, getRouterState, getUserConfiguration } from '../index';
import { KeymapAction, KeymapActions, MacroAction, MacroActions } from '../actions'; import * as Keymaps from '../actions/keymap';
import * as Macros from '../actions/macro';
import { import {
DismissUndoNotificationAction, DismissUndoNotificationAction,
LoadHardwareConfigurationSuccessAction, LoadHardwareConfigurationSuccessAction,
@@ -56,23 +57,25 @@ export class UserConfigEffects {
@Effect() saveUserConfig$: Observable<Action> = (this.actions$ @Effect() saveUserConfig$: Observable<Action> = (this.actions$
.ofType( .ofType(
KeymapActions.ADD, KeymapActions.DUPLICATE, KeymapActions.EDIT_NAME, KeymapActions.EDIT_ABBR, Keymaps.ActionTypes.Add, Keymaps.ActionTypes.Duplicate, Keymaps.ActionTypes.EditName, Keymaps.ActionTypes.EditAbbr,
KeymapActions.SET_DEFAULT, KeymapActions.REMOVE, KeymapActions.SAVE_KEY, KeymapActions.EDIT_DESCRIPTION, Keymaps.ActionTypes.SetDefault, Keymaps.ActionTypes.Remove, Keymaps.ActionTypes.SaveKey,
MacroActions.ADD, MacroActions.DUPLICATE, MacroActions.EDIT_NAME, MacroActions.REMOVE, MacroActions.ADD_ACTION, Keymaps.ActionTypes.EditDescription,
MacroActions.SAVE_ACTION, MacroActions.DELETE_ACTION, MacroActions.REORDER_ACTION, Macros.ActionTypes.Add, Macros.ActionTypes.Duplicate, Macros.ActionTypes.EditName, Macros.ActionTypes.Remove,
ActionTypes.RENAME_USER_CONFIGURATION, ActionTypes.SET_USER_CONFIGURATION_VALUE Macros.ActionTypes.AddAction, Macros.ActionTypes.SaveAction, Macros.ActionTypes.DeleteAction,
) as Observable<KeymapAction | MacroAction | RenameUserConfigurationAction>) Macros.ActionTypes.ReorderAction,
ActionTypes.RenameUserConfiguration, ActionTypes.SetUserConfigurationValue
) as Observable<Keymaps.Actions | Macros.Actions | RenameUserConfigurationAction>)
.pipe( .pipe(
withLatestFrom(this.store.select(getUserConfiguration), this.store.select(getPrevUserConfiguration)), withLatestFrom(this.store.select(getUserConfiguration), this.store.select(getPrevUserConfiguration)),
mergeMap(([action, config, prevUserConfiguration]) => { mergeMap(([action, config, prevUserConfiguration]) => {
config.recalculateConfigurationLength(); config.recalculateConfigurationLength();
this.dataStorageRepository.saveConfig(config); this.dataStorageRepository.saveConfig(config);
if (action.type === KeymapActions.REMOVE || action.type === MacroActions.REMOVE) { if (action.type === Keymaps.ActionTypes.Remove || action.type === Macros.ActionTypes.Remove) {
const text = action.type === KeymapActions.REMOVE ? 'Keymap' : 'Macro'; const text = action.type === Keymaps.ActionTypes.Remove ? 'Keymap' : 'Macro';
const pathPrefix = action.type === KeymapActions.REMOVE ? 'keymap' : 'macro'; const pathPrefix = action.type === Keymaps.ActionTypes.Remove ? 'keymap' : 'macro';
const payload: UndoUserConfigData = { const payload: UndoUserConfigData = {
path: `/${pathPrefix}/${action.payload}`, path: `/${pathPrefix}/${(action as Keymaps.RemoveKeymapAction | Macros.RemoveMacroAction).payload}`,
config: prevUserConfiguration.toJsonObject() config: prevUserConfiguration.toJsonObject()
}; };
@@ -83,7 +86,7 @@ export class UserConfigEffects {
message: `${text} has been deleted`, message: `${text} has been deleted`,
extra: { extra: {
payload, payload,
type: KeymapActions.UNDO_LAST_ACTION type: Keymaps.ActionTypes.UndoLastAction
} }
}), }),
new ShowSaveToKeyboardButtonAction() new ShowSaveToKeyboardButtonAction()
@@ -99,7 +102,7 @@ export class UserConfigEffects {
); );
@Effect() undoUserConfig$: Observable<Action> = this.actions$ @Effect() undoUserConfig$: Observable<Action> = this.actions$
.ofType<UndoLastAction>(KeymapActions.UNDO_LAST_ACTION) .ofType<UndoLastAction>(Keymaps.ActionTypes.UndoLastAction)
.pipe( .pipe(
map(action => action.payload), map(action => action.payload),
mergeMap((payload: UndoUserConfigData) => { mergeMap((payload: UndoUserConfigData) => {
@@ -112,13 +115,13 @@ export class UserConfigEffects {
); );
@Effect({ dispatch: false }) loadConfigFromDevice$ = this.actions$ @Effect({ dispatch: false }) loadConfigFromDevice$ = this.actions$
.ofType(ActionTypes.LOAD_CONFIG_FROM_DEVICE) .ofType(ActionTypes.LoadConfigFromDevice)
.pipe( .pipe(
tap(() => this.deviceRendererService.loadConfigurationFromKeyboard()) tap(() => this.deviceRendererService.loadConfigurationFromKeyboard())
); );
@Effect() loadConfigFromDeviceReply$ = this.actions$ @Effect() loadConfigFromDeviceReply$ = this.actions$
.ofType<LoadConfigFromDeviceReplyAction>(ActionTypes.LOAD_CONFIG_FROM_DEVICE_REPLY) .ofType<LoadConfigFromDeviceReplyAction>(ActionTypes.LoadConfigFromDeviceReply)
.pipe( .pipe(
withLatestFrom(this.store.select(getRouterState)), withLatestFrom(this.store.select(getRouterState)),
mergeMap(([action, route]): any => { mergeMap(([action, route]): any => {
@@ -175,7 +178,7 @@ export class UserConfigEffects {
); );
@Effect({ dispatch: false }) saveUserConfigInJsonFile$ = this.actions$ @Effect({ dispatch: false }) saveUserConfigInJsonFile$ = this.actions$
.ofType(ActionTypes.SAVE_USER_CONFIG_IN_JSON_FILE) .ofType(ActionTypes.SaveUserConfigInJsonFile)
.pipe( .pipe(
withLatestFrom(this.store.select(getUserConfiguration)), withLatestFrom(this.store.select(getUserConfiguration)),
tap(([action, userConfiguration]) => { tap(([action, userConfiguration]) => {
@@ -186,7 +189,7 @@ export class UserConfigEffects {
); );
@Effect({ dispatch: false }) saveUserConfigInBinFile$ = this.actions$ @Effect({ dispatch: false }) saveUserConfigInBinFile$ = this.actions$
.ofType(ActionTypes.SAVE_USER_CONFIG_IN_BIN_FILE) .ofType(ActionTypes.SaveUserConfigInBinFile)
.pipe( .pipe(
withLatestFrom(this.store.select(getUserConfiguration)), withLatestFrom(this.store.select(getUserConfiguration)),
tap(([action, userConfiguration]) => { tap(([action, userConfiguration]) => {
@@ -198,7 +201,7 @@ export class UserConfigEffects {
); );
@Effect() loadUserConfigurationFromFile$ = this.actions$ @Effect() loadUserConfigurationFromFile$ = this.actions$
.ofType<LoadUserConfigurationFromFileAction>(ActionTypes.LOAD_USER_CONFIGURATION_FROM_FILE) .ofType<LoadUserConfigurationFromFileAction>(ActionTypes.LoadUserConfigurationFromFile)
.pipe( .pipe(
map(action => action.payload), map(action => action.payload),
map((info: UploadFileData) => { map((info: UploadFileData) => {

View File

@@ -1,5 +1,4 @@
import { createSelector } from 'reselect'; import { ActionReducerMap, createSelector, MetaReducer } from '@ngrx/store';
import { ActionReducerMap, MetaReducer } from '@ngrx/store';
import { routerReducer, RouterReducerState } from '@ngrx/router-store'; import { routerReducer, RouterReducerState } from '@ngrx/router-store';
import { storeFreeze } from 'ngrx-store-freeze'; import { storeFreeze } from 'ngrx-store-freeze';
import { HardwareModules, Keymap, UserConfiguration } from 'uhk-common'; import { HardwareModules, Keymap, UserConfiguration } from 'uhk-common';
@@ -20,7 +19,7 @@ import { isVersionGte } from '../util';
// State interface for the application // State interface for the application
export interface AppState { export interface AppState {
userConfiguration: UserConfiguration; userConfiguration: fromUserConfig.State;
presetKeymaps: Keymap[]; presetKeymaps: Keymap[];
autoUpdateSettings: autoUpdateSettings.State; autoUpdateSettings: autoUpdateSettings.State;
app: fromApp.State; app: fromApp.State;
@@ -45,10 +44,18 @@ export const metaReducers: MetaReducer<AppState>[] = environment.production
? [] ? []
: [storeFreeze]; : [storeFreeze];
export const getUserConfiguration = (state: AppState) => state.userConfiguration; export const userConfigState = (state: AppState) => state.userConfiguration;
export const getUserConfiguration = createSelector(userConfigState, fromUserConfig.getUserConfiguration);
export const getKeymaps = createSelector(userConfigState, fromUserConfig.getKeymaps);
export const getDefaultKeymap = createSelector(userConfigState, fromUserConfig.getDefaultKeymap);
export const getSelectedKeymap = createSelector(userConfigState, fromUserConfig.getSelectedKeymap);
export const getMacros = createSelector(userConfigState, fromUserConfig.getMacros);
export const getSelectedMacro = createSelector(userConfigState, fromUserConfig.getSelectedMacro);
export const isKeymapDeletable = createSelector(userConfigState, fromUserConfig.isKeymapDeletable);
export const hasMacro = createSelector(userConfigState, fromUserConfig.hasMacro);
export const appState = (state: AppState) => state.app; export const appState = (state: AppState) => state.app;
export const showAddonMenu = createSelector(appState, fromApp.showAddonMenu); export const showAddonMenu = createSelector(appState, fromApp.showAddonMenu);
export const getUndoableNotification = createSelector(appState, fromApp.getUndoableNotification); export const getUndoableNotification = createSelector(appState, fromApp.getUndoableNotification);
export const getPrevUserConfiguration = createSelector(appState, fromApp.getPrevUserConfiguration); export const getPrevUserConfiguration = createSelector(appState, fromApp.getPrevUserConfiguration);

View File

@@ -1,5 +1,6 @@
import { Actions, ActionTypes, UpdateDownloadedAction } from '../actions/app-update.action'; import * as AppUpdate from '../actions/app-update.action';
import { UpdateInfo } from '../../models/update-info'; import { UpdateInfo } from '../../models/update-info';
import { UpdateDownloadedAction } from '../actions/app-update.action';
export interface State { export interface State {
updateAvailable: boolean; updateAvailable: boolean;
@@ -18,22 +19,22 @@ export const initialState: State = {
} }
}; };
export function reducer(state = initialState, action: Actions) { export function reducer(state = initialState, action: AppUpdate.Actions) {
switch (action.type) { switch (action.type) {
case ActionTypes.UPDATE_AVAILABLE: case AppUpdate.ActionTypes.UpdateAvailable:
return { return {
...state, ...state,
updateAvailable: true updateAvailable: true
}; };
case ActionTypes.UPDATE_DOWNLOADED: case AppUpdate.ActionTypes.UpdateDownloaded:
return { return {
...state, ...state,
updateDownloaded: true, updateDownloaded: true,
updateInfo: (action as UpdateDownloadedAction).payload updateInfo: (action as UpdateDownloadedAction).payload
}; };
case ActionTypes.DO_NOT_UPDATE_APP: case AppUpdate.ActionTypes.DoNotUpdateApp:
return { return {
...state, ...state,
doNotUpdateApp: true doNotUpdateApp: true

View File

@@ -1,7 +1,5 @@
import { ROUTER_NAVIGATION } from '@ngrx/router-store'; import { ROUTER_NAVIGATION, RouterNavigationAction } from '@ngrx/router-store';
import { Action } from '@ngrx/store';
import { import {
AppStartInfo,
CommandLineArgs, CommandLineArgs,
HardwareConfiguration, HardwareConfiguration,
Notification, Notification,
@@ -11,9 +9,9 @@ import {
VersionInformation VersionInformation
} from 'uhk-common'; } from 'uhk-common';
import { ActionTypes, ShowNotificationAction } from '../actions/app'; import * as App from '../actions/app';
import { ActionTypes as UserConfigActionTypes } from '../actions/user-config'; import { ActionTypes as UserConfigActionTypes, SaveUserConfigSuccessAction } from '../actions/user-config';
import { ActionTypes as DeviceActionTypes } from '../actions/device'; import { ActionTypes as DeviceActionTypes, ConnectionStateChangedAction } from '../actions/device';
import { KeyboardLayout } from '../../keyboard/keyboard-layout.enum'; import { KeyboardLayout } from '../../keyboard/keyboard-layout.enum';
import { getVersions } from '../../util'; import { getVersions } from '../../util';
@@ -45,17 +43,19 @@ export const initialState: State = {
keypressCapturing: false keypressCapturing: false
}; };
export function reducer(state = initialState, action: Action & { payload: any }) { export function reducer(
state = initialState,
action: App.Actions | RouterNavigationAction | SaveUserConfigSuccessAction | ConnectionStateChangedAction): State {
switch (action.type) { switch (action.type) {
case ActionTypes.APP_STARTED: { case App.ActionTypes.AppStarted: {
return { return {
...state, ...state,
started: true started: true
}; };
} }
case ActionTypes.APPLY_APP_START_INFO: { case App.ActionTypes.ApplyAppStartInfo: {
const payload = action.payload as AppStartInfo; const payload = (action as App.ApplyAppStartInfoAction).payload;
return { return {
...state, ...state,
@@ -65,8 +65,8 @@ export function reducer(state = initialState, action: Action & { payload: any })
}; };
} }
case ActionTypes.APP_SHOW_NOTIFICATION: { case App.ActionTypes.AppShowNotification: {
const currentAction = <ShowNotificationAction>action; const currentAction = <App.ShowNotificationAction>action;
if (currentAction.payload.type !== NotificationType.Undoable) { if (currentAction.payload.type !== NotificationType.Undoable) {
return state; return state;
} }
@@ -81,7 +81,7 @@ export function reducer(state = initialState, action: Action & { payload: any })
// When deleted a keymap or macro the app automaticaly navigate to other keymap, or macro, so // When deleted a keymap or macro the app automaticaly navigate to other keymap, or macro, so
// so we have to count the navigations and when reach the 2nd then remove the dialog. // so we have to count the navigations and when reach the 2nd then remove the dialog.
case ROUTER_NAVIGATION: { case ROUTER_NAVIGATION: {
const newState = {...state}; const newState = { ...state };
newState.navigationCountAfterNotification++; newState.navigationCountAfterNotification++;
if (newState.navigationCountAfterNotification > 1) { if (newState.navigationCountAfterNotification > 1) {
@@ -91,40 +91,41 @@ export function reducer(state = initialState, action: Action & { payload: any })
return newState; return newState;
} }
case ActionTypes.UNDO_LAST_SUCCESS: case App.ActionTypes.UndoLastSuccess:
case ActionTypes.DISMISS_UNDO_NOTIFICATION: { case App.ActionTypes.DismissUndoNotification: {
return { return {
...state, ...state,
undoableNotification: null undoableNotification: null
}; };
} }
case UserConfigActionTypes.LOAD_USER_CONFIG_SUCCESS: case UserConfigActionTypes.LoadUserConfigSuccess:
case UserConfigActionTypes.SAVE_USER_CONFIG_SUCCESS: { case UserConfigActionTypes.SaveUserConfigSuccess: {
return { return {
...state, ...state,
prevUserConfig: action.payload, prevUserConfig: (action as SaveUserConfigSuccessAction).payload,
configLoading: false configLoading: false
}; };
} }
case UserConfigActionTypes.LOAD_CONFIG_FROM_DEVICE: case UserConfigActionTypes.LoadConfigFromDevice:
case UserConfigActionTypes.LOAD_USER_CONFIG: { case UserConfigActionTypes.LoadUserConfig: {
return { return {
...state, ...state,
configLoading: true configLoading: true
}; };
} }
case ActionTypes.LOAD_HARDWARE_CONFIGURATION_SUCCESS: case App.ActionTypes.LoadHardwareConfigurationSuccess:
return { return {
...state, ...state,
hardwareConfig: action.payload hardwareConfig: (action as App.LoadHardwareConfigurationSuccessAction).payload
}; };
case DeviceActionTypes.CONNECTION_STATE_CHANGED: { case DeviceActionTypes.ConnectionStateChanged: {
const connectionState = (action as ConnectionStateChangedAction).payload;
if (action.payload === true) { if (connectionState && connectionState.connected === true) {
return state; return state;
} }
@@ -134,31 +135,31 @@ export function reducer(state = initialState, action: Action & { payload: any })
}; };
} }
case ActionTypes.PRIVILEGE_WHAT_WILL_THIS_DO: case App.ActionTypes.PrivilegeWhatWillThisDo:
return { return {
...state, ...state,
privilegeWhatWillThisDoClicked: true privilegeWhatWillThisDoClicked: true
}; };
case ActionTypes.SETUP_PERMISSION_ERROR: case App.ActionTypes.SetupPermissionError:
return { return {
...state, ...state,
permissionError: action.payload permissionError: (action as App.SetupPermissionErrorAction).payload
}; };
case DeviceActionTypes.SET_PRIVILEGE_ON_LINUX: case DeviceActionTypes.SetPrivilegeOnLinux:
return { return {
...state, ...state,
permissionError: null permissionError: null
}; };
case ActionTypes.START_KEYPRESS_CAPTURING: case App.ActionTypes.StartKeypressCapturing:
return { return {
...state, ...state,
keypressCapturing: true keypressCapturing: true
}; };
case ActionTypes.STOP_KEYPRESS_CAPTURING: case App.ActionTypes.StopKeypressCapturing:
return { return {
...state, ...state,
keypressCapturing: false keypressCapturing: false

View File

@@ -1,8 +1,7 @@
import { Action } from '@ngrx/store';
import { AutoUpdateSettings } from 'uhk-common'; import { AutoUpdateSettings } from 'uhk-common';
import { ActionTypes } from '../actions/auto-update-settings'; import * as AutoUpdate from '../actions/auto-update-settings';
import { ActionTypes as UpdateActions } from '../actions/app-update.action'; import * as AppUpdate from '../actions/app-update.action';
export interface State extends AutoUpdateSettings { export interface State extends AutoUpdateSettings {
checkingForUpdate: boolean; checkingForUpdate: boolean;
@@ -14,28 +13,43 @@ export const initialState: State = {
checkingForUpdate: false checkingForUpdate: false
}; };
export function reducer(state = initialState, action: Action & { payload?: any}): State { export function reducer(state = initialState, action: AutoUpdate.Actions | AppUpdate.Actions): State {
switch (action.type) { switch (action.type) {
case ActionTypes.TOGGLE_CHECK_FOR_UPDATE_ON_STARTUP: { case AutoUpdate.ActionTypes.ToggleCheckForUpdateOnStartup: {
return Object.assign({}, state, { checkForUpdateOnStartUp: action.payload }); return {
...state,
checkForUpdateOnStartUp: (action as AutoUpdate.ToggleCheckForUpdateOnStartupAction).payload
};
} }
case ActionTypes.TOGGLE_PRE_RELEASE_FLAG: { case AutoUpdate.ActionTypes.TogglePreReleaseFlag: {
return Object.assign({}, state, { usePreReleaseUpdate: action.payload }); return {
...state,
usePreReleaseUpdate: (action as AutoUpdate.TogglePreReleaseFlagAction).payload
};
} }
case ActionTypes.LOAD_AUTO_UPDATE_SETTINGS_SUCCESS: { case AutoUpdate.ActionTypes.LoadAutoUpdateSettingSuccess: {
return Object.assign({}, action.payload); return {
...state,
...(action as AutoUpdate.LoadAutoUpdateSettingsSuccessAction).payload
};
} }
case ActionTypes.CHECK_FOR_UPDATE_NOW: { case AutoUpdate.ActionTypes.CheckForUpdateNow: {
return Object.assign({}, state, { checkingForUpdate: true}); return {
...state,
checkingForUpdate: true
};
} }
case UpdateActions.UPDATE_ERROR: case AppUpdate.ActionTypes.UpdateError:
case ActionTypes.CHECK_FOR_UPDATE_SUCCESS: case AutoUpdate.ActionTypes.CheckForUpdateSuccess:
case ActionTypes.CHECK_FOR_UPDATE_FAILED: { case AutoUpdate.ActionTypes.CheckForUpdateFailed: {
return Object.assign({}, state, { checkingForUpdate: false }); return {
...state,
checkingForUpdate: false
};
} }
default: default:

View File

@@ -1,5 +1,4 @@
import { Actions, ActionTypes } from '../actions/contributors.action'; import * as Contributors from '../actions/contributors.action';
import { AgentContributorsAvailableAction, AgentContributorsNotAvailableAction } from '../actions/contributors.action';
import { UHKContributor } from '../../models/uhk-contributor'; import { UHKContributor } from '../../models/uhk-contributor';
export interface State { export interface State {
@@ -14,33 +13,33 @@ export const initialState: State = {
error: null error: null
}; };
export function reducer(state = initialState, action: Actions) { export function reducer(state = initialState, action: Contributors.Actions) {
switch (action.type) { switch (action.type) {
case ActionTypes.GET_AGENT_CONTRIBUTORS: { case Contributors.ActionTypes.GetAgentContributors: {
return { return {
...state ...state
}; };
} }
case ActionTypes.FETCH_AGENT_CONTRIBUTORS: { case Contributors.ActionTypes.FetchAgentContributors: {
return { return {
...state, ...state,
isLoading: true isLoading: true
}; };
} }
case ActionTypes.AGENT_CONTRIBUTORS_AVAILABLE: { case Contributors.ActionTypes.AgentContributorsAvailable: {
return { return {
...state, ...state,
contributors: (<AgentContributorsAvailableAction>action).payload, contributors: (<Contributors.AgentContributorsAvailableAction>action).payload,
isLoading: false isLoading: false
}; };
} }
case ActionTypes.AGENT_CONTRIBUTORS_NOT_AVAILABLE: { case Contributors.ActionTypes.AgentContributorsNotAvailable: {
return { return {
...state, ...state,
error: (<AgentContributorsNotAvailableAction>action).payload, error: (<Contributors.AgentContributorsNotAvailableAction>action).payload,
isLoading: false isLoading: false
}; };
} }

View File

@@ -1,16 +1,8 @@
import { Action } from '@ngrx/store'; import { Action } from '@ngrx/store';
import { HardwareModules, UdevRulesInfo } from 'uhk-common'; import { HardwareModules, UdevRulesInfo } from 'uhk-common';
import { import * as Device from '../actions/device';
ActionTypes, import * as App from '../actions/app';
ConnectionStateChangedAction,
HardwareModulesLoadedAction,
HasBackupUserConfigurationAction,
SaveConfigurationAction,
UpdateFirmwareFailedAction,
UpdateFirmwareSuccessAction
} from '../actions/device';
import { ActionTypes as AppActions, ElectronMainLogReceivedAction } from '../actions/app';
import { initProgressButtonState, ProgressButtonState } from './progress-button-state'; import { initProgressButtonState, ProgressButtonState } from './progress-button-state';
import { XtermCssClass, XtermLog } from '../../models/xterm-log'; import { XtermCssClass, XtermLog } from '../../models/xterm-log';
import { RestoreConfigurationState } from '../../models/restore-configuration-state'; import { RestoreConfigurationState } from '../../models/restore-configuration-state';
@@ -60,8 +52,8 @@ export const initialState: State = {
export function reducer(state = initialState, action: Action): State { export function reducer(state = initialState, action: Action): State {
switch (action.type) { switch (action.type) {
case ActionTypes.CONNECTION_STATE_CHANGED: { case Device.ActionTypes.ConnectionStateChanged: {
const data = (<ConnectionStateChangedAction>action).payload; const data = (<Device.ConnectionStateChangedAction>action).payload;
return { return {
...state, ...state,
connected: data.connected, connected: data.connected,
@@ -72,25 +64,25 @@ export function reducer(state = initialState, action: Action): State {
}; };
} }
case ActionTypes.SAVING_CONFIGURATION: { case Device.ActionTypes.SavingConfiguration: {
return { return {
...state, ...state,
savingToKeyboard: true savingToKeyboard: true
}; };
} }
case ActionTypes.SHOW_SAVE_TO_KEYBOARD_BUTTON: { case Device.ActionTypes.ShowSaveToKeyboardButton: {
return { return {
...state, ...state,
saveToKeyboard: { saveToKeyboard: {
showButton: true, showButton: true,
text: 'Save to keyboard', text: 'Save to keyboard',
action: new SaveConfigurationAction() action: new Device.SaveConfigurationAction()
} }
}; };
} }
case ActionTypes.SAVE_CONFIGURATION: { case Device.ActionTypes.SaveConfiguration: {
return { return {
...state, ...state,
saveToKeyboard: { saveToKeyboard: {
@@ -101,7 +93,7 @@ export function reducer(state = initialState, action: Action): State {
}; };
} }
case ActionTypes.SAVE_TO_KEYBOARD_SUCCESS: { case Device.ActionTypes.SaveToKeyboardSuccess: {
return { return {
...state, ...state,
saveToKeyboard: { saveToKeyboard: {
@@ -113,26 +105,26 @@ export function reducer(state = initialState, action: Action): State {
}; };
} }
case ActionTypes.SAVE_TO_KEYBOARD_FAILED: { case Device.ActionTypes.SaveToKeyboardFailed: {
return { return {
...state, ...state,
saveToKeyboard: { saveToKeyboard: {
showButton: true, showButton: true,
text: 'Save to keyboard', text: 'Save to keyboard',
action: new SaveConfigurationAction() action: new Device.SaveConfigurationAction()
} }
}; };
} }
case ActionTypes.HIDE_SAVE_TO_KEYBOARD_BUTTON: { case Device.ActionTypes.HideSaveToKeyboardButton: {
return { return {
...state, ...state,
saveToKeyboard: initProgressButtonState saveToKeyboard: initProgressButtonState
}; };
} }
case ActionTypes.UPDATE_FIRMWARE_WITH: case Device.ActionTypes.UpdateFirmwareWith:
case ActionTypes.UPDATE_FIRMWARE: case Device.ActionTypes.UpdateFirmware:
return { return {
...state, ...state,
updatingFirmware: true, updatingFirmware: true,
@@ -142,17 +134,17 @@ export function reducer(state = initialState, action: Action): State {
log: [{message: 'Start flashing firmware', cssClass: XtermCssClass.standard}] log: [{message: 'Start flashing firmware', cssClass: XtermCssClass.standard}]
}; };
case ActionTypes.UPDATE_FIRMWARE_SUCCESS: case Device.ActionTypes.UpdateFirmwareSuccess:
return { return {
...state, ...state,
updatingFirmware: false, updatingFirmware: false,
firmwareUpdateFinished: true, firmwareUpdateFinished: true,
firmwareUpdateSuccess: true, firmwareUpdateSuccess: true,
modules: (action as UpdateFirmwareSuccessAction).payload modules: (action as Device.UpdateFirmwareSuccessAction).payload
}; };
case ActionTypes.UPDATE_FIRMWARE_FAILED: { case Device.ActionTypes.UpdateFirmwareFailed: {
const data = (action as UpdateFirmwareFailedAction).payload; const data = (action as Device.UpdateFirmwareFailedAction).payload;
const logEntry = { const logEntry = {
message: data.error.message, message: data.error.message,
cssClass: XtermCssClass.error cssClass: XtermCssClass.error
@@ -168,12 +160,12 @@ export function reducer(state = initialState, action: Action): State {
}; };
} }
case AppActions.ELECTRON_MAIN_LOG_RECEIVED: { case App.ActionTypes.ElectronMainLogReceived: {
if (!state.updatingFirmware) { if (!state.updatingFirmware) {
return state; return state;
} }
const payload = (action as ElectronMainLogReceivedAction).payload; const payload = (action as App.ElectronMainLogReceivedAction).payload;
if (payload.message.indexOf('UHK Device not found:') > -1) { if (payload.message.indexOf('UHK Device not found:') > -1) {
return state; return state;
@@ -190,32 +182,32 @@ export function reducer(state = initialState, action: Action): State {
}; };
} }
case ActionTypes.MODULES_INFO_LOADED: case Device.ActionTypes.ModulesInfoLoaded:
return { return {
...state, ...state,
modules: (action as HardwareModulesLoadedAction).payload modules: (action as Device.HardwareModulesLoadedAction).payload
}; };
case ActionTypes.RESET_USER_CONFIGURATION: case Device.ActionTypes.ResetUserConfiguration:
case ActionTypes.RESTORE_CONFIGURATION_FROM_BACKUP: case Device.ActionTypes.RestoreConfigurationFromBackup:
return { return {
...state, ...state,
restoringUserConfiguration: true restoringUserConfiguration: true
}; };
case ActionTypes.HAS_BACKUP_USER_CONFIGURATION: case Device.ActionTypes.HasBackupUserConfiguration:
return { return {
...state, ...state,
hasBackupUserConfiguration: (action as HasBackupUserConfigurationAction).payload hasBackupUserConfiguration: (action as Device.HasBackupUserConfigurationAction).payload
}; };
case ActionTypes.RESTORE_CONFIGURATION_FROM_BACKUP_SUCCESS: case Device.ActionTypes.RestoreConfigurationFromBackupSuccess:
return { return {
...state, ...state,
hasBackupUserConfiguration: false hasBackupUserConfiguration: false
}; };
case ActionTypes.RECOVERY_DEVICE: { case Device.ActionTypes.RecoveryDevice: {
return { return {
...state, ...state,
updatingFirmware: true, updatingFirmware: true,

View File

@@ -1,13 +1,13 @@
import { Keymap } from 'uhk-common'; import { Keymap } from 'uhk-common';
import { KeymapAction, KeymapActions } from '../actions'; import * as Keymaps from '../actions/keymap';
export const initialState: Keymap[] = []; export const initialState: Keymap[] = [];
export function reducer(state = initialState, action: KeymapAction): Keymap[] { export function reducer(state = initialState, action: Keymaps.Actions): Keymap[] {
switch (action.type) { switch (action.type) {
case KeymapActions.LOAD_KEYMAPS_SUCCESS: { case Keymaps.ActionTypes.LoadKeymapsSuccess: {
return (action as KeymapActions.LoadKeymapSuccessAction).payload ; return (action as Keymaps.LoadKeymapSuccessAction).payload ;
} }
default: default:

View File

@@ -10,7 +10,7 @@ import {
} from 'uhk-common'; } from 'uhk-common';
import { getDefaultUserConfig } from '../../../../test/user-config-helper'; import { getDefaultUserConfig } from '../../../../test/user-config-helper';
import { KeymapActions } from '../actions'; import * as Keymaps from '../actions/keymap';
describe('user-configuration reducer', () => { describe('user-configuration reducer', () => {
it('should be initiate with default state', () => { it('should be initiate with default state', () => {
@@ -21,10 +21,10 @@ describe('user-configuration reducer', () => {
describe('SAVE_KEY', () => { describe('SAVE_KEY', () => {
it('should process KeyStrokeAction', () => { it('should process KeyStrokeAction', () => {
const defaultUserConfig = new UserConfiguration().fromJsonObject(getDefaultUserConfig()); const defaultUserConfig = new UserConfiguration().fromJsonObject(getDefaultUserConfig());
const state = new UserConfiguration().fromJsonObject(getDefaultUserConfig()); const state = { userConfiguration: new UserConfiguration().fromJsonObject(getDefaultUserConfig()) };
const keystrokeAction = new KeystrokeAction({_scancode: 100, type: KeystrokeType.basic} as any); const keystrokeAction = new KeystrokeAction({ _scancode: 100, type: KeystrokeType.basic } as any);
const saveKeyAction: KeymapActions.SaveKeyAction = { const saveKeyAction: Keymaps.SaveKeyAction = {
type: KeymapActions.SAVE_KEY, type: Keymaps.ActionTypes.SaveKey,
payload: { payload: {
keymap: new Keymap(defaultUserConfig.keymaps[0]), keymap: new Keymap(defaultUserConfig.keymaps[0]),
layer: 0, layer: 0,
@@ -37,7 +37,7 @@ describe('user-configuration reducer', () => {
} }
} }
}; };
const result = reducer(state, saveKeyAction); const result = reducer(state, saveKeyAction).userConfiguration;
const expectedKeyAction = <KeystrokeAction>result.keymaps[0].layers[0].modules[0].keyActions[0]; const expectedKeyAction = <KeystrokeAction>result.keymaps[0].layers[0].modules[0].keyActions[0];
expect(expectedKeyAction).toEqual(keystrokeAction); expect(expectedKeyAction).toEqual(keystrokeAction);
expect(result).not.toBe(defaultUserConfig); expect(result).not.toBe(defaultUserConfig);
@@ -52,15 +52,15 @@ describe('user-configuration reducer', () => {
it('should copy the SwitchLayerAction to the destination layer', () => { it('should copy the SwitchLayerAction to the destination layer', () => {
const defaultUserConfig = new UserConfiguration().fromJsonObject(getDefaultUserConfig()); const defaultUserConfig = new UserConfiguration().fromJsonObject(getDefaultUserConfig());
const state = new UserConfiguration().fromJsonObject(getDefaultUserConfig()); const state = { userConfiguration: new UserConfiguration().fromJsonObject(getDefaultUserConfig()) };
const destinationLayerId = LayerName.mod; const destinationLayerId = LayerName.mod;
const switchLayerAction = new SwitchLayerAction({ const switchLayerAction = new SwitchLayerAction({
switchLayerMode: SwitchLayerMode.toggle, switchLayerMode: SwitchLayerMode.toggle,
layer: destinationLayerId layer: destinationLayerId
} as any); } as any);
const saveKeyAction: KeymapActions.SaveKeyAction = { const saveKeyAction: Keymaps.SaveKeyAction = {
type: KeymapActions.SAVE_KEY, type: Keymaps.ActionTypes.SaveKey,
payload: { payload: {
keymap: new Keymap(defaultUserConfig.keymaps[0]), keymap: new Keymap(defaultUserConfig.keymaps[0]),
layer: 0, layer: 0,
@@ -74,7 +74,7 @@ describe('user-configuration reducer', () => {
} }
}; };
const result = reducer(state, saveKeyAction); const result = reducer(state, saveKeyAction).userConfiguration;
expect(result).not.toBe(defaultUserConfig); expect(result).not.toBe(defaultUserConfig);
expect(result.toJsonObject()).toEqual({ expect(result.toJsonObject()).toEqual({
userConfigVersion: 4, userConfigVersion: 4,
@@ -238,15 +238,15 @@ describe('user-configuration reducer', () => {
it('should copy the SwitchLayerAction to the destination layer and clear the modified', () => { it('should copy the SwitchLayerAction to the destination layer and clear the modified', () => {
const defaultUserConfig = new UserConfiguration().fromJsonObject(getDefaultUserConfig()); const defaultUserConfig = new UserConfiguration().fromJsonObject(getDefaultUserConfig());
const state = new UserConfiguration().fromJsonObject(getDefaultUserConfig()); const state = { userConfiguration: new UserConfiguration().fromJsonObject(getDefaultUserConfig()) };
const destinationLayerId = LayerName.fn; const destinationLayerId = LayerName.fn;
const switchLayerAction = new SwitchLayerAction({ const switchLayerAction = new SwitchLayerAction({
switchLayerMode: SwitchLayerMode.toggle, switchLayerMode: SwitchLayerMode.toggle,
layer: destinationLayerId layer: destinationLayerId
} as any); } as any);
const saveKeyAction: KeymapActions.SaveKeyAction = { const saveKeyAction: Keymaps.SaveKeyAction = {
type: KeymapActions.SAVE_KEY, type: Keymaps.ActionTypes.SaveKey,
payload: { payload: {
keymap: new Keymap(defaultUserConfig.keymaps[0]), keymap: new Keymap(defaultUserConfig.keymaps[0]),
layer: 0, layer: 0,
@@ -260,7 +260,7 @@ describe('user-configuration reducer', () => {
} }
}; };
const result = reducer(state, saveKeyAction); const result = reducer(state, saveKeyAction).userConfiguration;
expect(result).not.toBe(defaultUserConfig); expect(result).not.toBe(defaultUserConfig);
expect(result.toJsonObject()).toEqual({ expect(result.toJsonObject()).toEqual({
userConfigVersion: 4, userConfigVersion: 4,

File diff suppressed because it is too large Load Diff

View File

@@ -4,6 +4,8 @@
"outDir": "../uhk-agent/dist/out-tsc", "outDir": "../uhk-agent/dist/out-tsc",
"baseUrl": ".", "baseUrl": ".",
"declaration": false, "declaration": false,
"module": "es2015",
"moduleResolution": "node",
"target": "es5", "target": "es5",
"lib": [ "lib": [
"es2015.iterable", "es2015.iterable",