From a658d94db096d53111f1e24d14aeeca3ae437963 Mon Sep 17 00:00:00 2001 From: Adam Date: Sat, 28 Nov 2020 14:40:35 -0500 Subject: [PATCH] notifier: move osx terminal-notifier test to executor Additionally set a timeout on the process --- .../java/net/runelite/client/Notifier.java | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/Notifier.java b/runelite-client/src/main/java/net/runelite/client/Notifier.java index 77231f8a9e..872866c415 100644 --- a/runelite-client/src/main/java/net/runelite/client/Notifier.java +++ b/runelite-client/src/main/java/net/runelite/client/Notifier.java @@ -114,7 +114,7 @@ public class Notifier private final ChatMessageManager chatMessageManager; private final EventBus eventBus; private final Path notifyIconPath; - private final boolean terminalNotifierAvailable; + private boolean terminalNotifierAvailable; private Instant flashStart; private long mouseLastPressedMillis; private long lastClipMTime = CLIP_MTIME_UNLOADED; @@ -138,9 +138,10 @@ public class Notifier this.notifyIconPath = RuneLite.RUNELITE_DIR.toPath().resolve("icon.png"); // First check if we are running in launcher - this.terminalNotifierAvailable = - !Strings.isNullOrEmpty(RuneLiteProperties.getLauncherVersion()) - && isTerminalNotifierAvailable(); + if (!Strings.isNullOrEmpty(RuneLiteProperties.getLauncherVersion()) && OSType.getOSType() == OSType.MacOS) + { + executorService.execute(() -> terminalNotifierAvailable = isTerminalNotifierAvailable()); + } storeIcon(); } @@ -389,21 +390,19 @@ public class Notifier private boolean isTerminalNotifierAvailable() { - if (OSType.getOSType() == OSType.MacOS) + try { - try - { - final Process exec = Runtime.getRuntime().exec(new String[]{"terminal-notifier", "-help"}); - exec.waitFor(); - return exec.exitValue() == 0; - } - catch (IOException | InterruptedException e) + final Process exec = Runtime.getRuntime().exec(new String[]{"terminal-notifier", "-help"}); + if (!exec.waitFor(2, TimeUnit.SECONDS)) { return false; } + return exec.exitValue() == 0; + } + catch (IOException | InterruptedException e) + { + return false; } - - return false; } private static String toUrgency(TrayIcon.MessageType type)