From 62740a0d5abf9746210fa9a722a47beeab2f5845 Mon Sep 17 00:00:00 2001 From: nathan Date: Tue, 5 Apr 2016 14:19:13 +0200 Subject: [PATCH] Added `TIMEOUT` property to adjust how long to wait for the event dispatch queue to complete. --- README.md | 6 ++- src/dorkbox/systemTray/SystemTray.java | 70 ++++++++++++++++++++------ 2 files changed, 60 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 1478e2c..a21047c 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,10 @@ GnomeShellExtension.SHELL_RESTART_COMMAND (type String, default value 'gnome-s - Command to restart the gnome-shell. It is recommended to start it in the background (hence '&') +SystemTray.TIMEOUT (type int, default value '2') + - How long to wait when updating menu entries before the request times-out + + SystemTray.TRAY_SIZE (type int, default value '22') - Size of the tray, so that the icon can properly scale based on OS. (if it's not exact) @@ -147,7 +151,7 @@ This project is **kept in sync** with the utilities library, so "jar hell" is no com.dorkbox SystemTray - 2.14 + 2.15 ``` diff --git a/src/dorkbox/systemTray/SystemTray.java b/src/dorkbox/systemTray/SystemTray.java index 99ac5d3..c823971 100644 --- a/src/dorkbox/systemTray/SystemTray.java +++ b/src/dorkbox/systemTray/SystemTray.java @@ -54,6 +54,10 @@ public abstract class SystemTray { protected static final Logger logger = LoggerFactory.getLogger(SystemTray.class); + @Property + /** How long to wait when updating menu entries before the request times-out */ + public static final int TIMEOUT = 2; + @Property /** Size of the tray, so that the icon can properly scale based on OS. (if it's not exact) */ public static int TRAY_SIZE = 22; @@ -255,10 +259,6 @@ class SystemTray { //noinspection unused final AppIndicator instance = AppIndicator.INSTANCE; trayType = AppIndicatorTray.class; - - if (AppIndicator.IS_VERSION_3) { - - } } catch (Throwable e) { logger.error("AppIndicator support detected, but unable to load the library. Falling back to GTK"); e.printStackTrace(); @@ -267,7 +267,10 @@ class SystemTray { } } finally { if (bin != null) { - bin.close(); + try { + bin.close(); + } catch (Exception ignored) { + } bin = null; } } @@ -411,7 +414,7 @@ class SystemTray { */ public static String getVersion() { - return "2.14"; + return "2.15"; } /** @@ -531,6 +534,7 @@ class SystemTray { @Deprecated public void setIcon(InputStream imageStream) { + @SuppressWarnings("deprecation") final String fullPath = ImageUtil.iconPathNoCache(imageStream); setIcon_(fullPath); } @@ -625,7 +629,11 @@ class SystemTray { }); try { - final boolean await = countDownLatch.await(2, TimeUnit.SECONDS); + if (!countDownLatch.await(TIMEOUT, TimeUnit.SECONDS)) { + throw new RuntimeException("Event dispatch queue took longer than " + TIMEOUT + " seconds to complete. Please adjust " + + "`SystemTray.TIMEOUT` to a value which better suites your environment."); + + } } catch (InterruptedException e) { e.printStackTrace(); } @@ -666,7 +674,11 @@ class SystemTray { }); try { - final boolean await = countDownLatch.await(2, TimeUnit.SECONDS); + if (!countDownLatch.await(TIMEOUT, TimeUnit.SECONDS)) { + throw new RuntimeException("Event dispatch queue took longer than " + TIMEOUT + " seconds to complete. Please adjust " + + "`SystemTray.TIMEOUT` to a value which better suites your environment."); + + } } catch (InterruptedException e) { e.printStackTrace(); } @@ -708,7 +720,11 @@ class SystemTray { }); try { - final boolean await = countDownLatch.await(2, TimeUnit.SECONDS); + if (!countDownLatch.await(TIMEOUT, TimeUnit.SECONDS)) { + throw new RuntimeException("Event dispatch queue took longer than " + TIMEOUT + " seconds to complete. Please adjust " + + "`SystemTray.TIMEOUT` to a value which better suites your environment."); + + } } catch (InterruptedException e) { e.printStackTrace(); } @@ -749,7 +765,11 @@ class SystemTray { }); try { - final boolean await = countDownLatch.await(2, TimeUnit.SECONDS); + if (!countDownLatch.await(TIMEOUT, TimeUnit.SECONDS)) { + throw new RuntimeException("Event dispatch queue took longer than " + TIMEOUT + " seconds to complete. Please adjust " + + "`SystemTray.TIMEOUT` to a value which better suites your environment."); + + } } catch (InterruptedException e) { e.printStackTrace(); } @@ -794,7 +814,11 @@ class SystemTray { }); try { - final boolean await = countDownLatch.await(2, TimeUnit.SECONDS); + if (!countDownLatch.await(TIMEOUT, TimeUnit.SECONDS)) { + throw new RuntimeException("Event dispatch queue took longer than " + TIMEOUT + " seconds to complete. Please adjust " + + "`SystemTray.TIMEOUT` to a value which better suites your environment."); + + } } catch (InterruptedException e) { e.printStackTrace(); } @@ -835,7 +859,11 @@ class SystemTray { }); try { - final boolean await = countDownLatch.await(2, TimeUnit.SECONDS); + if (!countDownLatch.await(TIMEOUT, TimeUnit.SECONDS)) { + throw new RuntimeException("Event dispatch queue took longer than " + TIMEOUT + " seconds to complete. Please adjust " + + "`SystemTray.TIMEOUT` to a value which better suites your environment."); + + } } catch (InterruptedException e) { e.printStackTrace(); } @@ -879,7 +907,11 @@ class SystemTray { }); try { - final boolean await = countDownLatch.await(2, TimeUnit.SECONDS); + if (!countDownLatch.await(TIMEOUT, TimeUnit.SECONDS)) { + throw new RuntimeException("Event dispatch queue took longer than " + TIMEOUT + " seconds to complete. Please adjust " + + "`SystemTray.TIMEOUT` to a value which better suites your environment."); + + } } catch (InterruptedException e) { e.printStackTrace(); } @@ -931,7 +963,11 @@ class SystemTray { }); try { - final boolean await = countDownLatch.await(2, TimeUnit.SECONDS); + if (!countDownLatch.await(TIMEOUT, TimeUnit.SECONDS)) { + throw new RuntimeException("Event dispatch queue took longer than " + TIMEOUT + " seconds to complete. Please adjust " + + "`SystemTray.TIMEOUT` to a value which better suites your environment."); + + } } catch (InterruptedException e) { e.printStackTrace(); } @@ -978,7 +1014,11 @@ class SystemTray { }); try { - final boolean await = countDownLatch.await(2, TimeUnit.SECONDS); + if (!countDownLatch.await(TIMEOUT, TimeUnit.SECONDS)) { + throw new RuntimeException("Event dispatch queue took longer than " + TIMEOUT + " seconds to complete. Please adjust " + + "`SystemTray.TIMEOUT` to a value which better suites your environment."); + + } } catch (InterruptedException e) { e.printStackTrace(); }