Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 22 additions & 16 deletions electron/register-ipc.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,27 @@ const rename = util.promisify(fs.rename);
const writeFile = util.promisify(fs.writeFile);
const stat = util.promisify(fs.stat);

function walk_through(e, folderPath) {
fs.readdir(folderPath, (err, files) => {
if (err) return;

files.forEach(file => {
const fullPath = path.join(folderPath, file);
const extension = path.extname(file);
fs.stat(fullPath, (err, stats) => {
if (err) return;
if (stats.isDirectory()) {
walk_through(e, fullPath);
} else {
if (extension === '.png' || extension === '.jpg' || extension === '.jpeg') {
e.sender.send('manual-image-add', [fullPath, stats.size]);
}
}
});
});
});
}

/**
* Registers all ipc listeners
* @param {Electron.BrowserWindow} mainWindow Window to show dialogs under
Expand Down Expand Up @@ -134,22 +155,7 @@ function registerIpcListeners(mainWindow) {
});

ipcMain.on('folder-dropped', async (e, folderPath) => {
fs.readdir(folderPath, (err, files) => {
if (err) return;

files.forEach(file => {
const fullPath = path.join(folderPath, file);
const extension = path.extname(file);

if (extension === '.png' || extension === '.jpg' || extension === '.jpeg') {
fs.stat(fullPath, (err, stats) => {
if (err) return;

e.sender.send('manual-image-add', [fullPath, stats.size]);
});
}
})
});
walk_through(e, folderPath);
});
}

Expand Down