-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(App): Better error handling for config loader, missing songs and …
…osu scan (#400)
- Loading branch information
Showing
11 changed files
with
117 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,45 @@ | ||
import { readJSONSync, writeJSON } from 'fs-extra'; | ||
/* eslint-disable no-console */ | ||
import { readJSONSync } from 'fs-extra'; | ||
import fs from 'fs'; | ||
import { join } from 'path'; | ||
import { error, warn } from 'electron-log'; | ||
import { remote } from 'electron'; | ||
import baseConf from './baseConf'; | ||
import store from '../../../../shared/store'; | ||
|
||
class ConfLoader { | ||
constructor() { | ||
this.path = remote.app.getPath('documents') + '/Beatconnect/config.json'; | ||
this.path = join(remote.app.getPath('documents'), 'Beatconnect', 'config.json'); | ||
this.conf = null; | ||
} | ||
|
||
get config() { | ||
try { | ||
this.conf = { ...baseConf, ...readJSONSync(this.path) }; | ||
const userConfig = readJSONSync(this.path); | ||
this.conf = { ...this.conf, ...userConfig }; | ||
return this.conf; | ||
} catch (err) { | ||
// assume conf file does not exist | ||
warn('[Conf loader]: Failed to get user config creating a new one', err); | ||
this.conf = baseConf; | ||
return this.conf; | ||
} | ||
console.log('confLoader', this.conf); | ||
} | ||
|
||
save = () => { | ||
let { conf } = this; | ||
const { settings } = store.getState(); | ||
conf = { ...conf, ...settings }; | ||
this.conf = conf; | ||
writeJSON(this.path, this.conf, { EOL: '\n', spaces: 2 }) | ||
.then(console.log('config daved!')) | ||
.catch(console.error); | ||
}; | ||
async save(userSettings) { | ||
if (!this.conf) { | ||
console.log('Didnt save config cause its falsy'); | ||
return; | ||
} | ||
this.conf = { ...this.conf, ...userSettings }; | ||
try { | ||
const json = JSON.stringify(this.conf); | ||
fs.writeFileSync(this.path, json, { flag: 'w' }); | ||
console.log('config daved!'); | ||
} catch (e) { | ||
console.error('config ooofed!'); | ||
error('[config loader]: failed to write use config'); | ||
} | ||
} | ||
} | ||
|
||
export default new ConfLoader(); | ||
const configLoader = new ConfLoader(); | ||
export default configLoader; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters