[Settings] Small refactor: add comments, tweak some variable naming
This commit is contained in:
parent
ba9b26945c
commit
f10a49b18a
1 changed files with 6 additions and 6 deletions
|
@ -8,7 +8,7 @@ class Settings { // Heavily based on original for compat, but simplified and twe
|
||||||
try {
|
try {
|
||||||
this.lastSaved = readFileSync(this.path);
|
this.lastSaved = readFileSync(this.path);
|
||||||
this.settings = JSON.parse(this.lastSaved);
|
this.settings = JSON.parse(this.lastSaved);
|
||||||
} catch (e) {
|
} catch (_e) {
|
||||||
this.lastSaved = '';
|
this.lastSaved = '';
|
||||||
this.settings = {};
|
this.settings = {};
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ class Settings { // Heavily based on original for compat, but simplified and twe
|
||||||
}
|
}
|
||||||
|
|
||||||
save() {
|
save() {
|
||||||
if (this.lastModified && this.lastModified !== this.getLastModified()) {
|
if (this.lastModified && this.lastModified !== this.getLastModified()) { // File was last modified after Settings was made, so was externally edited therefore we don't save over
|
||||||
log('AppSettings', 'Refusing to save settings.json due to last modified date mismatch');
|
log('AppSettings', 'Refusing to save settings.json due to last modified date mismatch');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,7 @@ class Settings { // Heavily based on original for compat, but simplified and twe
|
||||||
try {
|
try {
|
||||||
const toSave = JSON.stringify(this.settings, null, 2);
|
const toSave = JSON.stringify(this.settings, null, 2);
|
||||||
|
|
||||||
if (this.lastSaved != toSave) {
|
if (this.lastSaved != toSave) { // Settings has changed
|
||||||
this.lastSaved = toSave;
|
this.lastSaved = toSave;
|
||||||
|
|
||||||
writeFileSync(this.path, toSave);
|
writeFileSync(this.path, toSave);
|
||||||
|
@ -51,9 +51,9 @@ class Settings { // Heavily based on original for compat, but simplified and twe
|
||||||
this.lastModified = this.getLastModified();
|
this.lastModified = this.getLastModified();
|
||||||
}
|
}
|
||||||
|
|
||||||
log('AppSettings', 'Saved settings.json');
|
log('AppSettings', 'Saved', this.path);
|
||||||
} catch (err) {
|
} catch (e) {
|
||||||
log('AppSettings', 'Failed to save settings.json', err);
|
log('AppSettings', 'Failed to save', this.path, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue