From a3fe062917beed910de6f20a9ec394e36dcae700 Mon Sep 17 00:00:00 2001 From: shrpne Date: Mon, 13 May 2019 18:15:09 +0300 Subject: [PATCH] clear leveldb log --- desktop/electron.js | 35 +++++++++++++++++++++++++++++++++++ package.json | 2 +- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/desktop/electron.js b/desktop/electron.js index 10e25d44..154222e5 100644 --- a/desktop/electron.js +++ b/desktop/electron.js @@ -41,6 +41,7 @@ const _NUXT_URL_ = `http://${HOST_NAME}:${PORT}/`; ** Electron */ +const fs = require('fs'); const { app, BrowserWindow, Menu } = require('electron'); // eslint-disable-line /** @@ -95,6 +96,19 @@ function createWindow() { mainWindow.webContents.openDevTools(); } + // clear leveldb log if localStorage is empty + mainWindow.on('close', async () => { + let vuex = await mainWindow.webContents.executeJavaScript(`window.localStorage.getItem('vuex')`); + vuex = vuex && JSON.parse(vuex); + if (!vuex.auth.advanced && !vuex.auth.password) { + const dbPath = path.join(app.getPath('userData'), 'Local Storage/leveldb'); + const logs = findInDir(dbPath, '.log'); + logs.forEach((filePath) => { + fs.unlinkSync(filePath); + }); + } + }); + mainWindow.on('closed', () => { mainWindow = null; }); @@ -123,6 +137,27 @@ function createMenu() { Menu.setApplicationMenu(Menu.buildFromTemplate(template)); } +function findInDir(startPath, filter) { + let result = []; + + if (!fs.existsSync(startPath)) { + return result; + } + + const files = fs.readdirSync(startPath); + for (let i = 0; i < files.length; i++) { + const filename = path.join(startPath, files[i]); + const stat = fs.lstatSync(filename); + if (stat.isDirectory()) { + result = result.concat(findInDir(filename, filter)); //recurse + } else if (filename.indexOf(filter) >= 0) { + result.push(filename); + } + } + + return result; +} + /** * Auto Updater * diff --git a/package.json b/package.json index 6ce1593d..b7cffab1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "minter-console-web", - "version": "0.3.0", + "version": "0.4.0", "description": "Minter Console Website", "author": "shrpne ", "private": true,