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

View File

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

View File

@@ -15,28 +15,6 @@ export function capitalizeFirstLetter(text: string): string {
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() {
return window && (<any>window).process && (<any>window).process.type;
}

View File

@@ -343,12 +343,6 @@
"@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": {
"version": "9.6.2",
"resolved": "https://registry.npmjs.org/@types/node/-/node-9.6.2.tgz",
@@ -9318,12 +9312,6 @@
"integrity": "sha1-kl0mAdOaxIXgkc8NpcbmlNw9yv8=",
"dev": true
},
"reselect": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/reselect/-/reselect-3.0.1.tgz",
"integrity": "sha1-79qpjqdFEyTQkrKyFjpqHXqaIUc=",
"dev": true
},
"resolve": {
"version": "1.8.1",
"resolved": "https://registry.npmjs.org/resolve/-/resolve-1.8.1.tgz",

View File

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

View File

@@ -2,7 +2,6 @@ import { Component, OnInit, OnDestroy } from '@angular/core';
import { Store } from '@ngrx/store';
import { AppState, getUserConfiguration } from '../../../store';
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 { Subscription } from 'rxjs/Subscription';
import { UserConfiguration } from 'uhk-common';
@@ -117,7 +116,8 @@ export class MouseSpeedComponent implements OnInit, OnDestroy {
private userConfig$: Store<UserConfiguration>;
private userConfigSubscription: Subscription;
constructor(private store: Store<AppState>, private defaultUserConfigurationService: DefaultUserConfigurationService) {}
constructor(private store: Store<AppState>) {
}
ngOnInit(): void {
this.userConfig$ = this.store.select(getUserConfiguration);
@@ -132,7 +132,9 @@ export class MouseSpeedComponent implements OnInit, OnDestroy {
}
ngOnDestroy(): void {
this.userConfigSubscription.unsubscribe();
if (this.userConfigSubscription) {
this.userConfigSubscription.unsubscribe();
}
}
onSetPropertyValue(propertyName: string, value: number): void {
@@ -143,6 +145,6 @@ export class MouseSpeedComponent implements OnInit, OnDestroy {
}
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 { Keymap } from 'uhk-common';
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
import { Observable } from 'rxjs/Observable';
import { BehaviorSubject, Observable } from 'rxjs';
import { combineLatest, publishReplay, refCount } from 'rxjs/operators';
import { AppState } from '../../../store';
import { KeymapActions } from '../../../store/actions';
import { AddKeymapAction } from '../../../store/actions/keymap';
@Component({
selector: 'keymap-add',
@@ -42,6 +41,6 @@ export class KeymapAddComponent {
}
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 { Keymap } from 'uhk-common';
import { Observable } from 'rxjs/Observable';
import { Observable } from 'rxjs';
import { of } from 'rxjs/observable/of';
import { switchMap, tap } from 'rxjs/operators';
import 'rxjs/add/operator/let';
import { Store } from '@ngrx/store';
import { AppState } from '../../../store';
import { getKeymaps } from '../../../store/reducers/user-configuration';
import { AppState, getDefaultKeymap } from '../../../store';
@Injectable()
export class KeymapEditGuard implements CanActivate {
@@ -20,10 +17,9 @@ export class KeymapEditGuard implements CanActivate {
canActivate(): Observable<boolean> {
return this.store
.let(getKeymaps())
.select(getDefaultKeymap)
.pipe(
tap((keymaps: Keymap[]) => {
const defaultKeymap = keymaps.find(keymap => keymap.isDefault);
tap((defaultKeymap: Keymap) => {
if (defaultKeymap) {
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 { Store } from '@ngrx/store';
import { Keymap } from 'uhk-common';
import { Observable } from 'rxjs/Observable';
import { combineLatest, first, map, pluck, publishReplay, refCount, switchMap } from 'rxjs/operators';
import 'rxjs/add/operator/let';
import { Observable, Subscription } from 'rxjs';
import { combineLatest, first, map, pluck, switchMap } from 'rxjs/operators';
import { saveAs } from 'file-saver';
import { layerDoubleTapSupported, AppState, getKeyboardLayout } from '../../../store';
import { getKeymap, getKeymaps, getUserConfiguration } from '../../../store/reducers/user-configuration';
import {
getUserConfiguration,
getSelectedKeymap,
isKeymapDeletable,
layerDoubleTapSupported,
AppState,
getKeyboardLayout
} from '../../../store';
import { KeyboardLayout } from '../../../keyboard/keyboard-layout.enum';
import { KeymapActions } from '../../../store/actions';
import { EditDescriptionAction, SelectKeymapAction } from '../../../store/actions/keymap';
import { ChangeKeymapDescription } from '../../../models/ChangeKeymapDescription';
@Component({
@@ -24,7 +29,7 @@ import { ChangeKeymapDescription } from '../../../models/ChangeKeymapDescription
'class': 'container-fluid'
}
})
export class KeymapEditComponent {
export class KeymapEditComponent implements OnDestroy {
keyboardSplit: boolean;
@@ -33,26 +38,29 @@ export class KeymapEditComponent {
keyboardLayout$: Observable<KeyboardLayout>;
allowLayerDoubleTap$: Observable<boolean>;
private routeSubscription: Subscription;
constructor(protected store: Store<AppState>,
route: ActivatedRoute) {
this.keymap$ = route
this.routeSubscription = route
.params
.pipe(
pluck<{}, string>('abbr'),
switchMap((abbr: string) => store.let(getKeymap(abbr))),
publishReplay(1),
refCount()
);
pluck<{}, string>('abbr')
)
.subscribe(abbr => store.dispatch(new SelectKeymapAction(abbr)));
this.deletable$ = store.let(getKeymaps())
.pipe(
map((keymaps: Keymap[]) => keymaps.length > 1)
);
this.keymap$ = store.select(getSelectedKeymap);
this.deletable$ = store.select(isKeymapDeletable);
this.keyboardLayout$ = store.select(getKeyboardLayout);
this.allowLayerDoubleTap$ = store.select(layerDoubleTapSupported);
}
ngOnDestroy(): void {
this.routeSubscription.unsubscribe();
}
downloadKeymap() {
const exportableJSON$: Observable<string> = this.keymap$
.pipe(
@@ -79,12 +87,12 @@ export class KeymapEditComponent {
}
descriptionChanged(event: ChangeKeymapDescription): void {
this.store.dispatch(new KeymapActions.EditDescriptionAction(event));
this.store.dispatch(new EditDescriptionAction(event));
}
private toExportableJSON(keymap: Keymap): Observable<any> {
return this.store
.let(getUserConfiguration())
.select(getUserConfiguration)
.pipe(
first(),
map(userConfiguration => {

View File

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

View File

@@ -3,13 +3,17 @@ import { ActivatedRoute } from '@angular/router';
import { Store } from '@ngrx/store';
import { Macro, MacroAction } from 'uhk-common';
import { Observable } from 'rxjs/Observable';
import { Subscription } from 'rxjs/Subscription';
import { pluck, switchMap } from 'rxjs/operators';
import { Observable, Subscription } from 'rxjs';
import { MacroActions } from '../../../store/actions';
import { AppState, macroPlaybackSupported } from '../../../store';
import { getMacro } from '../../../store/reducers/user-configuration';
import {
AddMacroActionAction,
DeleteMacroActionAction,
ReorderMacroActionAction,
SaveMacroActionAction,
SelectMacroAction
} from '../../../store/actions/macro';
import { AppState, getSelectedMacro, macroPlaybackSupported } from '../../../store';
import { pluck } from 'rxjs/operators';
@Component({
selector: 'macro-edit',
@@ -25,18 +29,20 @@ export class MacroEditComponent implements OnDestroy {
macroId: number;
macroPlaybackSupported$: Observable<boolean>;
private subscription: Subscription;
private selectedMacroSubscription: Subscription;
private routeSubscription: Subscription;
constructor(private store: Store<AppState>, public route: ActivatedRoute) {
this.subscription = route
constructor(private store: Store<AppState>,
public route: ActivatedRoute) {
this.routeSubscription = route
.params
.pipe(
pluck<{}, string>('id'),
switchMap((id: string) => {
this.macroId = +id;
return store.let(getMacro(this.macroId));
})
pluck<{}, string>('id')
)
.subscribe(id => store.dispatch(new SelectMacroAction(+id)));
this.selectedMacroSubscription = store.select(getSelectedMacro)
.subscribe((macro: Macro) => {
this.macro = macro;
});
@@ -46,22 +52,23 @@ export class MacroEditComponent implements OnDestroy {
}
ngOnDestroy() {
this.subscription.unsubscribe();
this.selectedMacroSubscription.unsubscribe();
this.routeSubscription.unsubscribe();
}
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) {
this.store.dispatch(MacroActions.saveMacroAction(macroId, index, action));
this.store.dispatch(new SaveMacroActionAction({ id: macroId, index, action }));
}
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) {
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 { Macro } from 'uhk-common';
import { MacroActions } from '../../../store/actions';
import { DuplicateMacroAction, EditMacroNameAction, RemoveMacroAction } from '../../../store/actions/macro';
import { AppState } from '../../../store';
import * as util from '../../../util';
@@ -51,11 +51,11 @@ export class MacroHeaderComponent implements AfterViewInit, OnChanges {
}
removeMacro() {
this.store.dispatch(MacroActions.removeMacro(this.macro.id));
this.store.dispatch(new RemoveMacroAction(this.macro.id));
}
duplicateMacro() {
this.store.dispatch(MacroActions.duplicateMacro(this.macro));
this.store.dispatch(new DuplicateMacroAction(this.macro));
}
editMacroName(name: string) {
@@ -64,7 +64,7 @@ export class MacroHeaderComponent implements AfterViewInit, OnChanges {
return;
}
this.store.dispatch(MacroActions.editMacroName(this.macro.id, name));
this.store.dispatch(new EditMacroNameAction({ id: this.macro.id, name }));
}
calculateHeaderTextWidth(text): void {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,121 +1,118 @@
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';
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 const ActionTypes = {
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 AppBootstrappedAction implements Action {
type = ActionTypes.AppBootstrapped;
}
export class AppStartedAction implements Action {
type = ActionTypes.APP_STARTED;
type = ActionTypes.AppStarted;
}
export class ShowNotificationAction implements Action {
type = ActionTypes.APP_SHOW_NOTIFICATION;
type = ActionTypes.AppShowNotification;
constructor(public payload: Notification) {
}
}
export class ApplyAppStartInfoAction implements Action {
type = ActionTypes.APPLY_APP_START_INFO;
type = ActionTypes.ApplyAppStartInfo;
constructor(public payload: AppStartInfo) {
}
}
export class ProcessAppStartInfoAction implements Action {
type = ActionTypes.APP_PROCESS_START_INFO;
type = ActionTypes.AppProcessStartInfo;
constructor(public payload: AppStartInfo) {
}
}
export class UndoLastAction implements Action {
type = ActionTypes.UNDO_LAST;
type = ActionTypes.UndoLast;
constructor(public payload: any) {
}
}
export class UndoLastSuccessAction implements Action {
type = ActionTypes.UNDO_LAST_SUCCESS;
type = ActionTypes.UndoLastSuccess;
}
export class DismissUndoNotificationAction implements Action {
type = ActionTypes.DISMISS_UNDO_NOTIFICATION;
type = ActionTypes.DismissUndoNotification;
}
export class LoadHardwareConfigurationSuccessAction implements Action {
type = ActionTypes.LOAD_HARDWARE_CONFIGURATION_SUCCESS;
type = ActionTypes.LoadHardwareConfigurationSuccess;
constructor(public payload: HardwareConfiguration) {
}
}
export class ElectronMainLogReceivedAction implements Action {
type = ActionTypes.ELECTRON_MAIN_LOG_RECEIVED;
type = ActionTypes.ElectronMainLogReceived;
constructor(public payload: ElectronLogEntry) {
}
}
export class OpenUrlInNewWindowAction implements Action {
type = ActionTypes.OPEN_URL_IN_NEW_WINDOW;
type = ActionTypes.OpenUrlInNewWindow;
constructor(public payload: string) {
}
}
export class PrivilegeWhatWillThisDoAction implements Action {
type = ActionTypes.PRIVILEGE_WHAT_WILL_THIS_DO;
type = ActionTypes.PrivilegeWhatWillThisDo;
}
export class SetupPermissionErrorAction implements Action {
type = ActionTypes.SETUP_PERMISSION_ERROR;
type = ActionTypes.SetupPermissionError;
constructor(public payload: string) {
}
}
export class LoadAppStartInfoAction implements Action {
type = ActionTypes.LOAD_APP_START_INFO;
type = ActionTypes.LoadAppStartInfo;
}
export class StartKeypressCapturingAction implements Action {
type = ActionTypes.START_KEYPRESS_CAPTURING;
type = ActionTypes.StartKeypressCapturing;
}
export class StopKeypressCapturingAction implements Action {
type = ActionTypes.STOP_KEYPRESS_CAPTURING;
type = ActionTypes.StopKeypressCapturing;
}
export type Actions
= AppStartedAction
| AppBootsrappedAction
| AppBootstrappedAction
| ShowNotificationAction
| ApplyAppStartInfoAction
| ProcessAppStartInfoAction

View File

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

View File

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

View File

@@ -1,158 +1,154 @@
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';
const PREFIX = '[device] ';
// tslint:disable-next-line:variable-name
export const ActionTypes = {
SET_PRIVILEGE_ON_LINUX: type(PREFIX + 'set privilege on linux'),
SET_PRIVILEGE_ON_LINUX_REPLY: type(PREFIX + 'set privilege on linux reply'),
CONNECTION_STATE_CHANGED: type(PREFIX + 'connection state changed'),
SAVE_CONFIGURATION: type(PREFIX + 'save configuration'),
SAVE_CONFIGURATION_REPLY: type(PREFIX + 'save configuration reply'),
SAVING_CONFIGURATION: type(PREFIX + 'saving configuration'),
SHOW_SAVE_TO_KEYBOARD_BUTTON: type(PREFIX + 'show save to keyboard button'),
SAVE_TO_KEYBOARD_SUCCESS: type(PREFIX + 'save to keyboard success'),
SAVE_TO_KEYBOARD_FAILED: type(PREFIX + 'save to keyboard failed'),
HIDE_SAVE_TO_KEYBOARD_BUTTON: type(PREFIX + 'hide save to keyboard button'),
RESET_USER_CONFIGURATION: type(PREFIX + 'reset user configuration'),
RESET_MOUSE_SPEED_SETTINGS: type(PREFIX + 'reset mouse speed settings'),
UPDATE_FIRMWARE: type(PREFIX + 'update firmware'),
UPDATE_FIRMWARE_WITH: type(PREFIX + 'update firmware with'),
UPDATE_FIRMWARE_REPLY: type(PREFIX + 'update firmware reply'),
UPDATE_FIRMWARE_SUCCESS: type(PREFIX + 'update firmware success'),
UPDATE_FIRMWARE_FAILED: type(PREFIX + 'update firmware failed'),
UPDATE_FIRMWARE_OK_BUTTON: type(PREFIX + 'update firmware ok button click'),
MODULES_INFO_LOADED: type(PREFIX + 'module info loaded'),
HAS_BACKUP_USER_CONFIGURATION: type(PREFIX + 'Store backup user configuration'),
RESTORE_CONFIGURATION_FROM_BACKUP: type(PREFIX + 'Restore configuration from backup'),
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 enum ActionTypes {
SetPrivilegeOnLinux = '[device] set privilege on linux',
SetPrivilegeOnLinuxReply = '[device] set privilege on linux reply',
ConnectionStateChanged = '[device] connection state changed',
SaveConfiguration = '[device] save configuration',
SaveConfigurationReply = '[device] save configuration reply',
SavingConfiguration = '[device] saving configuration',
ShowSaveToKeyboardButton = '[device] show save to keyboard button',
SaveToKeyboardSuccess = '[device] save to keyboard success',
SaveToKeyboardFailed = '[device] save to keyboard failed',
HideSaveToKeyboardButton = '[device] hide save to keyboard button',
ResetUserConfiguration = '[device] reset user configuration',
ResetMouseSpeedSettings = '[device] reset mouse speed settings',
UpdateFirmware = '[device] update firmware',
UpdateFirmwareWith = '[device] update firmware with',
UpdateFirmwareReply = '[device] update firmware reply',
UpdateFirmwareSuccess = '[device] update firmware success',
UpdateFirmwareFailed = '[device] update firmware failed',
ModulesInfoLoaded = '[device] module info loaded',
HasBackupUserConfiguration = '[device] Store backup user configuration',
RestoreConfigurationFromBackup = '[device] Restore configuration from backup',
RestoreConfigurationFromBackupSuccess = '[device] Restore configuration from backup success',
RecoveryDevice = '[device] Recovery device',
EnableUsbStackTest = '[device] USB stack test',
StartConnectionPoller = '[device] Start connection poller'
}
export class SetPrivilegeOnLinuxAction implements Action {
type = ActionTypes.SET_PRIVILEGE_ON_LINUX;
type = ActionTypes.SetPrivilegeOnLinux;
}
export class SetPrivilegeOnLinuxReplyAction implements Action {
type = ActionTypes.SET_PRIVILEGE_ON_LINUX_REPLY;
type = ActionTypes.SetPrivilegeOnLinuxReply;
constructor(public payload: IpcResponse) {
}
}
export class ConnectionStateChangedAction implements Action {
type = ActionTypes.CONNECTION_STATE_CHANGED;
type = ActionTypes.ConnectionStateChanged;
constructor(public payload: DeviceConnectionState) {
}
}
export class SaveConfigurationAction implements Action {
type = ActionTypes.SAVE_CONFIGURATION;
type = ActionTypes.SaveConfiguration;
constructor() {
}
}
export class SaveConfigurationReplyAction implements Action {
type = ActionTypes.SAVE_CONFIGURATION_REPLY;
type = ActionTypes.SaveConfigurationReply;
constructor(public payload: IpcResponse) {
}
}
export class ShowSaveToKeyboardButtonAction implements Action {
type = ActionTypes.SHOW_SAVE_TO_KEYBOARD_BUTTON;
type = ActionTypes.ShowSaveToKeyboardButton;
}
export class SaveToKeyboardSuccessAction implements Action {
type = ActionTypes.SAVE_TO_KEYBOARD_SUCCESS;
type = ActionTypes.SaveToKeyboardSuccess;
}
export class SaveToKeyboardSuccessFailed implements Action {
type = ActionTypes.SAVE_TO_KEYBOARD_FAILED;
type = ActionTypes.SaveToKeyboardFailed;
}
export class HideSaveToKeyboardButton implements Action {
type = ActionTypes.HIDE_SAVE_TO_KEYBOARD_BUTTON;
type = ActionTypes.HideSaveToKeyboardButton;
}
export class ResetUserConfigurationAction implements Action {
type = ActionTypes.RESET_USER_CONFIGURATION;
type = ActionTypes.ResetUserConfiguration;
}
export class UpdateFirmwareAction implements Action {
type = ActionTypes.UPDATE_FIRMWARE;
type = ActionTypes.UpdateFirmware;
}
export class UpdateFirmwareWithAction implements Action {
type = ActionTypes.UPDATE_FIRMWARE_WITH;
type = ActionTypes.UpdateFirmwareWith;
constructor(public payload: Array<number>) {
}
}
export class UpdateFirmwareReplyAction implements Action {
type = ActionTypes.UPDATE_FIRMWARE_REPLY;
type = ActionTypes.UpdateFirmwareReply;
constructor(public payload: FirmwareUpgradeIpcResponse) {
}
}
export class UpdateFirmwareSuccessAction implements Action {
type = ActionTypes.UPDATE_FIRMWARE_SUCCESS;
type = ActionTypes.UpdateFirmwareSuccess;
constructor(public payload: HardwareModules) {
}
}
export class UpdateFirmwareFailedAction implements Action {
type = ActionTypes.UPDATE_FIRMWARE_FAILED;
type = ActionTypes.UpdateFirmwareFailed;
constructor(public payload: FirmwareUpgradeError) {
}
}
export class ResetMouseSpeedSettingsAction implements Action {
type = ActionTypes.RESET_MOUSE_SPEED_SETTINGS;
type = ActionTypes.ResetMouseSpeedSettings;
}
export class HardwareModulesLoadedAction implements Action {
type = ActionTypes.MODULES_INFO_LOADED;
type = ActionTypes.ModulesInfoLoaded;
constructor(public payload: HardwareModules) {
}
}
export class RestoreUserConfigurationFromBackupAction implements Action {
type = ActionTypes.RESTORE_CONFIGURATION_FROM_BACKUP;
type = ActionTypes.RestoreConfigurationFromBackup;
}
export class HasBackupUserConfigurationAction implements Action {
type = ActionTypes.HAS_BACKUP_USER_CONFIGURATION;
type = ActionTypes.HasBackupUserConfiguration;
constructor(public payload: boolean) {
}
}
export class RestoreUserConfigurationFromBackupSuccessAction implements Action {
type = ActionTypes.RESTORE_CONFIGURATION_FROM_BACKUP_SUCCESS;
type = ActionTypes.RestoreConfigurationFromBackupSuccess;
}
export class RecoveryDeviceAction implements Action {
type = ActionTypes.RECOVERY_DEVICE;
type = ActionTypes.RecoveryDevice;
}
export class EnableUsbStackTestAction implements Action {
type = ActionTypes.ENABLE_USB_STACK_TEST;
type = ActionTypes.EnableUsbStackTest;
}
export class StartConnectionPollerAction implements Action {
type = ActionTypes.START_CONNECTION_POLLER;
type = ActionTypes.StartConnectionPoller;
}
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 { Keymap, Macro } from 'uhk-common';
import { UndoUserConfigData } from '../../models/undo-user-config-data';
import { Keymap } from 'uhk-common';
import { ChangeKeymapDescription } from '../../models/ChangeKeymapDescription';
import { KeyActionRemap } from '../../models/key-action-remap';
import { UndoUserConfigData } from '../../models/undo-user-config-data';
export type KeymapAction =
KeymapActions.AddKeymapAction |
KeymapActions.DuplicateKeymapAction |
KeymapActions.EditKeymapNameAction |
KeymapActions.EditKeymapAbbreviationAction |
KeymapActions.LoadKeymapSuccessAction |
KeymapActions.SetDefaultAction |
KeymapActions.RemoveKeymapAction |
KeymapActions.SaveKeyAction |
KeymapActions.CheckMacroAction |
KeymapActions.EditDescriptionAction;
export enum ActionTypes {
Add = '[Keymap] Add keymap',
Duplicate = '[Keymap] Duplicate keymap',
EditAbbr = '[Keymap] Edit keymap abbreviation',
EditName = '[Keymap] Edit keymap title',
SaveKey = '[Keymap] Save key action',
SetDefault = '[Keymap] Set default option',
Remove = '[Keymap] Remove keymap',
CheckMacro = '[Keymap] Check deleted macro',
LoadKeymaps = '[Keymap] Load keymaps',
LoadKeymapsSuccess = '[Keymap] Load keymaps success',
EditDescription = '[Keymap] Edit description',
UndoLastAction = '[Keymap] Undo last action',
Select = '[Keymap] Select keymap action'
}
export namespace KeymapActions {
export const ADD = '[Keymap] Add keymap';
export class AddKeymapAction implements Action {
type = ActionTypes.Add;
export type AddKeymapAction = {
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
};
constructor(public payload: Keymap) {
}
}
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 { 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 {
export const PREFIX = '[Macro] ';
AddAction = '[Macro] Add macro action',
SaveAction = '[Macro] Save macro action',
DeleteAction = '[Macro] Delete macro action',
ReorderAction = '[Macro] Reorder macro action'
}
export const DUPLICATE = MacroActions.PREFIX + 'Duplicate macro';
export const EDIT_NAME = MacroActions.PREFIX + 'Edit macro title';
export const REMOVE = MacroActions.PREFIX + 'Remove macro';
export const ADD = MacroActions.PREFIX + 'Add macro';
export class DuplicateMacroAction implements Action {
type = ActionTypes.Duplicate;
export const ADD_ACTION = MacroActions.PREFIX + 'Add macro action';
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
}
};
constructor(public payload: Macro) {
}
}
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 { type, UserConfiguration, ConfigurationReply } from 'uhk-common';
import { UserConfiguration, ConfigurationReply } from 'uhk-common';
import { UserConfigurationValue } from '../../models/user-configuration-value';
import { UploadFileData } from '../../models/upload-file-data';
const PREFIX = '[user-config] ';
// tslint:disable-next-line:variable-name
export const ActionTypes = {
LOAD_USER_CONFIG: type(PREFIX + 'Load User Config'),
LOAD_CONFIG_FROM_DEVICE: type(PREFIX + 'Load User Config from Device'),
LOAD_CONFIG_FROM_DEVICE_REPLY: type(PREFIX + 'Load User Config from Device reply'),
LOAD_USER_CONFIG_SUCCESS: type(PREFIX + 'Load User Config Success'),
SAVE_USER_CONFIG_SUCCESS: type(PREFIX + 'Save User Config Success'),
SAVE_USER_CONFIG_IN_JSON_FILE: type(PREFIX + 'Save User Config in JSON file'),
SAVE_USER_CONFIG_IN_BIN_FILE: type(PREFIX + 'Save User Config in binary file'),
LOAD_RESET_USER_CONFIGURATION: type(PREFIX + 'Load reset user configuration'),
RENAME_USER_CONFIGURATION: type(PREFIX + 'Rename user configuration'),
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 enum ActionTypes {
LoadUserConfig = '[user-config] Load User Config',
LoadConfigFromDevice = '[user-config] Load User Config from Device',
LoadConfigFromDeviceReply = '[user-config] Load User Config from Device reply',
LoadUserConfigSuccess = '[user-config] Load User Config Success',
SaveUserConfigSuccess = '[user-config] Save User Config Success',
SaveUserConfigInJsonFile = '[user-config] Save User Config in JSON file',
SaveUserConfigInBinFile = '[user-config] Save User Config in binary file',
LoadResetUserConfiguration = '[user-config] Load reset user configuration',
RenameUserConfiguration = '[user-config] Rename user configuration',
SetUserConfigurationValue = '[user-config] Set user configuration value',
LoadUserConfigurationFromFile = '[user-config] Load user configuration from file',
ApplyUserConfigurationFromFile = '[user-config] Apply user configuration from file'
}
export class LoadUserConfigAction implements Action {
type = ActionTypes.LOAD_USER_CONFIG;
type = ActionTypes.LoadUserConfig;
}
export class LoadConfigFromDeviceAction implements Action {
type = ActionTypes.LOAD_CONFIG_FROM_DEVICE;
type = ActionTypes.LoadConfigFromDevice;
}
export class LoadConfigFromDeviceReplyAction implements Action {
type = ActionTypes.LOAD_CONFIG_FROM_DEVICE_REPLY;
type = ActionTypes.LoadConfigFromDeviceReply;
constructor(public payload: ConfigurationReply) {
}
}
export class LoadUserConfigSuccessAction implements Action {
type = ActionTypes.LOAD_USER_CONFIG_SUCCESS;
type = ActionTypes.LoadUserConfigSuccess;
constructor(public payload: UserConfiguration) {
}
}
export class SaveUserConfigSuccessAction implements Action {
type = ActionTypes.SAVE_USER_CONFIG_SUCCESS;
type = ActionTypes.SaveUserConfigSuccess;
constructor(public payload: UserConfiguration) {
}
}
export class SaveUserConfigInJsonFileAction implements Action {
type = ActionTypes.SAVE_USER_CONFIG_IN_JSON_FILE;
type = ActionTypes.SaveUserConfigInJsonFile;
}
export class SaveUserConfigInBinaryFileAction implements Action {
type = ActionTypes.SAVE_USER_CONFIG_IN_BIN_FILE;
type = ActionTypes.SaveUserConfigInBinFile;
}
export class LoadResetUserConfigurationAction implements Action {
type = ActionTypes.LOAD_RESET_USER_CONFIGURATION;
type = ActionTypes.LoadResetUserConfiguration;
constructor(public payload: UserConfiguration) {
}
}
export class RenameUserConfigurationAction implements Action {
type = ActionTypes.RENAME_USER_CONFIGURATION;
type = ActionTypes.RenameUserConfiguration;
constructor(public payload: string) {
}
}
export class SetUserConfigurationValueAction implements Action {
type = ActionTypes.SET_USER_CONFIGURATION_VALUE;
type = ActionTypes.SetUserConfigurationValue;
constructor(public payload: UserConfigurationValue) {
}
}
export class LoadUserConfigurationFromFileAction implements Action {
type = ActionTypes.LOAD_USER_CONFIGURATION_FROM_FILE;
type = ActionTypes.LoadUserConfigurationFromFile;
constructor(public payload: UploadFileData) {
}
}
export class ApplyUserConfigurationFromFileAction implements Action {
type = ActionTypes.APPLY_USER_CONFIGURATION_FROM_FILE;
type = ActionTypes.ApplyUserConfigurationFromFile;
constructor(public payload: UserConfiguration) {
}

View File

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

View File

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

View File

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

View File

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

View File

@@ -52,7 +52,7 @@ import { getVersions } from '../../util';
export class DeviceEffects {
@Effect()
deviceConnectionStateChange$: Observable<Action> = this.actions$
.ofType<ConnectionStateChangedAction>(ActionTypes.CONNECTION_STATE_CHANGED)
.ofType<ConnectionStateChangedAction>(ActionTypes.ConnectionStateChanged)
.pipe(
withLatestFrom(this.store.select(getRouterState), this.store.select(deviceConnected)),
tap(([action, route]) => {
@@ -93,7 +93,7 @@ export class DeviceEffects {
@Effect({ dispatch: false })
setPrivilegeOnLinux$: Observable<Action> = this.actions$
.ofType(ActionTypes.SET_PRIVILEGE_ON_LINUX)
.ofType(ActionTypes.SetPrivilegeOnLinux)
.pipe(
tap(() => {
this.deviceRendererService.setPrivilegeOnLinux();
@@ -102,7 +102,7 @@ export class DeviceEffects {
@Effect()
setPrivilegeOnLinuxReply$: Observable<Action> = this.actions$
.ofType<SetPrivilegeOnLinuxReplyAction>(ActionTypes.SET_PRIVILEGE_ON_LINUX_REPLY)
.ofType<SetPrivilegeOnLinuxReplyAction>(ActionTypes.SetPrivilegeOnLinuxReply)
.pipe(
map(action => action.payload),
switchMap((response: any): any => {
@@ -117,18 +117,21 @@ export class DeviceEffects {
@Effect({ dispatch: false })
saveConfiguration$: Observable<Action> = this.actions$
.ofType(ActionTypes.SAVE_CONFIGURATION)
.ofType(ActionTypes.SaveConfiguration)
.pipe(
withLatestFrom(this.store),
tap(([action, state]) => {
setTimeout(() => this.sendUserConfigToKeyboard(state.userConfiguration, state.app.hardwareConfig), 100);
setTimeout(() => this.sendUserConfigToKeyboard(
state.userConfiguration.userConfiguration,
state.app.hardwareConfig),
100);
}),
switchMap(() => empty())
);
@Effect()
saveConfigurationReply$: Observable<Action> = this.actions$
.ofType<SaveConfigurationReplyAction>(ActionTypes.SAVE_CONFIGURATION_REPLY)
.ofType<SaveConfigurationReplyAction>(ActionTypes.SaveConfigurationReply)
.pipe(
map(action => action.payload),
mergeMap((response: IpcResponse) => {
@@ -150,7 +153,7 @@ export class DeviceEffects {
@Effect()
autoHideSaveToKeyboardButton$: Observable<Action> = this.actions$
.ofType(ActionTypes.SAVE_TO_KEYBOARD_SUCCESS)
.ofType(ActionTypes.SaveToKeyboardSuccess)
.pipe(
withLatestFrom(this.store),
switchMap(([action, state]) => timer(1000)
@@ -169,7 +172,7 @@ export class DeviceEffects {
@Effect()
resetMouseSpeedSettings$: Observable<Action> = this.actions$
.ofType(ActionTypes.RESET_MOUSE_SPEED_SETTINGS)
.ofType(ActionTypes.ResetMouseSpeedSettings)
.pipe(
switchMap(() => {
const config = this.defaultUserConfigurationService.getDefault();
@@ -194,7 +197,7 @@ export class DeviceEffects {
);
@Effect() resetUserConfiguration$: Observable<Action> = this.actions$
.ofType(ActionTypes.RESET_USER_CONFIGURATION)
.ofType(ActionTypes.ResetUserConfiguration)
.pipe(
switchMap(() => {
const config = this.defaultUserConfigurationService.getDefault();
@@ -205,8 +208,8 @@ export class DeviceEffects {
@Effect() saveResetUserConfigurationToDevice$ = this.actions$
.ofType<ApplyUserConfigurationFromFileAction
| LoadResetUserConfigurationAction>(
UserConfigActions.LOAD_RESET_USER_CONFIGURATION,
UserConfigActions.APPLY_USER_CONFIGURATION_FROM_FILE)
UserConfigActions.LoadResetUserConfiguration,
UserConfigActions.ApplyUserConfigurationFromFile)
.pipe(
map(action => action.payload),
switchMap((config: UserConfiguration) => {
@@ -217,7 +220,7 @@ export class DeviceEffects {
);
@Effect({ dispatch: false }) updateFirmware$ = this.actions$
.ofType<UpdateFirmwareAction>(ActionTypes.UPDATE_FIRMWARE)
.ofType<UpdateFirmwareAction>(ActionTypes.UpdateFirmware)
.pipe(
tap(() => this.deviceRendererService.updateFirmware({
versionInformation: getVersions()
@@ -225,7 +228,7 @@ export class DeviceEffects {
);
@Effect({ dispatch: false }) updateFirmwareWith$ = this.actions$
.ofType<UpdateFirmwareWithAction>(ActionTypes.UPDATE_FIRMWARE_WITH)
.ofType<UpdateFirmwareWithAction>(ActionTypes.UpdateFirmwareWith)
.pipe(
map(action => action.payload),
tap(data => this.deviceRendererService.updateFirmware({
@@ -235,7 +238,7 @@ export class DeviceEffects {
);
@Effect() updateFirmwareReply$ = this.actions$
.ofType<UpdateFirmwareReplyAction>(ActionTypes.UPDATE_FIRMWARE_REPLY)
.ofType<UpdateFirmwareReplyAction>(ActionTypes.UpdateFirmwareReply)
.pipe(
map(action => action.payload),
switchMap((response: FirmwareUpgradeIpcResponse)
@@ -253,25 +256,25 @@ export class DeviceEffects {
);
@Effect() restoreUserConfiguration$ = this.actions$
.ofType<ResetUserConfigurationAction>(ActionTypes.RESTORE_CONFIGURATION_FROM_BACKUP)
.ofType<ResetUserConfigurationAction>(ActionTypes.RestoreConfigurationFromBackup)
.pipe(
map(() => new SaveConfigurationAction())
);
@Effect({ dispatch: false }) recoveryDevice$ = this.actions$
.ofType<RecoveryDeviceAction>(ActionTypes.RECOVERY_DEVICE)
.ofType<RecoveryDeviceAction>(ActionTypes.RecoveryDevice)
.pipe(
tap(() => this.deviceRendererService.recoveryDevice())
);
@Effect({ dispatch: false }) enableUsbStackTest$ = this.actions$
.ofType<EnableUsbStackTestAction>(ActionTypes.ENABLE_USB_STACK_TEST)
.ofType<EnableUsbStackTestAction>(ActionTypes.EnableUsbStackTest)
.pipe(
tap(() => this.deviceRendererService.enableUsbStackTest())
);
@Effect({ dispatch: false }) startConnectionPoller$ = this.actions$
.ofType(ActionTypes.START_CONNECTION_POLLER)
.ofType(ActionTypes.StartConnectionPoller)
.pipe(
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 { findNewItem } from '../../util';
import { KeymapActions } from '../actions';
import { AppState } from '../index';
import { getKeymaps } from '../reducers/user-configuration';
import * as Keymaps from '../actions/keymap';
import { AppState, getKeymaps } from '../index';
@Injectable()
export class KeymapEffects {
@Effect() loadKeymaps$: Observable<Action> = this.actions$
.ofType(KeymapActions.LOAD_KEYMAPS)
.ofType(Keymaps.ActionTypes.LoadKeymaps)
.pipe(
startWith(KeymapActions.loadKeymaps()),
startWith(new Keymaps.LoadKeymapsAction()),
switchMap(() => {
const presetsRequireContext = (<any>require).context('../../../res/presets', false, /.json$/);
const uhkPresets = presetsRequireContext.keys().map(presetsRequireContext) // load the presets into an array
.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$
.ofType(KeymapActions.ADD, KeymapActions.DUPLICATE)
.ofType(Keymaps.ActionTypes.Add, Keymaps.ActionTypes.Duplicate)
.pipe(
withLatestFrom(this.store.let(getKeymaps())
withLatestFrom(this.store.select(getKeymaps)
.pipe(
pairwise()
)
@@ -45,10 +44,10 @@ export class KeymapEffects {
);
@Effect({ dispatch: false }) remove$: any = this.actions$
.ofType(KeymapActions.REMOVE)
.ofType(Keymaps.ActionTypes.Remove)
.pipe(
withLatestFrom(this.store),
map(latest => latest[1].userConfiguration.keymaps),
withLatestFrom(this.store.select(getKeymaps)),
map(latest => latest[1]),
tap(keymaps => {
if (keymaps.length === 0) {
this.router.navigate(['/keymap/add']);
@@ -60,11 +59,11 @@ export class KeymapEffects {
);
@Effect({ dispatch: false }) editAbbr$: any = this.actions$
.ofType(KeymapActions.EDIT_ABBR)
.ofType(Keymaps.ActionTypes.EditAbbr)
.pipe(
withLatestFrom(this.store),
tap(([action, store]: [KeymapActions.EditKeymapAbbreviationAction, AppState]) => {
for (const keymap of store.userConfiguration.keymaps) {
withLatestFrom(this.store.select(getKeymaps)),
tap(([action, keymaps]: [Keymaps.EditKeymapAbbreviationAction, Keymap[]]) => {
for (const keymap of keymaps) {
if (keymap.name === action.payload.name && keymap.abbreviation === action.payload.newAbbr) {
this.router.navigate(['/keymap', action.payload.newAbbr]);
return;

View File

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

View File

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

View File

@@ -1,5 +1,4 @@
import { createSelector } from 'reselect';
import { ActionReducerMap, MetaReducer } from '@ngrx/store';
import { ActionReducerMap, createSelector, MetaReducer } from '@ngrx/store';
import { routerReducer, RouterReducerState } from '@ngrx/router-store';
import { storeFreeze } from 'ngrx-store-freeze';
import { HardwareModules, Keymap, UserConfiguration } from 'uhk-common';
@@ -20,7 +19,7 @@ import { isVersionGte } from '../util';
// State interface for the application
export interface AppState {
userConfiguration: UserConfiguration;
userConfiguration: fromUserConfig.State;
presetKeymaps: Keymap[];
autoUpdateSettings: autoUpdateSettings.State;
app: fromApp.State;
@@ -45,10 +44,18 @@ export const metaReducers: MetaReducer<AppState>[] = environment.production
? []
: [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 showAddonMenu = createSelector(appState, fromApp.showAddonMenu);
export const getUndoableNotification = createSelector(appState, fromApp.getUndoableNotification);
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 { UpdateDownloadedAction } from '../actions/app-update.action';
export interface State {
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) {
case ActionTypes.UPDATE_AVAILABLE:
case AppUpdate.ActionTypes.UpdateAvailable:
return {
...state,
updateAvailable: true
};
case ActionTypes.UPDATE_DOWNLOADED:
case AppUpdate.ActionTypes.UpdateDownloaded:
return {
...state,
updateDownloaded: true,
updateInfo: (action as UpdateDownloadedAction).payload
};
case ActionTypes.DO_NOT_UPDATE_APP:
case AppUpdate.ActionTypes.DoNotUpdateApp:
return {
...state,
doNotUpdateApp: true

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,13 +1,13 @@
import { Keymap } from 'uhk-common';
import { KeymapAction, KeymapActions } from '../actions';
import * as Keymaps from '../actions/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) {
case KeymapActions.LOAD_KEYMAPS_SUCCESS: {
return (action as KeymapActions.LoadKeymapSuccessAction).payload ;
case Keymaps.ActionTypes.LoadKeymapsSuccess: {
return (action as Keymaps.LoadKeymapSuccessAction).payload ;
}
default:

View File

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

File diff suppressed because it is too large Load Diff

View File

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