[Settings] Small refactor: add comments, tweak some variable naming

This commit is contained in:
Ducko 2021-12-11 21:50:23 +00:00
parent ba9b26945c
commit f10a49b18a

View file

@ -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);
} }
} }