From fa1512dee56a6332c23a82b419360f956ff122b2 Mon Sep 17 00:00:00 2001 From: Alexey Kasyanchuk Date: Fri, 2 Feb 2018 20:10:07 +0300 Subject: [PATCH] fix(config): saving config restored --- src/background/bt/spider.js | 8 +++++++- src/background/config.js | 1 - src/background/spider.js | 11 +++++++++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/background/bt/spider.js b/src/background/bt/spider.js index ed5fc47..b89ab7e 100644 --- a/src/background/bt/spider.js +++ b/src/background/bt/spider.js @@ -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() @@ -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}`) @@ -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) diff --git a/src/background/config.js b/src/background/config.js index a4ddf5a..b5a6e77 100644 --- a/src/background/config.js +++ b/src/background/config.js @@ -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, '{}') diff --git a/src/background/spider.js b/src/background/spider.js index 190286d..cdb8a52 100644 --- a/src/background/spider.js +++ b/src/background/spider.js @@ -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] }