Skip to content

Commit

Permalink
Added ability to drop folders
Browse files Browse the repository at this point in the history
  • Loading branch information
christopherwk210 committed Jan 15, 2019
1 parent 64d2c00 commit 60c4d01
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 3 deletions.
2 changes: 1 addition & 1 deletion electron/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"main": "electron.js",
"version": "1.1.0",
"version": "1.2.0",
"dependencies": {
"electron-settings": "^3.2.0",
"feather-icons": "^4.10.0",
Expand Down
20 changes: 20 additions & 0 deletions electron/register-ipc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
const { app, dialog, ipcMain, shell } = require('electron');
const tinify = require('tinify');
const fs = require('fs');
const path = require('path');
const util = require('util');
const settings = require('electron-settings');

Expand Down Expand Up @@ -131,6 +132,25 @@ 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]);
});
}
})
});
});
}

module.exports = registerIpcListeners;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bamboo",
"version": "1.1.2",
"version": "1.2.0",
"description": "A cross-platform TinyPNG client 🌱🎍",
"scripts": {
"build.win": "npm run build.parcel && npm run build.electron.win32",
Expand Down
9 changes: 9 additions & 0 deletions src/assets/scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@ let app = new Vue({
if (~file.type.indexOf('png') || ~file.type.indexOf('jpg') || ~file.type.indexOf('jpeg')) {
this.addImage(file.path, file.size);
}

if (!file.type) {
ipcRenderer.send('folder-dropped', file.path);
}
});
return false;
}
Expand Down Expand Up @@ -209,3 +213,8 @@ ipcRenderer.on('imageComplete', (e, args) => {
}
});
});

// On folder parse image
ipcRenderer.on('manual-image-add', (e, args) => {
app.addImage(args[0], args[1]);
});
2 changes: 1 addition & 1 deletion src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<!-- Drop file text -->
<div v-bind:class="{ drag: draggingOver }" v-if="!imageList.length" class="drag-drop drop-target" @dragenter="handleDragenter" @dragleave="handleDragleave" @dragend="handleDragend" @drop="handleDrop">
<p>
<i data-feather="droplet"></i> <span>Drop a PNG or JPG here!</span>
<i data-feather="droplet"></i> <span>Drop a PNG, JPG, or folder here!</span>
</p>
</div>

Expand Down

0 comments on commit 60c4d01

Please sign in to comment.