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

@@ -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,