notifier: move osx terminal-notifier test to executor

Additionally set a timeout on the process
This commit is contained in:
Adam
2020-11-28 14:40:35 -05:00
parent e9acabf549
commit a658d94db0

View File

@@ -114,7 +114,7 @@ public class Notifier
private final ChatMessageManager chatMessageManager; private final ChatMessageManager chatMessageManager;
private final EventBus eventBus; private final EventBus eventBus;
private final Path notifyIconPath; private final Path notifyIconPath;
private final boolean terminalNotifierAvailable; private boolean terminalNotifierAvailable;
private Instant flashStart; private Instant flashStart;
private long mouseLastPressedMillis; private long mouseLastPressedMillis;
private long lastClipMTime = CLIP_MTIME_UNLOADED; private long lastClipMTime = CLIP_MTIME_UNLOADED;
@@ -138,9 +138,10 @@ public class Notifier
this.notifyIconPath = RuneLite.RUNELITE_DIR.toPath().resolve("icon.png"); this.notifyIconPath = RuneLite.RUNELITE_DIR.toPath().resolve("icon.png");
// First check if we are running in launcher // First check if we are running in launcher
this.terminalNotifierAvailable = if (!Strings.isNullOrEmpty(RuneLiteProperties.getLauncherVersion()) && OSType.getOSType() == OSType.MacOS)
!Strings.isNullOrEmpty(RuneLiteProperties.getLauncherVersion()) {
&& isTerminalNotifierAvailable(); executorService.execute(() -> terminalNotifierAvailable = isTerminalNotifierAvailable());
}
storeIcon(); storeIcon();
} }
@@ -389,21 +390,19 @@ public class Notifier
private boolean isTerminalNotifierAvailable() private boolean isTerminalNotifierAvailable()
{ {
if (OSType.getOSType() == OSType.MacOS) try
{ {
try final Process exec = Runtime.getRuntime().exec(new String[]{"terminal-notifier", "-help"});
{ if (!exec.waitFor(2, TimeUnit.SECONDS))
final Process exec = Runtime.getRuntime().exec(new String[]{"terminal-notifier", "-help"});
exec.waitFor();
return exec.exitValue() == 0;
}
catch (IOException | InterruptedException e)
{ {
return false; return false;
} }
return exec.exitValue() == 0;
}
catch (IOException | InterruptedException e)
{
return false;
} }
return false;
} }
private static String toUrgency(TrayIcon.MessageType type) private static String toUrgency(TrayIcon.MessageType type)