diff --git a/src/main/core/broker/broker.js b/src/main/core/broker/broker.js index 2d8bd5db0..63f42c799 100644 --- a/src/main/core/broker/broker.js +++ b/src/main/core/broker/broker.js @@ -33,23 +33,25 @@ module.exports = class Broker extends EventEmitter { constructor(renderer) { super() this.renderer = renderer; + this.initStore(); } - initDB() { + initStore() { /** - * Initialize db + * Singleton initialize db * @type {function(*=): void} */ log.warn('Creating local db') - this.db = new LinvoDB(DB)//, MOVIES_SCHEMA, {}) + if (this.db) return this.db; + this.db = new LinvoDB(DB) } flush() { /** * Kill all this shit XD * */ - log.warn('Flushing app') + this.db.remove({}, {multi: true}, (err, numRemoved) => { if (err) log.error(err) @@ -168,7 +170,6 @@ module.exports = class Broker extends EventEmitter { log.info(collection[0]['_id']); // get id for ingested chunk const total = this.db.getAllData().length; const firstChunk = Object.is(total, 0); - this.db.insert(collection, (e, n) => { if (e) return; // Avoid `n.length` undefined if (firstChunk) { @@ -191,7 +192,6 @@ module.exports = class Broker extends EventEmitter { */ // Clean old listeners first log.info('Broker ready') - this.initDB(); this.stopIpcEvents(); this.emitStart(); this.listenForPartyRock(); diff --git a/src/main/index.js b/src/main/index.js index 6a010f136..2947ea5e3 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -196,7 +196,6 @@ app.on('ready', async () => { }) } - }) // Disable cors errors @@ -228,7 +227,7 @@ app.whenReady().then(() => { ipcMain.on('party', async () => { if (key.existKey) await removeFiles(key.keyFile) ipcMain.emit('party-success') // Just after key being removed - removeCacheDirs(); // Clean old data dir + // removeCacheDirs(); // Clean old data dir }) ipcMain.on('focus', () => win.focus())