Skip to content

Commit 7baf9ad

Browse files
ert78gbmondalaci
authored andcommitted
fix(user-config): Layer switcher key behaviour on non-base layers (#440)
* refactor(user-config): Optimize imports * feat(user-config): Clone SwitchLayerAction to destination layer * fix(user-config): Fix Keymap SwitchLayerAction normalization * test(user-config): Remove spy callThrough * build: Add uhk-common test runner * build: delete test serialization files * fix(user-config): Add missing "type": "basic" properties to the user-config.json * test(user-config): Add KeyMacroAction tests * fix(user-config): Delete SwitchLayerAction from non destination layer * fix(user-config): Keymap normalize delete SwitchLayerActions from non base layers * ci: turn of uhk-web tests * ci: turn off karma watch mode in uhk-web test
1 parent 46b97a9 commit 7baf9ad

File tree

16 files changed

+948
-8637
lines changed

16 files changed

+948
-8637
lines changed

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,16 @@ addons:
2525
- libudev-dev
2626
- build-essential
2727
- libusb-1.0-0-dev
28+
chrome: stable
2829

2930
install:
3031
- nvm install
3132
- npm install
3233

3334
before_script:
35+
- export DISPLAY=:99.0
36+
- sh -e /etc/init.d/xvfb start
37+
- sleep 3 # give xvfb some time to start
3438
- npm run build
3539
- npm run lint
3640

appveyor.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ shallow_clone: true
1818

1919
install:
2020
- ps: Install-Product node $env:nodejs_version
21+
- choco install chromium
2122
- set CI=true
2223
- set PATH=%APPDATA%\npm;%PATH%
2324
- node -v
@@ -27,5 +28,6 @@ install:
2728
test_script:
2829
- appveyor-retry npm run build
2930
- npm run lint
31+
- set CHROME_BIN="C:\Program Files (x86)\Chromium\Application\chrome.exe"
3032
- npm run test
3133
- npm run release

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@
5050
},
5151
"scripts": {
5252
"postinstall": "lerna bootstrap",
53-
"test": "lerna exec --scope test-serializer npm test",
53+
"test":"run-p -sn test:test-serializer test:uhk-common test:uhk-web",
54+
"test:test-serializer": "lerna exec --scope test-serializer npm test",
55+
"test:uhk-common": "lerna exec --scope uhk-common npm test",
56+
"test:uhk-web": "lerna exec --scope uhk-web npm test",
5457
"lint": "run-s -scn lint:ts lint:style",
5558
"lint:ts": "run-p -sn lint:ts:electron-main lint:ts:electron-renderer lint:ts:web lint:ts:test-serializer lint:ts:uhk-usb",
5659
"lint:ts:electron-main": "tslint --type-check --project ./packages/uhk-agent/tsconfig.json",
-3.78 KB
Binary file not shown.

packages/test-serializer/user-config-serialized.json

Lines changed: 0 additions & 7442 deletions
This file was deleted.
-3.78 KB
Binary file not shown.

packages/uhk-common/src/config-serializer/config-items/keymap.ts

Lines changed: 54 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { UhkBuffer } from '../uhk-buffer';
22
import { Layer } from './layer';
33
import { Macro } from './macro';
4-
import { SwitchLayerAction } from './key-action/switch-layer-action';
5-
import { KeyAction } from './key-action/key-action';
4+
import { KeyActionHelper, SwitchLayerAction } from './key-action';
65
import { UserConfiguration } from './user-configuration';
76

87
export class Keymap {
@@ -97,30 +96,64 @@ export class Keymap {
9796
}
9897

9998
private normalize() {
100-
// Removes all the SwitchLayerActions from any non base layer
101-
for (let i = 1; i < this.layers.length; ++i) {
102-
for (const module of this.layers[i].modules) {
103-
module.keyActions = module.keyActions.map(keyAction => {
104-
if (keyAction instanceof SwitchLayerAction) {
105-
return undefined;
106-
}
107-
return keyAction;
108-
});
109-
}
99+
if (this.layers.length < 1) {
100+
return;
110101
}
111102

112-
// Adds the SwitchLayerActions from the base layer to any none base layer
113-
const baseLayerModules = this.layers[0].modules;
114-
for (let i = 0; i < baseLayerModules.length; ++i) {
115-
baseLayerModules[i].keyActions.forEach((keyAction: KeyAction, keyActionIndex: number) => {
116-
if (keyAction instanceof SwitchLayerAction) {
117-
for (let j = 1; j < this.layers.length; ++j) {
118-
this.layers[j].modules[i].keyActions[keyActionIndex] = new SwitchLayerAction(keyAction);
103+
for (let moduleId = 0; moduleId < this.layers[0].modules.length && moduleId < 2; moduleId++) {
104+
const baseModule = this.layers[0].modules[moduleId];
105+
for (let keyActionId = 0; keyActionId < baseModule.keyActions.length; keyActionId++) {
106+
const baseKeyAction = baseModule.keyActions[keyActionId];
107+
108+
if (baseKeyAction instanceof SwitchLayerAction) {
109+
const destinationLayerId = baseKeyAction.layer + 1;
110+
if (this.layers.length < destinationLayerId) {
111+
// TODO: What should we do???
112+
console.error(`${this.name} has not enough layer. Need: ${destinationLayerId}`);
119113
}
120114
}
121-
});
122115

116+
for (let currentLayerId = 1; currentLayerId < this.layers.length; currentLayerId++) {
117+
const currentLayer = this.layers[currentLayerId];
118+
if (currentLayer.modules.length < moduleId) {
119+
// TODO: What should we do???
120+
console.error(`${this.name}.layers[${currentLayerId}] has not enough module. Need: ${moduleId}`);
121+
continue;
122+
}
123+
const currentModule = currentLayer.modules[moduleId];
124+
const currentKeyAction = currentModule.keyActions[keyActionId];
125+
126+
if (baseKeyAction instanceof SwitchLayerAction) {
127+
if (currentLayerId - 1 === baseKeyAction.layer) {
128+
if (currentKeyAction instanceof SwitchLayerAction) {
129+
if (currentKeyAction.layer === baseKeyAction.layer &&
130+
currentKeyAction.isLayerToggleable === baseKeyAction.isLayerToggleable) {
131+
continue;
132+
}
133+
// tslint:disable-next-line: max-line-length
134+
const error = `${this.name}.layers[${currentLayerId}]modules[${moduleId}].keyActions[${keyActionId}]` +
135+
` is different switch layer. ${currentKeyAction} will be override with ${baseKeyAction}`;
136+
console.warn(error);
137+
} else {
138+
// tslint:disable-next-line: max-line-length
139+
const error = `${this.name}.layers[${currentLayerId}]modules[${moduleId}].keyActions[${keyActionId}]` +
140+
` is not switch layer. ${currentKeyAction} will be override with ${baseKeyAction}`;
141+
console.warn(error);
142+
}
143+
currentModule.keyActions[keyActionId] = KeyActionHelper.createKeyAction(baseKeyAction);
144+
}
145+
}
146+
else {
147+
if (currentKeyAction instanceof SwitchLayerAction) {
148+
// tslint:disable-next-line: max-line-length
149+
const error = `${this.name}.layers[${currentLayerId}]modules[${moduleId}].keyActions[${keyActionId}]` +
150+
` is switch layer action, but the base key action is not switch layer action, so will delete`;
151+
console.warn(error);
152+
currentModule.keyActions[keyActionId] = null;
153+
}
154+
}
155+
}
156+
}
123157
}
124158
}
125-
126159
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { KeyMacroAction } from './key-macro-action';
2+
import { binaryDefaultHelper, jsonDefaultHelper } from '../../../../test/serializer-test-helper';
3+
import { MacroSubAction } from './macro-action';
4+
import { KeystrokeType } from '../key-action';
5+
6+
describe('key-macro-action', () => {
7+
it('should be instantiate', () => {
8+
const action = new KeyMacroAction();
9+
expect(action).toBeTruthy();
10+
});
11+
12+
describe('full serialization', () => {
13+
it('should json match', () => {
14+
const action = new KeyMacroAction();
15+
action.action = MacroSubAction.hold;
16+
action.type = KeystrokeType.basic;
17+
action.scancode = 100;
18+
jsonDefaultHelper(action);
19+
});
20+
21+
it('should binary match', () => {
22+
const action = new KeyMacroAction();
23+
action.action = MacroSubAction.hold;
24+
action.type = KeystrokeType.basic;
25+
action.scancode = 100;
26+
binaryDefaultHelper(action);
27+
});
28+
});
29+
});

0 commit comments

Comments
 (0)