Skip to content

Commit

Permalink
69 Fix notifications on linux when using notify-send (#70)
Browse files Browse the repository at this point in the history
* Remove cmd.msg from args when using notify-send

Fixes Issue#69 #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
  • Loading branch information
hmshwt authored and deiga committed Jan 28, 2018
1 parent 1ccc7e8 commit 8f55ced
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions lib/growl.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ function setupCmd() {
type: 'Linux',
pkg: 'notify-send',
msg: '',
sticky: '-t 0',
sticky: '-t',
icon: '-i',
priority: {
cmd: '-u',
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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'));
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 8f55ced

Please sign in to comment.