Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/components/inputs/custom-keycode-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ type KeycodeModalProps = {

function isHex(input: string): boolean {
const lowercased = input.toLowerCase();
const parsed = parseInt(lowercased, 16);
return `0x${parsed.toString(16).toLowerCase()}` === lowercased;
return /^0x[0-9a-f]{1,4}$/.test(lowercased);
}

// This is hella basic 💁‍♀️💁‍♂️
Expand Down
17 changes: 14 additions & 3 deletions src/components/panes/configure-panes/save-load.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,23 @@ export const Pane: FC = () => {
dispatch(saveMacros(selectedDevice, saveFile.macros));
}

let parseErrors: string[] = [];
const keymap: number[][] = saveFile.layers.map((layer) =>
layer.map((key) =>
getByteForCode(`${deprecatedKeycodes[key] ?? key}`, basicKeyToByte),
),
layer.map((key) => {
try {
return getByteForCode(`${deprecatedKeycodes[key] ?? key}`, basicKeyToByte);
} catch (error) {
console.error(error);
parseErrors.push(`"${key}"`);
return 0;
}
}),
);

if (parseErrors.length > 0) {
setErrorMessage(`Unsupported keycodes: ${parseErrors.join(', ')}`);
}

// John you drongo, don't trust the compiler, dispatches are totes awaitable for async thunks
await dispatch(saveRawKeymapToDevice(keymap, selectedDevice));

Expand Down
2 changes: 1 addition & 1 deletion src/utils/advanced-keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ const parseModifierCode = (
: null;
}
});
if (bytes.find((e) => e === null)) {
if (bytes.includes(null)) {
return 0;
}
return bytes.reduce((acc, byte) => acc | byte, 0);
Expand Down
4 changes: 2 additions & 2 deletions src/utils/key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export function getByteForCode(
return byte;
} else if (isLayerCode(code)) {
return getByteForLayerCode(code, basicKeyToByte);
} else if (advancedStringToKeycode(code, basicKeyToByte) !== null) {
} else if (advancedStringToKeycode(code, basicKeyToByte) !== 0) {
return advancedStringToKeycode(code, basicKeyToByte);
}
throw `Could not find byte for ${code}`;
Expand Down Expand Up @@ -263,7 +263,7 @@ export function keycodeInMaster(
return (
keycode in basicKeyToByte ||
isLayerCode(keycode) ||
advancedStringToKeycode(keycode, basicKeyToByte) !== null
advancedStringToKeycode(keycode, basicKeyToByte) !== 0
);
}

Expand Down