From 8f55cedc6a5aab3ba39e649ec7a5574bea43d462 Mon Sep 17 00:00:00 2001 From: Himshwet Gaurav Date: Sun, 28 Jan 2018 18:29:58 +0530 Subject: [PATCH] 69 Fix notifications on linux when using notify-send (#70) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Remove cmd.msg from args when using notify-send Fixes Issue#69 https://github.com/tj/node-growl/issues/69 On linux notify-send responds with 'Invalid number of options' because of an extra empty '' argument introduced by cmd.msg * Fix options.sticky argument when using notify-send When using the sticky option with notify-send, it interprets '-t 0' as a single argument. To resolve that '-t' and '0' are sent as separate arguments. - Executing the following command "notify-send '-t 0' 'Email Client' '5 new emails' " - results in "Cannot parse integer value “Email Client” for -t" * Log cmd and args to stderr for easier debugging --- lib/growl.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/growl.js b/lib/growl.js index 4636927..c38d3c1 100644 --- a/lib/growl.js +++ b/lib/growl.js @@ -86,7 +86,7 @@ function setupCmd() { type: 'Linux', pkg: 'notify-send', msg: '', - sticky: '-t 0', + sticky: '-t', icon: '-i', priority: { cmd: '-u', @@ -214,6 +214,7 @@ function growl(msg, opts, callback) { // sticky if (options.sticky) args.push(cmd.sticky); + if (options.sticky && cmd.type === 'Linux') args.push('0'); // priority if (options.priority) { @@ -272,13 +273,8 @@ function growl(msg, opts, callback) { } break; case 'Linux': - if (options.title) { - args.push(options.title); - args.push(cmd.msg); - args.push(msg.replace(/\\n/g, '\n')); - } else { - args.push(msg.replace(/\\n/g, '\n')); - } + if (options.title) args.push(options.title); + args.push(msg.replace(/\\n/g, '\n')); break; case 'Windows': args.push(msg.replace(/\\n/g, '\n')); @@ -312,6 +308,11 @@ function growl(msg, opts, callback) { let stderr = ''; let error; + const now = new Date(); + const timestamp = `${now.getHours()}:${now.getMinutes()}:${now.getSeconds()}.${now.getMilliseconds()}` + + stderr += `[${timestamp}][node-growl] : Executed command '${cmdToExec}' with arguments '${args}'\n[stderr] : `; + child.on('error', (err) => { console.error('An error occured.', err); error = err;