Skip to content

Commit

Permalink
Set timeout parameter for terminal-notifier
Browse files Browse the repository at this point in the history
-timeout option is now set when using terminal-notifier.
  • Loading branch information
jcgay committed Nov 1, 2017
1 parent 61f142f commit c5fcb9c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,6 @@ public class TerminalNotifier implements DiscoverableNotifier {

private static final Logger LOGGER = LoggerFactory.getLogger(TerminalNotifier.class);

private static final String CMD_MESSAGE = "-message";
private static final String CMD_TITLE = "-title";
private static final String CMD_SUBTITLE = "-subtitle";
private static final String CMD_GROUP = "-group";
private static final String CMD_ACTIVATE = "-activate";
private static final String CMD_CONTENT_IMAGE = "-contentImage";
private static final String CMD_SOUND = "-sound";
private static final String CMD_APP_ICON = "-appIcon";

private final Application application;
private final TerminalNotifierConfiguration configuration;
private final Executor executor;
Expand All @@ -47,28 +38,32 @@ public void send(Notification notification) {

List<String> commands = new ArrayList<String>();
commands.add(configuration.bin());
commands.add(CMD_TITLE);
commands.add("-title");
commands.add(application.name());
if (notification.subtitle() != null) {
commands.add(CMD_SUBTITLE);
commands.add("-subtitle");
commands.add(notification.subtitle());
}
commands.add(CMD_MESSAGE);
commands.add("-message");
commands.add(notification.message());
commands.add(CMD_GROUP);
commands.add("-group");
commands.add(application.id());
if (configuration.activateApplication() != null) {
commands.add(CMD_ACTIVATE);
commands.add("-activate");
commands.add(configuration.activateApplication());
}
commands.add(CMD_CONTENT_IMAGE);
commands.add("-contentImage");
commands.add(notification.icon().asPath());
if (configuration.sound() != null) {
commands.add(CMD_SOUND);
commands.add("-sound");
commands.add(configuration.sound());
}
commands.add(CMD_APP_ICON);
commands.add("-appIcon");
commands.add(application.icon().asPath());
if (application.timeout() != -1) {
commands.add("-timeout");
commands.add(String.valueOf(Math.round(application.timeout() / 1000)));
}

try {
executor.exec(commands.toArray(new String[commands.size()]));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ class TerminalNotifierSpec extends Specification {

def setup() {
def configuration = TerminalNotifierConfiguration.create([
'notifier.notification-center.path':TerminalNotifierConfiguration.byDefault().bin(),
'notifier.notification-center.activate':'com.apple.Terminal',
'notifier.notification-center.sound':'default'
'notifier.notification-center.path' : TerminalNotifierConfiguration.byDefault().bin(),
'notifier.notification-center.activate': 'com.apple.Terminal',
'notifier.notification-center.sound' : 'default'
] as Properties)
notifier = new TerminalNotifier(application, configuration, executor)
}
Expand Down Expand Up @@ -114,4 +114,18 @@ class TerminalNotifierSpec extends Specification {
!result
1 * executor.tryExec([TerminalNotifierConfiguration.byDefault().bin(), '-help']) >> false
}

def "should set timeout when application includes one"() {
given:
def application = Application.builder('id', 'name', TestIcon.application()).timeout(1000).build()
def notifier = new TerminalNotifier(application, TerminalNotifierConfiguration.byDefault(), executor)
def notification = Notification.builder('title', 'message', TestIcon.ok()).build()

when:
notifier.send(notification)

then:
executor.executedCommand.join(' ').contains('-timeout 1')
!executor.executedCommand.join(' ').contains('-timeout 1000')
}
}

0 comments on commit c5fcb9c

Please sign in to comment.