Permalink
Browse files

Add Windows compatibility by using a temporary file instead of a pipe…

… for sending the configuration
  • Loading branch information...
1 parent 3663e4f commit d85da6a6d2347a45456eee1a2fcecbf71e9e0f0d @mixu committed Jan 5, 2017
Showing with 16 additions and 13 deletions.
  1. +10 −7 bin/electroshot.js
  2. +6 −6 electron/index.js
View
@@ -1,7 +1,8 @@
#!/usr/bin/env node
var fs = require('fs'),
path = require('path'),
- spawn = require('child_process').spawn;
+ spawn = require('child_process').spawn,
+ os = require('os');
var electron = require('electron'),
express = require('express'),
@@ -80,8 +81,10 @@ if (pairs.length > 0) {
// run electron and pipe the tasks into it
function runElectron() {
+ var configFile = os.tmpdir() + '/electroshot-config.json';
+
var electronArgs = [
- __dirname + '/../electron/index.js'
+ path.join(__dirname, '..', 'electron', 'index.js')
].concat(Object.keys(argv).filter(function(key) {
return typeof defaultOptions[key] === 'undefined' && key !== '_' || key === 'debug';
}).reduce(function(all, key) {
@@ -90,13 +93,13 @@ function runElectron() {
} else {
return all.concat('--' + (!argv[key] ? 'no-' : '') + key);
}
- }, []));
+ }, [])).concat(['--config', configFile]);
- var child = spawn(electron, electronArgs, {
- stdio: ['pipe', process.stdout, process.stderr]
- });
+ // Windows does not support piped stdio on GUI programs like electron
+ // see https://github.com/electron/electron/issues/4218
+ fs.writeFileSync(configFile, JSON.stringify(tasks));
- child.stdin.end(JSON.stringify(tasks));
+ var child = spawn(electron, electronArgs, {stdio: 'ignore'});
child.on('exit', function(code) {
if (server) {
View
@@ -36,12 +36,12 @@ app.on('window-all-closed', function() {
app.quit();
});
+var buffer = fs.readFileSync(argv.config, 'utf8');
+
app.on('ready', function() {
- var buffer = '';
- process.stdin.on('data', function(data) {
- buffer += data.toString();
- });
- process.stdin.once('end', function() {
+ try {
runTasks(JSON.parse(buffer));
- });
+ } catch (e) {
+ console.log(e);
+ }
});

0 comments on commit d85da6a

Please sign in to comment.