Skip to content

Commit c5fcb9c

Browse files
committed
Set timeout parameter for terminal-notifier
-timeout option is now set when using terminal-notifier.
1 parent 61f142f commit c5fcb9c

File tree

2 files changed

+29
-20
lines changed

2 files changed

+29
-20
lines changed

send-notification/src/main/java/fr/jcgay/notification/notifier/notificationcenter/TerminalNotifier.java

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,6 @@ public class TerminalNotifier implements DiscoverableNotifier {
1717

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

20-
private static final String CMD_MESSAGE = "-message";
21-
private static final String CMD_TITLE = "-title";
22-
private static final String CMD_SUBTITLE = "-subtitle";
23-
private static final String CMD_GROUP = "-group";
24-
private static final String CMD_ACTIVATE = "-activate";
25-
private static final String CMD_CONTENT_IMAGE = "-contentImage";
26-
private static final String CMD_SOUND = "-sound";
27-
private static final String CMD_APP_ICON = "-appIcon";
28-
2920
private final Application application;
3021
private final TerminalNotifierConfiguration configuration;
3122
private final Executor executor;
@@ -47,28 +38,32 @@ public void send(Notification notification) {
4738

4839
List<String> commands = new ArrayList<String>();
4940
commands.add(configuration.bin());
50-
commands.add(CMD_TITLE);
41+
commands.add("-title");
5142
commands.add(application.name());
5243
if (notification.subtitle() != null) {
53-
commands.add(CMD_SUBTITLE);
44+
commands.add("-subtitle");
5445
commands.add(notification.subtitle());
5546
}
56-
commands.add(CMD_MESSAGE);
47+
commands.add("-message");
5748
commands.add(notification.message());
58-
commands.add(CMD_GROUP);
49+
commands.add("-group");
5950
commands.add(application.id());
6051
if (configuration.activateApplication() != null) {
61-
commands.add(CMD_ACTIVATE);
52+
commands.add("-activate");
6253
commands.add(configuration.activateApplication());
6354
}
64-
commands.add(CMD_CONTENT_IMAGE);
55+
commands.add("-contentImage");
6556
commands.add(notification.icon().asPath());
6657
if (configuration.sound() != null) {
67-
commands.add(CMD_SOUND);
58+
commands.add("-sound");
6859
commands.add(configuration.sound());
6960
}
70-
commands.add(CMD_APP_ICON);
61+
commands.add("-appIcon");
7162
commands.add(application.icon().asPath());
63+
if (application.timeout() != -1) {
64+
commands.add("-timeout");
65+
commands.add(String.valueOf(Math.round(application.timeout() / 1000)));
66+
}
7267

7368
try {
7469
executor.exec(commands.toArray(new String[commands.size()]));

send-notification/src/test/groovy/fr/jcgay/notification/notifier/notificationcenter/TerminalNotifierSpec.groovy

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ class TerminalNotifierSpec extends Specification {
2020

2121
def setup() {
2222
def configuration = TerminalNotifierConfiguration.create([
23-
'notifier.notification-center.path':TerminalNotifierConfiguration.byDefault().bin(),
24-
'notifier.notification-center.activate':'com.apple.Terminal',
25-
'notifier.notification-center.sound':'default'
23+
'notifier.notification-center.path' : TerminalNotifierConfiguration.byDefault().bin(),
24+
'notifier.notification-center.activate': 'com.apple.Terminal',
25+
'notifier.notification-center.sound' : 'default'
2626
] as Properties)
2727
notifier = new TerminalNotifier(application, configuration, executor)
2828
}
@@ -114,4 +114,18 @@ class TerminalNotifierSpec extends Specification {
114114
!result
115115
1 * executor.tryExec([TerminalNotifierConfiguration.byDefault().bin(), '-help']) >> false
116116
}
117+
118+
def "should set timeout when application includes one"() {
119+
given:
120+
def application = Application.builder('id', 'name', TestIcon.application()).timeout(1000).build()
121+
def notifier = new TerminalNotifier(application, TerminalNotifierConfiguration.byDefault(), executor)
122+
def notification = Notification.builder('title', 'message', TestIcon.ok()).build()
123+
124+
when:
125+
notifier.send(notification)
126+
127+
then:
128+
executor.executedCommand.join(' ').contains('-timeout 1')
129+
!executor.executedCommand.join(' ').contains('-timeout 1000')
130+
}
117131
}

0 commit comments

Comments
 (0)