From 3a6d3bb8c219ee0a8ebbe95445659207396f9005 Mon Sep 17 00:00:00 2001 From: Spencer Ofwiti Date: Wed, 26 May 2021 10:00:08 +0300 Subject: [PATCH] Refactor file management functions. --- src-backend/main.ts | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src-backend/main.ts b/src-backend/main.ts index 53cf1c2..8dad0c0 100644 --- a/src-backend/main.ts +++ b/src-backend/main.ts @@ -53,26 +53,26 @@ function isRoot(): boolean { } function getImages(): void { - // const cwd = process.cwd(); - // fs.readdir('.', { withFileTypes: true }, ((err, files) => { - // if (!err) { - // const re = /(?:\.([^.]+))?$/; - // const images = files.filter(file => file.isFile() && ['jpg', 'png'].includes(re.exec(file.name)[1])).map(file => `file://${cwd}/${file.name}`); - // mainWindow.webContents.send('getImagesResponse', images); - // } - // })); + const cwd = process.cwd(); + fs.readdir('.', { withFileTypes: true }, ((err, files) => { + if (!err) { + const re = /(?:\.([^.]+))?$/; + const images = files.filter(file => file.isFile() && ['jpg', 'png'].includes(re.exec(file.name)[1])).map(file => `file://${cwd}/${file.name}`); + mainWindow.webContents.send('getImagesResponse', images); + } + })); } function getDirectory(): void { - // fs.readdir('.', { withFileTypes: true }, (err, files) => { - // if (!err) { - // const directories = files.filter(file => file.isDirectory()).map(file => file.name); - // if (!isRoot()) { - // directories.unshift('..'); - // } - // mainWindow.webContents.send('getDirectoryResponse', directories); - // } - // }); + fs.readdir('.', { withFileTypes: true }, (err, files) => { + if (!err) { + const directories = files.filter(file => file.isDirectory()).map(file => file.name); + if (!isRoot()) { + directories.unshift('..'); + } + mainWindow.webContents.send('getDirectoryResponse', directories); + } + }); } // This method will be called when Electron has finished