mirror of
https://github.com/CharaChorder/DeviceManager.git
synced 2026-01-03 08:32:52 +00:00
fix: chord files not detected properly
feat: alert on unknown backups
This commit is contained in:
@@ -60,6 +60,8 @@ export async function restoreBackup(event: Event) {
|
|||||||
restoreFromFile(csvLayoutToJson(text))
|
restoreFromFile(csvLayoutToJson(text))
|
||||||
} else if (isCsvChords(text)) {
|
} else if (isCsvChords(text)) {
|
||||||
restoreFromFile(csvChordsToJson(text))
|
restoreFromFile(csvChordsToJson(text))
|
||||||
|
} else {
|
||||||
|
alert("Unknown backup format")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,16 +5,19 @@ export function csvChordsToJson(csv: string): CharaChordFile {
|
|||||||
return {
|
return {
|
||||||
charaVersion: 1,
|
charaVersion: 1,
|
||||||
type: "chords",
|
type: "chords",
|
||||||
chords: csv.split("\n").map(line => {
|
chords: csv
|
||||||
const [input, output] = line.split(",", 2)
|
.trim()
|
||||||
return [
|
.split("\n")
|
||||||
input.split("+").map(it => KEYMAP_IDS.get(it.trim())?.code ?? 0),
|
.map(line => {
|
||||||
output.split("").map(it => KEYMAP_IDS.get(it.trim())?.code ?? 0),
|
const [input, output] = line.split(",", 2)
|
||||||
]
|
return [
|
||||||
}),
|
input.split("+").map(it => KEYMAP_IDS.get(it.trim())?.code ?? 0),
|
||||||
|
output.split("").map(it => KEYMAP_IDS.get(it.trim())?.code ?? 0),
|
||||||
|
]
|
||||||
|
}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isCsvChords(csv: string): boolean {
|
export function isCsvChords(csv: string): boolean {
|
||||||
return /^([^+,\s]( *\+ *[^+,\s]+)* *, *[^+,\s]+ *(\n|(?=$)))+$/.test(csv)
|
return /^([^+, ]+( *\+ *[^+, ]+)* *, *[^+, ]+ *(\n|(?=$)))+$/.test(csv)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user