Merge pull request #1164 from h3poteto/iss-1163

refs #1163 Use default preference if the file does not exist when get proxy configuration
This commit is contained in:
AkiraFukushima 2019-12-11 21:36:42 +09:00 committed by GitHub
commit d58ab38350
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 7 deletions

View File

@ -93,9 +93,9 @@ export default class Preferences {
this.path = path this.path = path
} }
async load(): Promise<BaseConfig> { public async load(): Promise<BaseConfig> {
try { try {
const preferences = await this.get() const preferences = await this._get()
return objectAssignDeep({}, Base, preferences) return objectAssignDeep({}, Base, preferences)
} catch (err) { } catch (err) {
log.error(err) log.error(err)
@ -103,7 +103,7 @@ export default class Preferences {
} }
} }
get(): Promise<BaseConfig> { private _get(): Promise<BaseConfig> {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
storage.get(this.path, (err, data) => { storage.get(this.path, (err, data) => {
if (err) return reject(err) if (err) return reject(err)
@ -112,7 +112,7 @@ export default class Preferences {
}) })
} }
save(data: BaseConfig): Promise<BaseConfig> { private _save(data: BaseConfig): Promise<BaseConfig> {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
storage.set(this.path, data, err => { storage.set(this.path, data, err => {
if (err) return reject(err) if (err) return reject(err)
@ -121,10 +121,10 @@ export default class Preferences {
}) })
} }
async update(obj: any): Promise<BaseConfig> { public async update(obj: any): Promise<BaseConfig> {
const current = await this.load() const current = await this.load()
const data = objectAssignDeep({}, current, obj) const data = objectAssignDeep({}, current, obj)
const result = await this.save(data) const result = await this._save(data)
return result return result
} }
} }

View File

@ -44,7 +44,7 @@ export default class ProxyConfiguration {
} }
public async getConfig(): Promise<false | ManualProxy> { public async getConfig(): Promise<false | ManualProxy> {
const conf = await this.preferences.get() const conf = await this.preferences.load()
const source = conf.proxy.source as ProxySource const source = conf.proxy.source as ProxySource
switch (source) { switch (source) {
case ProxySource.no: case ProxySource.no: