Skip to content

Commit

Permalink
fix(config): saving config restored
Browse files Browse the repository at this point in the history
  • Loading branch information
DEgITx committed Feb 4, 2018
1 parent 7247044 commit ddc309e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
8 changes: 7 additions & 1 deletion src/background/bt/spider.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class Spider extends Emiter {
constructor(client) {
super()
const options = arguments.length? arguments[0]: {}
this.udp = dgram.createSocket('udp4')
this.table = new Table(options.tableCaption || 1000)
this.bootstraps = options.bootstraps || bootstraps
this.token = new Token()
Expand Down Expand Up @@ -225,6 +224,8 @@ class Spider extends Emiter {
return
this.initialized = true

this.closing = false
this.udp = dgram.createSocket('udp4')
this.udp.bind(port)
this.udp.on('listening', () => {
console.log(`Listen DHT protocol on ${this.udp.address().address}:${this.udp.address().port}`)
Expand Down Expand Up @@ -270,6 +271,11 @@ class Spider extends Emiter {

close(callback)
{
if(!this.initialized) {
if(callback)
callback()
return
}
clearInterval(this.joinInterval)
if(this.trafficInterval)
clearInterval(this.trafficInterval)
Expand Down
1 change: 0 additions & 1 deletion src/background/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ if(app.getPath("userData") && app.getPath("userData").length > 0)
const configProxy = new Proxy(config, {
set: (target, prop, value, receiver) => {
target[prop] = value
console.log('set op', configPath)

if(!fs.existsSync(configPath))
fs.writeFileSync(configPath, '{}')
Expand Down
11 changes: 9 additions & 2 deletions src/background/spider.js
Original file line number Diff line number Diff line change
Expand Up @@ -544,10 +544,17 @@ setInterval(() => {
if(typeof options !== 'object')
return;

if(typeof options.indexer !== 'undefined')
{
if(options.indexer)
spider.listen(config.spiderPort)
else
spider.close()
}

for(const option in options)
{
console.log('set', option, options[option])
if(config[option])
if(option in config)
config[option] = options[option]
}

Expand Down

0 comments on commit ddc309e

Please sign in to comment.