Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(GUI): multiple JSON objects coming up at once from the IPC client #997

Merged
merged 1 commit into from Jan 5, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 15 additions & 1 deletion lib/src/child-writer/writer-proxy.js
Expand Up @@ -157,7 +157,21 @@ return isElevated().then((elevated) => {
child.on('close', resolve);

const emitMessage = (data) => {
ipc.of[process.env.IPC_SERVER_ID].emit('message', data.toString());

// Output from stdout/stderr coming from the CLI might be buffered,
// causing several progress lines to come up at once as single message.
// Trying to parse multiple JSON objects separated by new lines will
// of course make the parser confused, causing errors later on.
//
// As a solution, we split the data coming in from the CLI into
// separate lines, and only emit a "message" event for the last one.
//
// Since each line is terminated by a new line, the last string
// is an empty string, which we don't want to send to the IPC
// server, so we take the last element of every element but the last.
const object = _.last(_.initial(_.split(data.toString(), /\r?\n/)));
ipc.of[process.env.IPC_SERVER_ID].emit('message', object);

};

child.stdout.on('data', emitMessage);
Expand Down