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:
commit
d58ab38350
|
@ -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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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:
|
||||||
|
|
Loading…
Reference in New Issue