Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
AstroCB committed Aug 1, 2020
1 parent ec030ee commit 87dbd5b
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,24 @@ exports.getConfigDir = () => {
}

exports.getConfigPath = () => {
return `${exports.getConfigDir()}/mnotify-config.json`;
return `${this.getConfigDir()}/mnotify-config.json`;
}

exports.configExists = () => {
return fs.existsSync(exports.getConfigDir());
return fs.existsSync(this.getConfigDir());
}

exports.loadConfig = () => {
if (exports.configExists()) {
const config = fs.readFileSync(exports.getConfigPath());
if (this.configExists()) {
const config = fs.readFileSync(this.getConfigPath());
return JSON.parse(config);
} else {
throw Error("Config not found");
}
}

exports.saveConfig = (config, callback = () => { }) => {
fs.writeFile(exports.getConfigPath(), JSON.stringify(config), callback);
fs.writeFile(this.getConfigPath(), JSON.stringify(config), callback);
}

exports.printNoConfigError = () => {
Expand All @@ -36,16 +36,16 @@ exports.printNoConfigError = () => {

exports.updateLogin = (config, api) => {
config.appState = api.getAppState();
exports.saveConfig(config);
this.saveConfig(config);
}

exports.updatePassword = pass => {
try {
const config = exports.loadConfig();
const config = this.loadConfig();
config.password = pass;
exports.saveConfig(config);
this.saveConfig(config);
} catch {
exports.printNoConfigError();
this.printNoConfigError();
}
}

Expand All @@ -66,17 +66,17 @@ exports.getStdin = cb => {

exports.checkLogin = (fail, succeed) => {
try {
const config = exports.loadConfig();
login({ "appState": config.appState }, exports.silentOpt, (err, _) => {
const config = this.loadConfig();
login({ "appState": config.appState }, this.silentOpt, (err, _) => {
if (err) {
if (config.email && config.password) {
login({ "email": config.email, "password": config.password },
exports.silentOpt, (err, api) => {
this.silentOpt, (err, api) => {
if (err) {
fail()
} else {
// Re-login succeeded; need to update stored session
exports.updateLogin(config, api);
this.updateLogin(config, api);
succeed();
}
});
Expand Down

0 comments on commit 87dbd5b

Please sign in to comment.