From cc23e3aa7543170a4de82d2ae571e08d4984f662 Mon Sep 17 00:00:00 2001 From: John Murphy-Teixidor Date: Sat, 27 Aug 2016 00:00:18 -0400 Subject: [PATCH 1/3] Fixed Darwin special characters and spaces --- capture/darwin.js | 8 ++++---- module.js | 4 ++-- package.json | 3 ++- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/capture/darwin.js b/capture/darwin.js index 5491252..b2b15ca 100644 --- a/capture/darwin.js +++ b/capture/darwin.js @@ -1,9 +1,9 @@ module.exports = function(options, callback) { - var path = require('path'); + var path = require('flavored-path'); var fs = require('fs'); var childProcess = require('child_process'); - + // due to bug in jpgjs processing OSX jpg images https://github.com/notmasteryet/jpgjs/issues/34 // when requesting JPG capture as PNG, so JIMP can read it var ext = extension(options.output); @@ -36,8 +36,8 @@ module.exports = function(options, callback) { function capture(output, callback) { var cmd = "screencapture" - + " -t " + path.extname(output).toLowerCase().substring(1) // will create PNG by default - + " -x " + output; + + " -t " + path.extname(output).toLowerCase().substring(1) // will create PNG by default + + " -x " + output.replace(/ /g, '\\ ') + ""; childProcess.exec(cmd, function(error, stdout, stderr) { if(error) diff --git a/module.js b/module.js index 8a36f48..fdaee33 100755 --- a/module.js +++ b/module.js @@ -2,7 +2,7 @@ module.exports = function() { return new Screenshot(arguments); }; -var path = require('path'); +var path = require('flavored-path'); var jimp = require('jimp'); var fs = require('fs'); @@ -94,7 +94,7 @@ Screenshot.prototype.parseArgs = function(args) { config.options.output = file; if(typeof config.options.output === "string") - config.options.output = path.resolve(config.options.output); + config.options.output = path.normalize(config.options.output); return config; }; diff --git a/package.json b/package.json index edbb2a5..4a5564a 100755 --- a/package.json +++ b/package.json @@ -12,7 +12,8 @@ "url": "https://github.com/johnvmt/node-desktop-screenshot" }, "dependencies": { - "jimp": "0.2.x" + "jimp": "0.2.x", + "flavored-path": "0.0.x" }, "main": "module.js" } From 5e24336fa1dd3a988e6ff3ee09a8dbf0b70f7db8 Mon Sep 17 00:00:00 2001 From: John Murphy-Teixidor Date: Sat, 27 Aug 2016 23:09:08 -0400 Subject: [PATCH 2/3] Changed exec to spawn --- capture/darwin.js | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/capture/darwin.js b/capture/darwin.js index b2b15ca..7b64886 100644 --- a/capture/darwin.js +++ b/capture/darwin.js @@ -1,9 +1,8 @@ module.exports = function(options, callback) { - - var path = require('flavored-path'); + var path = require('path'); var fs = require('fs'); var childProcess = require('child_process'); - + // due to bug in jpgjs processing OSX jpg images https://github.com/notmasteryet/jpgjs/issues/34 // when requesting JPG capture as PNG, so JIMP can read it var ext = extension(options.output); @@ -35,22 +34,26 @@ module.exports = function(options, callback) { } function capture(output, callback) { - var cmd = "screencapture" - + " -t " + path.extname(output).toLowerCase().substring(1) // will create PNG by default - + " -x " + output.replace(/ /g, '\\ ') + ""; - - childProcess.exec(cmd, function(error, stdout, stderr) { - if(error) - callback(error, null); - else { - try { - fs.statSync(output); - callback(null, true); - } - catch (error) { - callback(error, null); - } - } + var cmd = "screencapture"; + var args = [ + // will create PNG by default + "-t", + path.extname(output).toLowerCase().substring(1), + "-x", + output + ]; + + var captureChild = childProcess.spawn(cmd, args); + + captureChild.on('close', function(error) { + if (error) + callback(error.toString()); + else + callback(); + }); + + captureChild.stderr.on('data', function(data) { + callback(data.toString()); }); } }; \ No newline at end of file From 267f65e48a3a8e47c43bdf53c748c93614973404 Mon Sep 17 00:00:00 2001 From: John Murphy-Teixidor Date: Sun, 28 Aug 2016 18:34:54 -0400 Subject: [PATCH 3/3] Bumped to 0.1.1, Fixes to darwin for paths with special characters --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4a5564a..8606fab 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "desktop-screenshot", - "version": "0.1.0", + "version": "0.1.1", "description": "Cross-platform screenshot module, using external tools", "license": "MIT", "author": {