From ebf749190a00fcb96728e06f539c2c2a7d6c57ab Mon Sep 17 00:00:00 2001 From: "Yasmin Seidel (JasminDreasond)" Date: Tue, 15 Aug 2023 21:31:31 -0300 Subject: [PATCH] temp cleaner added --- electron/fs/deleteAllFilesInDir.js | 16 ++++++++++++++++ electron/main/notification/index.js | 4 ++++ 2 files changed, 20 insertions(+) create mode 100644 electron/fs/deleteAllFilesInDir.js diff --git a/electron/fs/deleteAllFilesInDir.js b/electron/fs/deleteAllFilesInDir.js new file mode 100644 index 000000000..c4c2bff10 --- /dev/null +++ b/electron/fs/deleteAllFilesInDir.js @@ -0,0 +1,16 @@ +import fs from 'fs/promises'; +import path from 'path'; + +export default async function deleteAllFilesInDir(dirPath) { + try { + const files = await fs.readdir(dirPath); + + const deleteFilePromises = files.map(file => + fs.unlink(path.join(dirPath, file)), + ); + + await Promise.all(deleteFilePromises); + } catch (err) { + console.log(err); + } +}; \ No newline at end of file diff --git a/electron/main/notification/index.js b/electron/main/notification/index.js index d0ae87da5..d0f236d6e 100644 --- a/electron/main/notification/index.js +++ b/electron/main/notification/index.js @@ -2,8 +2,10 @@ import fs from 'fs'; import path from 'path'; import { app, Notification } from 'electron'; +import deleteAllFilesInDir from '../../fs/deleteAllFilesInDir'; import { objType } from '../../../src/util/tools'; +// Validate Folders const tempFolder = path.join(app.getPath('temp'), './pony-house-matrix'); if (!fs.existsSync(tempFolder)) { fs.mkdirSync(tempFolder); @@ -14,6 +16,8 @@ if (!fs.existsSync(tempFolderNoti)) { fs.mkdirSync(tempFolderNoti); } +deleteAllFilesInDir(tempFolderNoti); + // Module const notifications = {}; export default function startNotifications(ipcMain) {