mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-02-20 22:23:53 +08:00
fix(keymaps): Handle empty keymap.json, recover when saving
This commit is contained in:
parent
f865b48f4e
commit
e23d597493
2 changed files with 13 additions and 3 deletions
|
@ -83,11 +83,20 @@ export default class CommandKeybinding extends React.Component {
|
|||
_onFinishedEditing = () => {
|
||||
if (this.state.editingBinding) {
|
||||
const keymapPath = NylasEnv.keymaps.getUserKeymapPath();
|
||||
let keymaps = {};
|
||||
|
||||
try {
|
||||
const exists = fs.existsSync(keymapPath);
|
||||
const keymaps = exists ? JSON.parse(fs.readFileSync(keymapPath)) : {};
|
||||
keymaps[this.props.command] = this.state.editingBinding;
|
||||
if (exists) {
|
||||
keymaps = JSON.parse(fs.readFileSync(keymapPath));
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
|
||||
keymaps[this.props.command] = this.state.editingBinding;
|
||||
|
||||
try {
|
||||
fs.writeFileSync(keymapPath, JSON.stringify(keymaps, null, 2));
|
||||
} catch (err) {
|
||||
NylasEnv.showErrorDialog(`Nylas was unable to modify your keymaps at ${keymapPath}. ${err.toString()}`);
|
||||
|
|
|
@ -41,7 +41,8 @@ class KeymapFile {
|
|||
if (e.code === 'ENOENT') {
|
||||
return;
|
||||
}
|
||||
throw e;
|
||||
console.error(e);
|
||||
return;
|
||||
}
|
||||
|
||||
this._bindings = {};
|
||||
|
|
Loading…
Reference in a new issue