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

Allow timeout: false to remove a timeout #271

Merged
merged 2 commits into from Aug 4, 2019
Merged
Show file tree
Hide file tree
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
6 changes: 1 addition & 5 deletions README.md
Expand Up @@ -186,11 +186,7 @@ notifier.notify(
**Note:** The `wait` option is shorthand for `timeout: 5`. This just sets a timeout
for 5 seconds. It does _not_ make the notification sticky!

Without `wait` or `timeout`, notifications are just fired and forgotten. They don't
wait for any response.

To make notifications wait for a response (like activation/click), you must define
a `timeout`.
As of 5.4.0, `timeout` defaults to `10`. In order to have a "fire and forgotten" notification, you need to set `timeout` to `false`.

_Exception:_ If `reply` is defined, it's recommended to set `timeout` to a either
high value, or to nothing at all.
Expand Down
8 changes: 8 additions & 0 deletions lib/utils.js
Expand Up @@ -210,6 +210,14 @@ module.exports.mapToMac = function(options) {
delete options.wait;
}

if (!options.wait && !options.timeout) {
if (options.timeout === false) {
delete options.timeout;
} else {
options.timeout = 10;
}
}

options.json = true;
return options;
};
Expand Down
22 changes: 22 additions & 0 deletions test/terminal-notifier.js
Expand Up @@ -273,6 +273,28 @@ describe('terminal-notifier', function() {
});
});

it('should not set a default timeout if explicitly false', function(done) {
var expected = [
'-title',
'"Title"',
'-message',
'"Message"',
'-json',
'"true"'
];

expectArgsListToBe(expected, done);
var notifier = new NotificationCenter();
notifier.isNotifyChecked = true;
notifier.hasNotifier = true;

notifier.notify({
title: 'Title',
message: 'Message',
timeout: false
});
});

it('should escape all title and message', function(done) {
var expected = [
'-title',
Expand Down