diff --git a/electron/main.js b/electron/main.js index 71e1b9d..aaf311e 100644 --- a/electron/main.js +++ b/electron/main.js @@ -3,7 +3,35 @@ const isDev = require('electron-is-dev'); const path = require('path'); const fs = require('fs'); const crypto = require("crypto"); +const { shell } = require('electron'); let mainWindow; +const { Notification } = require('electron') + +function showNotification() { + const notification = { + title: 'Welcome to Crypt-It', + body: 'Get started with it and keep your files safe!' + } + new Notification(notification).show() +} + +app.whenReady().then(showNotification); + +function encryptNotification() { + const notification = { + title: 'Encryption Competed', + body: 'Your file has been encrypted successfully!!' + } + new Notification(notification).show() +} + +function decryptNotification(outFilePath) { + const notification = { + title: 'Decryption Competed', + body: 'Your file has been decrypted successfully and has been stored to ' + outFilePath + } + new Notification(notification).show() +} function createWindow() { mainWindow = new BrowserWindow({ @@ -21,9 +49,17 @@ function createWindow() { const startURL = isDev ? 'http://localhost:3000/' : `file://${path.join(__dirname, '../build/index.html')}`; mainWindow.loadURL(startURL); - + mainWindow.setIcon(path.join(__dirname, '../public/favicon.ico')); + mainWindow.maximize(); mainWindow.once('ready-to-show', () => mainWindow.show()); mainWindow.on('closed', () => { + try { + fs.rmdirSync(viewDir, { recursive: true }); + + console.log(`${viewDir} is deleted!`); + } catch (err) { + console.error(`Error while deleting ${viewDir}.`); + } mainWindow = null; }); } @@ -87,6 +123,7 @@ function Encrypt(key, inFilePath, outFilePath) { output.on('finish', function () { // ipcRenderer.send('encryption', output); console.log('Encrypted file written to disk!'); + encryptNotification(); }); fs.unlinkSync(inFilePath, (err) => { if (err) throw err; @@ -128,6 +165,7 @@ function Decrypt(key, inFilePath, outFilePath) { output.on('finish', function () { console.log(outFilePath); console.log('Decrypted file written to disk!'); + decryptNotification(outFilePath); }); // fs.unlinkSync(inFilepPath); @@ -172,16 +210,34 @@ function viewDecrypt(key, inFilePath, outFilePath) { console.log('Decrypted file written to disk!'); }); - shell.exec(outFilePath); + shell.openPath(outFilePath); + // del(outFilePath); + } -ipcMain.on('close', (event, arg) => { - try { - fs.rmdirSync(viewDir, { recursive: true }); +// var delInterval = setInterval(del(), 1000); + +// function del(filePath){ +// fs.open(filePath, 'r+', function(err, fd){ +// if (err && err.code === 'EBUSY'){ +// //do nothing till next loop +// } else if (err && err.code === 'ENOENT'){ +// console.log(filePath, 'deleted'); +// clearInterval(delInterval); +// } else { +// fs.close(fd, function(){ +// fs.unlink(filePath, function(err){ +// if(err){ +// } else { +// console.log(filePath, 'deleted'); +// clearInterval(delInterval); +// } +// }); +// }); +// } +// }); +// } - console.log(`${viewDir} is deleted!`); - } catch (err) { - console.error(`Error while deleting ${viewDir}.`); - } +ipcMain.on('close', (event, arg) => { app.quit(); }); \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 20b91ec..eb51fa0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8229,6 +8229,11 @@ "side-channel": "^1.0.4" } }, + "interpret": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/interpret/-/interpret-1.4.0.tgz", + "integrity": "sha512-agE4QfB2Lkp9uICn7BAqoscw4SZP9kTE2hxiFI3jBPmXJfdqiahTbUuKGsMoN2GtqL9AxhYioAcVvgsb1HvRbA==" + }, "invariant": { "version": "2.2.4", "resolved": "https://registry.npmjs.org/invariant/-/invariant-2.2.4.tgz", @@ -13140,6 +13145,14 @@ "picomatch": "^2.2.1" } }, + "rechoir": { + "version": "0.6.2", + "resolved": "https://registry.npmjs.org/rechoir/-/rechoir-0.6.2.tgz", + "integrity": "sha1-hSBLVNuoLVdC4oyWdW70OvUOM4Q=", + "requires": { + "resolve": "^1.1.6" + } + }, "recursive-readdir": { "version": "2.2.2", "resolved": "https://registry.npmjs.org/recursive-readdir/-/recursive-readdir-2.2.2.tgz", @@ -14237,6 +14250,16 @@ "resolved": "https://registry.npmjs.org/shell.js/-/shell.js-3.2.3.tgz", "integrity": "sha512-FBy/2W05kbwlOCrKDCuVjbhHxs5IK20EjVp1dNxLBjsPggC4gS3BJWqexRbVrmzOJ4d0mS+FRmfVsBJJUasqxw==" }, + "shelljs": { + "version": "0.8.4", + "resolved": "https://registry.npmjs.org/shelljs/-/shelljs-0.8.4.tgz", + "integrity": "sha512-7gk3UZ9kOfPLIAbslLzyWeGiEqx9e3rxwZM0KE6EL8GlGwjym9Mrlx5/p33bWTu9YG6vcS4MBxYZDHYr5lr8BQ==", + "requires": { + "glob": "^7.0.0", + "interpret": "^1.0.0", + "rechoir": "^0.6.2" + } + }, "shellwords": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/shellwords/-/shellwords-0.1.1.tgz", diff --git a/package.json b/package.json index b1a7ac3..f66d266 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ "react-scripts": "4.0.3", "sass": "^1.32.8", "shell.js": "^3.2.3", + "shelljs": "^0.8.4", "styled-components": "^5.2.1", "wait-on": "^5.2.1", "web-vitals": "^1.1.0" diff --git a/public/favicon.ico b/public/favicon.ico index a11777c..a4124a1 100644 Binary files a/public/favicon.ico and b/public/favicon.ico differ diff --git a/public/index.html b/public/index.html index 4ff10b1..d9781ba 100644 --- a/public/index.html +++ b/public/index.html @@ -27,7 +27,7 @@ work correctly both with client-side routing and a non-root public URL. Learn how to configure a non-root public URL by running `npm run build`. --> -