Skip to content

Commit

Permalink
clear leveldb log
Browse files Browse the repository at this point in the history
  • Loading branch information
shrpne committed May 13, 2019
1 parent df08cfe commit a3fe062
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
35 changes: 35 additions & 0 deletions desktop/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand Down Expand Up @@ -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;
});
Expand Down Expand Up @@ -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
*
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "minter-console-web",
"version": "0.3.0",
"version": "0.4.0",
"description": "Minter Console Website",
"author": "shrpne <[email protected]>",
"private": true,
Expand Down

0 comments on commit a3fe062

Please sign in to comment.