mirror of
https://github.com/CharaChorder/DeviceManager.git
synced 2026-01-21 01:12:59 +00:00
feat: enable stricter type checking options
feat: make the app more fault tolerant
This commit is contained in:
@@ -95,6 +95,7 @@ export function restoreFromFile(
|
||||
switch (file.type) {
|
||||
case "backup": {
|
||||
const recent = file.history[0];
|
||||
if (!recent) return;
|
||||
if (recent[1].device !== get(serialPort)?.device) {
|
||||
alert("Backup is incompatible with this device");
|
||||
throw new Error("Backup is incompatible with this device");
|
||||
@@ -177,7 +178,7 @@ export function getChangesFromLayoutFile(file: CharaLayoutFile) {
|
||||
const changes: Change[] = [];
|
||||
for (const [layer, keys] of file.layout.entries()) {
|
||||
for (const [id, action] of keys.entries()) {
|
||||
if (get(layout)[layer][id].action !== action) {
|
||||
if (get(layout)[layer]?.[id]?.action !== action) {
|
||||
changes.push({
|
||||
type: ChangeType.Layout,
|
||||
layer,
|
||||
|
||||
@@ -13,11 +13,11 @@ export function csvChordsToJson(csv: string): CharaChordFile {
|
||||
.map((line) => {
|
||||
const [input, output] = line.split(/,(?=[^,]*$)/, 2);
|
||||
return [
|
||||
input
|
||||
input!
|
||||
.split("+")
|
||||
.map((it) => KEYMAP_IDS.get(it.trim())?.code ?? 0)
|
||||
.sort((a, b) => a - b),
|
||||
output
|
||||
output!
|
||||
.trim()
|
||||
.split("")
|
||||
.map((it) => KEYMAP_IDS.get(SPECIAL_KEYS.get(it) ?? it)?.code ?? 0),
|
||||
|
||||
@@ -17,7 +17,7 @@ export function csvLayoutToJson(
|
||||
for (const layer of csv.trim().split("\n")) {
|
||||
const [layerId, key, action] = layer.substring(1).split(",").map(Number);
|
||||
|
||||
layout.layout[Number(layerId) - 1][Number(key)] = Number(action);
|
||||
layout.layout[Number(layerId) - 1]![Number(key)] = Number(action);
|
||||
}
|
||||
|
||||
return layout;
|
||||
|
||||
Reference in New Issue
Block a user