diff --git a/js/cryptoLib/index.js b/js/cryptoLib/index.js index 9189cb92..b5bb8cd9 100644 --- a/js/cryptoLib/index.js +++ b/js/cryptoLib/index.js @@ -116,32 +116,6 @@ class Crypto { }); }); } - - /** - * Deleting the data index folder - * when the app is closed - */ - deleteFolders() { - Crypto.deleteFolderRecursive(this.dataFolder); - } - - /** - * Removing all the folders and files inside the data folder - * @param location - */ - static deleteFolderRecursive(location) { - if (fs.existsSync(location)) { - fs.readdirSync(location).forEach((file) => { - let curPath = location + "/" + file; - if (fs.lstatSync(curPath).isDirectory()) { - Crypto.deleteFolderRecursive(curPath); - } else { - fs.unlinkSync(curPath); - } - }); - fs.rmdirSync(location); - } - } } module.exports = Crypto; \ No newline at end of file diff --git a/js/main.js b/js/main.js index a1ca5049..92937eef 100644 --- a/js/main.js +++ b/js/main.js @@ -18,8 +18,7 @@ const protocolHandler = require('./protocolHandler'); const getCmdLineArg = require('./utils/getCmdLineArg.js'); const log = require('./log.js'); const logLevels = require('./enums/logLevels.js'); -const Crypto = require('./cryptoLib'); -const crypto = new Crypto(); +const { deleteIndexFolder } = require('./search/search.js'); require('electron-dl')(); @@ -132,7 +131,7 @@ app.on('activate', function() { app.on('will-quit', function (e) { e.preventDefault(); - crypto.deleteFolders(); + deleteIndexFolder(); app.exit(); }); diff --git a/js/preload/preloadMain.js b/js/preload/preloadMain.js index c9f64cd1..ff9b937f 100644 --- a/js/preload/preloadMain.js +++ b/js/preload/preloadMain.js @@ -136,6 +136,11 @@ function createAPI() { */ Search: remote.require('./search/search.js').Search, + /** + * Function to clear the user index data + */ + deleteIndexFolder: remote.require('./search/search.js').deleteIndexFolder, + /** * Brings window forward and gives focus. * @param {String} windowName Name of window. Note: main window name is 'main' diff --git a/js/search/search.js b/js/search/search.js index 1e2d7dd5..dc2a9f06 100644 --- a/js/search/search.js +++ b/js/search/search.js @@ -492,6 +492,33 @@ class Search { throw new Error(err); } } + + /** + * Removing all the folders and files inside the data folder + * @param location + */ + static deleteFolderRecursive(location) { + if (fs.existsSync(location)) { + fs.readdirSync(location).forEach((file) => { + let curPath = location + "/" + file; + if (fs.lstatSync(curPath).isDirectory()) { + Search.deleteFolderRecursive(curPath); + } else { + fs.unlinkSync(curPath); + } + }); + fs.rmdirSync(location); + } + } + +} + +/** + * Deleting the data index folder + * when the app is closed/signed-out/navigates + */ +function deleteIndexFolder() { + Search.deleteFolderRecursive(INDEX_DATA_FOLDER); } /** @@ -499,5 +526,6 @@ class Search { * @type {{Search: Search}} */ module.exports = { - Search: Search + Search: Search, + deleteIndexFolder: deleteIndexFolder }; diff --git a/js/windowMgr.js b/js/windowMgr.js index 600ef2b1..e76559be 100644 --- a/js/windowMgr.js +++ b/js/windowMgr.js @@ -20,6 +20,7 @@ const eventEmitter = require('./eventEmitter'); const throttle = require('./utils/throttle.js'); const { getConfigField, updateConfigField } = require('./config.js'); const { isMac, isNodeEnv } = require('./utils/misc'); +const { deleteIndexFolder } = require('./search/search.js'); // show dialog when certificate errors occur require('./dialogs/showCertError.js'); @@ -256,6 +257,11 @@ function doCreateMainWindow(initialUrl, initialBounds) { }); }); + // To delete the user index data folder on navigation + mainWindow.webContents.on('will-navigate', () => { + deleteIndexFolder(); + }); + getConfigField('url') .then(initializeCrashReporter) .catch(app.quit);