refactor(agent): Rename 'LongKeypressAction' to 'SecondaryRoleAction' (#462)

* refactor(agent): Rename 'LongKeypressAction' to 'SecondaryRoleAction'

* build: Change the build order of the modules

* fix(user-config): Fix hasSecondaryRoleAction() calculation

* fix(user-config): fix stylelint warnings
This commit is contained in:
Róbert Kiss
2017-10-18 21:16:56 +02:00
committed by László Monda
parent 641248c9e6
commit 3ffaf918cd
15 changed files with 69 additions and 68 deletions

View File

@@ -62,7 +62,7 @@
"lint:ts:test-serializer": "tslint --type-check --project ./packages/test-serializer/tsconfig.json",
"lint:ts:uhk-usb": "tslint --type-check --project ./packages/uhk-usb/tsconfig.json",
"lint:style": "stylelint \"packages/uhk-agent/src/**/*.scss\" \"packages/uhk-web/src/**/*.scss\" --syntax scss",
"build": "run-s build:web build:electron build:usb build:common",
"build": "run-s build:common build:usb build:web build:electron",
"build:web": "lerna exec --scope uhk-web npm run build",
"build:electron": "cross-env AOT_BUILD=true run-s -sn build:electron:renderer build:electron:main",
"build:electron:main": "lerna exec --scope uhk-agent npm run build",

View File

@@ -37,7 +37,7 @@ KeyActions.fromJsObject: [{"keyActionType":"none"},{"keyActionType":"keystroke",
KeystrokeModifiersAction.fromJsObject: {"keyActionType":"keystrokeModifiers","modifierMask":33} => <KeystrokeModifiersAction modifierMask="33">
KeystrokeWithModifiersAction.fromJsObject: {"keyActionType":"keystrokeWithModifiers","scancode":120,"modifierMask":16} => <KeystrokeWithModifiersAction scancode="120" modifierMask="16">
SwitchLayerAction.fromJsObject: {"keyActionType":"switchLayer","layer":"fn","toggle":false} => <SwitchLayerAction layer="1" toggle="false">
DualRoleKeystrokeAction.fromJsObject: {"keyActionType":"dualRoleKeystroke","scancode":111,"longPressAction":"mod"} => <DualRoleKeystrokeAction scancode="111" longPressAction="8">
DualRoleKeystrokeAction.fromJsObject: {"keyActionType":"dualRoleKeystroke","scancode":111,"secondaryRoleAction":"mod"} => <DualRoleKeystrokeAction scancode="111" secondaryRoleAction="8">
MouseAction.fromJsObject: {"keyActionType":"mouse","mouseAction":"scrollDown"} => <MouseAction mouseAction="8">
PlayMacroAction.fromJsObject: {"keyActionType":"playMacro","macroId":0} => <PlayMacroAction macroId="0">
SwitchKeymapAction.fromJsObject: {"keyActionType":"switchKeymap","keymapId":1} => <SwitchKeymapAction keymapId="1">
@@ -47,7 +47,7 @@ KeyActions.toBinary: <KeyActions length="9"> => ['u8(9)]
KeystrokeModifiersAction.toBinary: <KeystrokeModifiersAction modifierMask="33"> => ['u8(2), u8(33)]
KeystrokeWithModifiersAction.toBinary: <KeystrokeWithModifiersAction scancode="120" modifierMask="16"> => ['u8(3), u8(120), u8(16)]
SwitchLayerAction.toBinary: <SwitchLayerAction layer="1" toggle="false"> => ['u8(5), u8(1)]
DualRoleKeystrokeAction.toBinary: <DualRoleKeystrokeAction scancode="111" longPressAction="8"> => ['u8(4), u8(111), u8(8)]
DualRoleKeystrokeAction.toBinary: <DualRoleKeystrokeAction scancode="111" secondaryRoleAction="8"> => ['u8(4), u8(111), u8(8)]
MouseAction.toBinary: <MouseAction mouseAction="8"> => ['u8(7), u8(8)]
PlayMacroAction.toBinary: <PlayMacroAction macroId="0"> => ['u8(8), u8(0)]
SwitchKeymapAction.toBinary: <SwitchKeymapAction keymapId="1"> => ['u8(6), u8(1)]
@@ -57,7 +57,7 @@ KeyActions.fromBinary: [u8(9)]
KeystrokeModifiersAction.fromBinary: [u8(2), u8(33)] => <KeystrokeModifiersAction modifierMask="33">
KeystrokeWithModifiersAction.fromBinary: [u8(3), u8(120), u8(16)] => <KeystrokeWithModifiersAction scancode="120" modifierMask="16">
SwitchLayerAction.fromBinary: [u8(5), u8(1)] => <SwitchLayerAction layer="1" toggle="false">
DualRoleKeystrokeAction.fromBinary: [u8(4), u8(111), u8(8)] => <DualRoleKeystrokeAction scancode="111" longPressAction="8">
DualRoleKeystrokeAction.fromBinary: [u8(4), u8(111), u8(8)] => <DualRoleKeystrokeAction scancode="111" secondaryRoleAction="8">
MouseAction.fromBinary: [u8(7), u8(8)] => <MouseAction mouseAction="8">
PlayMacroAction.fromBinary: [u8(8), u8(0)] => <PlayMacroAction macroId="0">
SwitchKeymapAction.fromBinary: [u8(6), u8(1)] => <SwitchKeymapAction keymapId="1">
@@ -67,7 +67,7 @@ KeyActions.toJsObject: <KeyActions length="9">
KeystrokeModifiersAction.toJsObject: <KeystrokeModifiersAction modifierMask="33"> => {"keyActionType":"keystrokeModifiers","modifierMask":33}
KeystrokeWithModifiersAction.toJsObject: <KeystrokeWithModifiersAction scancode="120" modifierMask="16"> => {"keyActionType":"keystrokeWithModifiers","scancode":120,"modifierMask":16}
SwitchLayerAction.toJsObject: <SwitchLayerAction layer="1" toggle="false"> => {"keyActionType":"switchLayer","layer":"fn","toggle":false}
DualRoleKeystrokeAction.toJsObject: <DualRoleKeystrokeAction scancode="111" longPressAction="8"> => {"keyActionType":"dualRoleKeystroke","scancode":111,"longPressAction":"mod"}
DualRoleKeystrokeAction.toJsObject: <DualRoleKeystrokeAction scancode="111" secondaryRoleAction="8"> => {"keyActionType":"dualRoleKeystroke","scancode":111,"secondaryRoleAction":"mod"}
MouseAction.toJsObject: <MouseAction mouseAction="8"> => {"keyActionType":"mouse","mouseAction":"scrollDown"}
PlayMacroAction.toJsObject: <PlayMacroAction macroId="0"> => {"keyActionType":"playMacro","macroId":0}
SwitchKeymapAction.toJsObject: <SwitchKeymapAction keymapId="1"> => {"keyActionType":"switchKeymap","keymapId":1}

View File

@@ -4,7 +4,7 @@ export * from './hardware-configuration';
export * from './key-modifiers';
export * from './keymap';
export * from './layer';
export * from './long-press-action';
export * from './secondary-role-action';
export * from './macro';
export * from './module';
export * from './module-configuration';

View File

@@ -10,7 +10,7 @@ export enum KeyActionId {
5 bits:
1: Do we have scancode?
2: Do we have modifiers?
3: Do we have longpress?
3: Do we have secondaryRole?
4-5: What kind of keystroke? (basic, short/long media, system)
*/
LastKeystrokeAction = 31, // TODO: remove this after refactoring the keyActionId check

View File

@@ -1,6 +1,6 @@
import { KeystrokeAction } from './keystroke-action';
import { KeystrokeType } from './keystroke-type';
import { LongPressAction } from '../long-press-action';
import { SecondaryRoleAction } from '../secondary-role-action';
describe('keystroke-action', () => {
it('should be instantiate', () => {
@@ -13,7 +13,7 @@ describe('keystroke-action', () => {
other.type = KeystrokeType.basic;
other.scancode = 125;
other.modifierMask = 1;
other.longPressAction = LongPressAction.leftAlt;
other.secondaryRoleAction = SecondaryRoleAction.leftAlt;
const action = new KeystrokeAction(other);
expect(action).toEqual(other);
});
@@ -104,12 +104,12 @@ describe('keystroke-action', () => {
});
});
describe('longPressAction', () => {
describe('secondaryRoleAction', () => {
it('should store the value without modification', () => {
const value = LongPressAction.leftAlt;
const value = SecondaryRoleAction.leftAlt;
const action = new KeystrokeAction();
action.longPressAction = value;
expect(action.longPressAction).toEqual(value);
action.secondaryRoleAction = value;
expect(action.secondaryRoleAction).toEqual(value);
});
});
@@ -182,7 +182,7 @@ describe('keystroke-action', () => {
type: 'basic',
scancode: 100,
modifierMask: 10,
longPressAction: 'leftAlt'
secondaryRoleAction: 'leftAlt'
};
const action = new KeystrokeAction();
action.fromJsonObject(jsObject);
@@ -191,7 +191,7 @@ describe('keystroke-action', () => {
expected.type = KeystrokeType.basic;
expected.scancode = 100;
expected.modifierMask = 10;
expected.longPressAction = LongPressAction.leftAlt;
expected.secondaryRoleAction = SecondaryRoleAction.leftAlt;
expect(action).toEqual(expected);
});
@@ -202,7 +202,7 @@ describe('keystroke-action', () => {
type: 'system',
scancode: 100,
modifierMask: 10,
longPressAction: 'leftAlt'
secondaryRoleAction: 'leftAlt'
};
const action = new KeystrokeAction();
action.fromJsonObject(jsObject);
@@ -211,7 +211,7 @@ describe('keystroke-action', () => {
expected.type = KeystrokeType.system;
expected.scancode = 100;
expected.modifierMask = 10;
expected.longPressAction = LongPressAction.leftAlt;
expected.secondaryRoleAction = SecondaryRoleAction.leftAlt;
expect(action).toEqual(expected);
});
@@ -222,7 +222,7 @@ describe('keystroke-action', () => {
type: 'media',
scancode: 100,
modifierMask: 10,
longPressAction: 'leftAlt'
secondaryRoleAction: 'leftAlt'
};
const action = new KeystrokeAction();
action.fromJsonObject(jsObject);
@@ -231,7 +231,7 @@ describe('keystroke-action', () => {
expected.type = KeystrokeType.shortMedia;
expected.scancode = 100;
expected.modifierMask = 10;
expected.longPressAction = LongPressAction.leftAlt;
expected.secondaryRoleAction = SecondaryRoleAction.leftAlt;
expect(action).toEqual(expected);
});
@@ -242,7 +242,7 @@ describe('keystroke-action', () => {
type: 'media',
scancode: 256,
modifierMask: 10,
longPressAction: 'leftAlt'
secondaryRoleAction: 'leftAlt'
};
const action = new KeystrokeAction();
action.fromJsonObject(jsObject);
@@ -251,7 +251,7 @@ describe('keystroke-action', () => {
expected.type = KeystrokeType.longMedia;
expected.scancode = 256;
expected.modifierMask = 10;
expected.longPressAction = LongPressAction.leftAlt;
expected.secondaryRoleAction = SecondaryRoleAction.leftAlt;
expect(action).toEqual(expected);
});
@@ -281,7 +281,7 @@ describe('keystroke-action', () => {
});
describe('hasLongPressAction', () => {
describe('hasSecondaryRoleAction', () => {
});

View File

@@ -1,14 +1,14 @@
import { assertEnum, assertUInt8 } from '../../assert';
import { UhkBuffer } from '../../uhk-buffer';
import { KeyModifiers } from '../key-modifiers';
import { LongPressAction } from '../long-press-action';
import { SecondaryRoleAction } from '../secondary-role-action';
import { KeyAction, KeyActionId, keyActionType } from './key-action';
import { KeystrokeType } from './keystroke-type';
export enum KeystrokeActionFlag {
scancode = 1 << 0,
modifierMask = 1 << 1,
longPressAction = 1 << 2
secondaryRoleAction = 1 << 2
}
const KEYSTROKE_ACTION_FLAG_LENGTH = 3;
@@ -17,7 +17,7 @@ interface JsonObjectKeystrokeAction {
keyActionType: string;
scancode?: number;
modifierMask?: number;
longPressAction?: string;
secondaryRoleAction?: string;
type?: string;
}
@@ -40,8 +40,8 @@ export class KeystrokeAction extends KeyAction {
@assertUInt8
modifierMask: number;
@assertEnum(LongPressAction)
longPressAction: LongPressAction;
@assertEnum(SecondaryRoleAction)
secondaryRoleAction: SecondaryRoleAction;
set type(type: KeystrokeType) {
if (type === KeystrokeType.shortMedia || type === KeystrokeType.longMedia) {
@@ -67,7 +67,7 @@ export class KeystrokeAction extends KeyAction {
this.type = other.type;
this._scancode = other._scancode;
this.modifierMask = other.modifierMask;
this.longPressAction = other.longPressAction;
this.secondaryRoleAction = other.secondaryRoleAction;
}
fromJsonObject(jsonObject: JsonObjectKeystrokeAction): KeystrokeAction {
@@ -80,7 +80,7 @@ export class KeystrokeAction extends KeyAction {
this._scancode = jsonObject.scancode;
this.modifierMask = jsonObject.modifierMask;
this.longPressAction = LongPressAction[jsonObject.longPressAction];
this.secondaryRoleAction = SecondaryRoleAction[jsonObject.secondaryRoleAction];
return this;
}
@@ -94,8 +94,8 @@ export class KeystrokeAction extends KeyAction {
if (flags & KeystrokeActionFlag.modifierMask) {
this.modifierMask = buffer.readUInt8();
}
if (flags & KeystrokeActionFlag.longPressAction) {
this.longPressAction = buffer.readUInt8();
if (flags & KeystrokeActionFlag.secondaryRoleAction) {
this.secondaryRoleAction = buffer.readUInt8();
}
return this;
}
@@ -119,8 +119,8 @@ export class KeystrokeAction extends KeyAction {
jsonObject.modifierMask = this.modifierMask;
}
if (this.hasLongPressAction()) {
jsonObject.longPressAction = LongPressAction[this.longPressAction];
if (this.hasSecondaryRoleAction()) {
jsonObject.secondaryRoleAction = SecondaryRoleAction[this.secondaryRoleAction];
}
return jsonObject;
@@ -143,9 +143,9 @@ export class KeystrokeAction extends KeyAction {
toWrite.push({data: this.modifierMask, long: false});
}
if (this.hasLongPressAction()) {
flags |= KeystrokeActionFlag.longPressAction;
toWrite.push({data: this.longPressAction, long: false});
if (this.hasSecondaryRoleAction()) {
flags |= KeystrokeActionFlag.secondaryRoleAction;
toWrite.push({data: this.secondaryRoleAction, long: false});
}
const TYPE_OFFSET = flags + (this.type << KEYSTROKE_ACTION_FLAG_LENGTH);
@@ -172,8 +172,8 @@ export class KeystrokeAction extends KeyAction {
if (this.hasActiveModifier()) {
properties.push(`modifierMask="${this.modifierMask}"`);
}
if (this.hasLongPressAction()) {
properties.push(`longPressAction="${this.longPressAction}"`);
if (this.hasSecondaryRoleAction()) {
properties.push(`secondaryRoleAction="${this.secondaryRoleAction}"`);
}
return `<KeystrokeAction ${properties.join(' ')}>`;
@@ -187,8 +187,8 @@ export class KeystrokeAction extends KeyAction {
return this.modifierMask > 0;
}
hasLongPressAction(): boolean {
return this.longPressAction !== undefined;
hasSecondaryRoleAction(): boolean {
return this.secondaryRoleAction !== undefined && this.secondaryRoleAction !== null;
}
hasScancode(): boolean {

View File

@@ -1,4 +1,4 @@
export enum LongPressAction {
export enum SecondaryRoleAction {
leftCtrl,
leftShift,
leftAlt,

View File

@@ -4,6 +4,6 @@
height: 100%;
p {
margin: 1.5rem 0px 1.5rem;
margin: 1.5rem 0;
}
}

View File

@@ -26,7 +26,8 @@
<h4 *ngIf="activeTab === TabName.Keypress">Press key</h4>
<h4 *ngIf="activeTab === TabName.Hold">Hold key</h4>
<h4 *ngIf="activeTab === TabName.Release">Release key</h4>
<keypress-tab #keypressTab [defaultKeyAction]="defaultKeyAction" [longPressEnabled]="false" (validAction)="validate()"></keypress-tab>
<keypress-tab #keypressTab [defaultKeyAction]="defaultKeyAction" [secondaryRoleEnabled]="false"
(validAction)="validate()"></keypress-tab>
</div>
</div>
</div>

View File

@@ -49,7 +49,7 @@
<div [ngSwitch]="activeTab">
<keypress-tab #tab *ngSwitchCase="tabName.Keypress" class="popover-content"
[defaultKeyAction]="defaultKeyAction"
[longPressEnabled]="true"
[secondaryRoleEnabled]="true"
(validAction)="keyActionValid=$event"
></keypress-tab>
<layer-tab #tab *ngSwitchCase="tabName.Layer" class="popover-content"

View File

@@ -32,12 +32,12 @@
</div>
</div>
</div>
<div class="long-press-container" *ngIf="longPressEnabled">
<b class="setting-label">Long press action:</b>
<select2 #longPressSelect
[data]="longPressGroups"
[value]="selectedLongPressIndex.toString()"
(valueChanged)="onLongpressChange($event)"
<div class="long-press-container" *ngIf="secondaryRoleEnabled">
<b class="setting-label">Secondary role action:</b>
<select2 #secondaryRoleSelect
[data]="secondaryRoleGroups"
[value]="selectedSecondaryRoleIndex.toString()"
(valueChanged)="onSecondaryRoleChange($event)"
[width]="140"
></select2>
<icon name="question-circle"

View File

@@ -12,7 +12,7 @@ import { MapperService } from '../../../../services/mapper.service';
})
export class KeypressTabComponent extends Tab implements OnChanges {
@Input() defaultKeyAction: KeyAction;
@Input() longPressEnabled: boolean;
@Input() secondaryRoleEnabled: boolean;
leftModifiers: string[];
rightModifiers: string[];
@@ -21,11 +21,11 @@ export class KeypressTabComponent extends Tab implements OnChanges {
rightModifierSelects: boolean[];
scanCodeGroups: Array<Select2OptionData>;
longPressGroups: Array<Select2OptionData>;
secondaryRoleGroups: Array<Select2OptionData>;
options: Select2Options;
selectedScancodeOption: Select2OptionData;
selectedLongPressIndex: number;
selectedSecondaryRoleIndex: number;
constructor(private mapper: MapperService) {
super();
@@ -36,11 +36,11 @@ export class KeypressTabComponent extends Tab implements OnChanges {
text: 'None'
}];
this.scanCodeGroups = this.scanCodeGroups.concat(require('./scancodes.json'));
this.longPressGroups = require('./longPress.json');
this.secondaryRoleGroups = require('./secondaryRole.json');
this.leftModifierSelects = Array(this.leftModifiers.length).fill(false);
this.rightModifierSelects = Array(this.rightModifiers.length).fill(false);
this.selectedScancodeOption = this.scanCodeGroups[0];
this.selectedLongPressIndex = -1;
this.selectedSecondaryRoleIndex = -1;
this.options = {
templateResult: this.scanCodeTemplateResult,
matcher: (term: string, text: string, data: Select2OptionData) => {
@@ -100,9 +100,9 @@ export class KeypressTabComponent extends Tab implements OnChanges {
this.rightModifierSelects[index] = ((keystrokeAction.modifierMask >> i) & 1) === 1;
}
// Restore longPressAction
if (keystrokeAction.longPressAction !== undefined) {
this.selectedLongPressIndex = this.mapper.modifierMapper(keystrokeAction.longPressAction);
// Restore secondaryRoleAction
if (keystrokeAction.secondaryRoleAction !== undefined) {
this.selectedSecondaryRoleIndex = this.mapper.modifierMapper(keystrokeAction.secondaryRoleAction);
}
return true;
@@ -123,9 +123,9 @@ export class KeypressTabComponent extends Tab implements OnChanges {
keystrokeAction.modifierMask |= modifiers[i] << this.mapper.modifierMapper(i);
}
keystrokeAction.longPressAction = this.selectedLongPressIndex === -1
keystrokeAction.secondaryRoleAction = this.selectedSecondaryRoleIndex === -1
? undefined
: this.mapper.modifierMapper(this.selectedLongPressIndex);
: this.mapper.modifierMapper(this.selectedSecondaryRoleIndex);
if (this.keyActionValid(keystrokeAction)) {
return keystrokeAction;
@@ -158,8 +158,8 @@ export class KeypressTabComponent extends Tab implements OnChanges {
this.validAction.emit(this.keyActionValid());
}
onLongpressChange(event: { value: string }) {
this.selectedLongPressIndex = +event.value;
onSecondaryRoleChange(event: { value: string }) {
this.selectedSecondaryRoleIndex = +event.value;
}
onScancodeChange(event: { value: string }) {

View File

@@ -28,7 +28,7 @@ ul {
.sidebar {
&__level-0 {
padding: 0.5rem 1rem 0 1rem;
padding: 0.5rem 1rem 0;
}
&__level-1 {
padding: 0.5rem 1rem 0.5rem 2rem;

View File

@@ -25,7 +25,7 @@ import {
KeystrokeAction,
Layer,
LayerName,
LongPressAction,
SecondaryRoleAction,
MouseAction,
MouseActionParam,
PlayMacroAction,
@@ -266,10 +266,10 @@ export class SvgKeyboardWrapComponent implements OnInit, OnChanges {
});
}
if (keystrokeAction.hasLongPressAction()) {
if (keystrokeAction.hasSecondaryRoleAction()) {
content.push({
name: 'Long press',
value: LongPressAction[keystrokeAction.longPressAction]
name: 'Secondary role',
value: SecondaryRoleAction[keystrokeAction.secondaryRoleAction]
});
}
return Observable.of(content);