Skip to content

Commit

Permalink
Merge pull request #1164 from h3poteto/iss-1163
Browse files Browse the repository at this point in the history
refs #1163 Use default preference if the file does not exist when get proxy configuration
  • Loading branch information
h3poteto committed Dec 11, 2019
2 parents 2cfe8b6 + d01a8d5 commit d58ab38
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions src/main/preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,17 @@ export default class Preferences {
this.path = path
}

async load(): Promise<BaseConfig> {
public async load(): Promise<BaseConfig> {
try {
const preferences = await this.get()
const preferences = await this._get()
return objectAssignDeep({}, Base, preferences)
} catch (err) {
log.error(err)
return Base
}
}

get(): Promise<BaseConfig> {
private _get(): Promise<BaseConfig> {
return new Promise((resolve, reject) => {
storage.get(this.path, (err, data) => {
if (err) return reject(err)
Expand All @@ -112,7 +112,7 @@ export default class Preferences {
})
}

save(data: BaseConfig): Promise<BaseConfig> {
private _save(data: BaseConfig): Promise<BaseConfig> {
return new Promise((resolve, reject) => {
storage.set(this.path, data, err => {
if (err) return reject(err)
Expand All @@ -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 data = objectAssignDeep({}, current, obj)
const result = await this.save(data)
const result = await this._save(data)
return result
}
}
2 changes: 1 addition & 1 deletion src/main/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export default class ProxyConfiguration {
}

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
switch (source) {
case ProxySource.no:
Expand Down

0 comments on commit d58ab38

Please sign in to comment.