Skip to content

Commit

Permalink
Override custom keycode list if the keyboard uses BMP
Browse files Browse the repository at this point in the history
  • Loading branch information
sekigon-gonnoc committed Nov 2, 2023
1 parent 4f1ce64 commit fbdb415
Showing 1 changed file with 29 additions and 9 deletions.
38 changes: 29 additions & 9 deletions src/actions/hid.action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { LayoutOption } from '../components/configure/keymap/Keymap';
import { maxValueByBitLength } from '../utils/NumberUtils';
import { KeyOp } from '../gen/types/KeyboardDefinition';
import { getEncoderIdList } from './utils';
import { bmpKeyInfoList } from '../services/hid/KeycodeInfoListBmp';

const PRODUCT_PREFIX_FOR_BLE_MICRO_PRO = '(BMP)';

Expand Down Expand Up @@ -290,13 +291,32 @@ export const hidActionsThunk = {
product_id: keyboard.getInformation().productId,
product_name: keyboard.getInformation().productName,
});
dispatch(
HidActions.updateBleMicroPro(
keyboard
.getInformation()
.productName.includes(PRODUCT_PREFIX_FOR_BLE_MICRO_PRO)
)
);

const isBleMicroPro = keyboard
.getInformation()
.productName.includes(PRODUCT_PREFIX_FOR_BLE_MICRO_PRO);

// Override custom keycode list if the keyboard uses BLE Micro Pro
const customKeycodes = !isBleMicroPro
? entities.keyboardDefinition?.customKeycodes
: bmpKeyInfoList.map((k) => {
return {
name: k.keycodeInfo.name.long,
title: k.desc,
shortName: k.keycodeInfo.name.short,
};
});

if (isBleMicroPro) {
dispatch(HidActions.updateBleMicroPro(isBleMicroPro));
dispatch(
StorageActions.updateKeyboardDefinition({
...entities.keyboardDefinition,
customKeycodes: customKeycodes,
})
);
}

const viaProtocolVersionResult = await keyboard.fetchViaProtocolVersion();
if (!viaProtocolVersionResult.success) {
dispatch(
Expand Down Expand Up @@ -338,15 +358,15 @@ export const hidActionsThunk = {
entities.keyboardDefinition!.matrix.rows,
entities.keyboardDefinition!.matrix.cols,
app.labelLang,
entities.keyboardDefinition!.customKeycodes
customKeycodes
);
dispatch(HidActions.updateKeymaps(keymaps));
const encodersKeymaps: IEncoderKeymaps[] = await loadEncodersKeymap(
dispatch,
keyboard,
layerCount,
app.labelLang,
entities.keyboardDefinition!.customKeycodes,
customKeycodes,
entities.keyboardDefinition!.layouts.keymap,
viaProtocolVersion
);
Expand Down

0 comments on commit fbdb415

Please sign in to comment.