From 60c4d017fcea5dc237e91fdede29e1efbe54a145 Mon Sep 17 00:00:00 2001 From: Chris Anselmo Date: Tue, 15 Jan 2019 09:34:31 -0800 Subject: [PATCH] Added ability to drop folders --- electron/package.json | 2 +- electron/register-ipc.js | 20 ++++++++++++++++++++ package.json | 2 +- src/assets/scripts/main.js | 9 +++++++++ src/index.html | 2 +- 5 files changed, 32 insertions(+), 3 deletions(-) diff --git a/electron/package.json b/electron/package.json index f5402d8..e47bd3e 100644 --- a/electron/package.json +++ b/electron/package.json @@ -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", diff --git a/electron/register-ipc.js b/electron/register-ipc.js index 34e9b00..c44f2ae 100644 --- a/electron/register-ipc.js +++ b/electron/register-ipc.js @@ -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'); @@ -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; diff --git a/package.json b/package.json index 51f9d45..89edb2c 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/assets/scripts/main.js b/src/assets/scripts/main.js index 5e6467f..0ed1d79 100644 --- a/src/assets/scripts/main.js +++ b/src/assets/scripts/main.js @@ -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; } @@ -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]); +}); diff --git a/src/index.html b/src/index.html index 5a3cd0c..031ade9 100644 --- a/src/index.html +++ b/src/index.html @@ -24,7 +24,7 @@

- Drop a PNG or JPG here! + Drop a PNG, JPG, or folder here!