Skip to content

Commit

Permalink
config-util: Use package reload instead of custom reload.
Browse files Browse the repository at this point in the history
This is a WIP commit to fix the errors while saving settings that occur from
reloadDB function.
  • Loading branch information
abhigyank authored and akashnimare committed Sep 3, 2018
1 parent 24f5c9b commit bb99015
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions app/renderer/js/utils/config-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@ class ConfigUtil {
}

getConfigItem(key, defaultValue = null) {
this.reloadDB();
try {
this.db.reload();
} catch (err) {
logger.error('Error while reloading settings.json: ');
logger.error(err);
}
const value = this.db.getData('/')[key];
if (value === undefined) {
this.setConfigItem(key, defaultValue);
Expand All @@ -50,19 +55,24 @@ class ConfigUtil {
}
// This function returns whether a key exists in the configuration file (settings.json)
isConfigItemExists(key) {
this.reloadDB();
try {
this.db.reload();
} catch (err) {
logger.error('Error while reloading settings.json: ');
logger.error(err);
}
const value = this.db.getData('/')[key];
return (value !== undefined);
}

setConfigItem(key, value) {
this.db.push(`/${key}`, value, true);
this.reloadDB();
this.db.save();
}

removeConfigItem(key) {
this.db.delete(`/${key}`);
this.reloadDB();
this.db.save();
}

reloadDB() {
Expand Down

0 comments on commit bb99015

Please sign in to comment.