From 6ffe5da92959ab26ed3c9b36131228daaefb78c3 Mon Sep 17 00:00:00 2001 From: Tomas Slusny Date: Wed, 28 Feb 2018 10:48:32 +0100 Subject: [PATCH 1/3] Move the notification options to Notifier - Move enabling of tray notifications to RuneLiteConfig - Move request when focused notification option to RuneLiteConfig and use it in notifier - Move request window focus to RuneLiteConfig and use it in notifier - Change Notifier to use Guice for creation Signed-off-by: Tomas Slusny --- .../java/net/runelite/client/Notifier.java | 60 ++++++++++++++----- .../java/net/runelite/client/RuneLite.java | 10 ---- .../net/runelite/client/RuneLiteModule.java | 6 -- .../client/config/RuneLiteConfig.java | 32 +++++++++- .../client/plugins/PluginManagerTest.java | 5 -- 5 files changed, 76 insertions(+), 37 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 5a5b0c5ea4..66ada917a4 100644 --- a/runelite-client/src/main/java/net/runelite/client/Notifier.java +++ b/runelite-client/src/main/java/net/runelite/client/Notifier.java @@ -26,39 +26,40 @@ package net.runelite.client; import com.google.common.escape.Escaper; import com.google.common.escape.Escapers; +import com.google.inject.Inject; import java.awt.Toolkit; import java.awt.TrayIcon; import java.io.IOException; import java.util.ArrayList; import java.util.List; +import javax.inject.Provider; +import javax.inject.Singleton; import lombok.extern.slf4j.Slf4j; import net.runelite.client.config.RuneLiteConfig; import net.runelite.client.util.OSType; +import net.runelite.client.ui.ClientUI; +@Singleton @Slf4j public class Notifier { - // Default timeout of notification in milliseconds private static final int DEFAULT_TIMEOUT = 10000; private static final String DOUBLE_QUOTE = "\""; - private static final Escaper SHELL_ESCAPE; - - static - { - final Escapers.Builder builder = Escapers.builder(); - builder.addEscape('"', "'"); - SHELL_ESCAPE = builder.build(); - } + private static final Escaper SHELL_ESCAPE = Escapers.builder() + .addEscape('"', "'") + .build(); private final String appName; - private final TrayIcon trayIcon; private final RuneLiteConfig runeLiteConfig; + private final Provider clientUI; - Notifier(final String appName, final TrayIcon trayIcon, final RuneLiteConfig runeliteConfig) + @Inject + private Notifier(final Provider clientUI, final RuneLiteConfig runeliteConfig, final RuneLiteProperties + runeLiteProperties) { - this.appName = appName; - this.trayIcon = trayIcon; + this.appName = runeLiteProperties.getTitle(); + this.clientUI = clientUI; this.runeLiteConfig = runeliteConfig; } @@ -69,6 +70,28 @@ public class Notifier public void notify(String message, TrayIcon.MessageType type) { + if (!runeLiteConfig.enableTrayNotifications()) + { + return; + } + + final ClientUI clientUI = this.clientUI.get(); + + if (clientUI == null) + { + return; + } + + if (!runeLiteConfig.sendNotificationsWhenFocused() && clientUI.isFocused()) + { + return; + } + + if (runeLiteConfig.requestFocusOnNotification()) + { + clientUI.requestFocus(); + } + sendNotification(appName, message, type, null); if (runeLiteConfig.enableNotificationSound()) @@ -105,9 +128,16 @@ public class Notifier final String message, final TrayIcon.MessageType type) { - if (trayIcon != null) + final ClientUI clientUI = this.clientUI.get(); + + if (clientUI == null) { - trayIcon.displayMessage(title, message, type); + return; + } + + if (clientUI.getTrayIcon() != null) + { + clientUI.getTrayIcon().displayMessage(title, message, type); } } diff --git a/runelite-client/src/main/java/net/runelite/client/RuneLite.java b/runelite-client/src/main/java/net/runelite/client/RuneLite.java index 3320e7507b..a3e6af2849 100644 --- a/runelite-client/src/main/java/net/runelite/client/RuneLite.java +++ b/runelite-client/src/main/java/net/runelite/client/RuneLite.java @@ -98,7 +98,6 @@ public class RuneLite Client client; ClientUI gui; - Notifier notifier; public static void main(String[] args) throws Exception { @@ -161,9 +160,6 @@ public class RuneLite eventBus.register(gui); eventBus.register(pluginManager); - // Setup the notifier - notifier = new Notifier(properties.getTitle(), gui.getTrayIcon(), runeliteConfig); - // Tell the plugin manager if client is outdated or not pluginManager.setOutdated(isOutdated); @@ -219,12 +215,6 @@ public class RuneLite this.client = client; } - @VisibleForTesting - public void setNotifier(Notifier notifier) - { - this.notifier = notifier; - } - public static Injector getInjector() { return injector; diff --git a/runelite-client/src/main/java/net/runelite/client/RuneLiteModule.java b/runelite-client/src/main/java/net/runelite/client/RuneLiteModule.java index a901557d8a..24c49fd308 100644 --- a/runelite-client/src/main/java/net/runelite/client/RuneLiteModule.java +++ b/runelite-client/src/main/java/net/runelite/client/RuneLiteModule.java @@ -73,12 +73,6 @@ public class RuneLiteModule extends AbstractModule return runelite.gui; } - @Provides - Notifier provideNotifier(RuneLite runeLite) - { - return runeLite.notifier; - } - @Provides @Singleton RuneLiteConfig provideConfig(ConfigManager configManager) diff --git a/runelite-client/src/main/java/net/runelite/client/config/RuneLiteConfig.java b/runelite-client/src/main/java/net/runelite/client/config/RuneLiteConfig.java index 9604c7d9bb..c579bb264e 100644 --- a/runelite-client/src/main/java/net/runelite/client/config/RuneLiteConfig.java +++ b/runelite-client/src/main/java/net/runelite/client/config/RuneLiteConfig.java @@ -76,6 +76,16 @@ public interface RuneLiteConfig extends Config return false; } + @ConfigItem( + keyName = "notificationTray", + name = "Enable tray notifications", + description = "Enables tray notifications" + ) + default boolean enableTrayNotifications() + { + return true; + } + @ConfigItem( keyName = "notificationSound", name = "Enable sound on notifications", @@ -85,4 +95,24 @@ public interface RuneLiteConfig extends Config { return true; } -} + + @ConfigItem( + keyName = "notificationFocused", + name = "Send notifications when focused", + description = "Toggles idle notifications for when the client is focused" + ) + default boolean sendNotificationsWhenFocused() + { + return false; + } + + @ConfigItem( + keyName = "notificationRequestFocus", + name = "Request focus on notification", + description = "Toggles window focus request" + ) + default boolean requestFocusOnNotification() + { + return true; + } +} \ No newline at end of file diff --git a/runelite-client/src/test/java/net/runelite/client/plugins/PluginManagerTest.java b/runelite-client/src/test/java/net/runelite/client/plugins/PluginManagerTest.java index 67e0d58cde..da87c58bc3 100644 --- a/runelite-client/src/test/java/net/runelite/client/plugins/PluginManagerTest.java +++ b/runelite-client/src/test/java/net/runelite/client/plugins/PluginManagerTest.java @@ -43,7 +43,6 @@ import java.util.Objects; import java.util.Set; import joptsimple.OptionSet; import net.runelite.api.Client; -import net.runelite.client.Notifier; import net.runelite.client.RuneLite; import net.runelite.client.RuneLiteModule; import net.runelite.client.ui.ClientUI; @@ -74,9 +73,6 @@ public class PluginManagerTest @Mock Client client; - @Mock - Notifier notifier; - @Before public void before() throws IOException { @@ -88,7 +84,6 @@ public class PluginManagerTest runelite = injector.getInstance(RuneLite.class); runelite.setGui(clientUi); - runelite.setNotifier(notifier); // Find plugins we expect to have pluginClasses = new HashSet<>(); From 5f0f0c6836d64a0207e06734b280261edda8b3c2 Mon Sep 17 00:00:00 2001 From: Tomas Slusny Date: Wed, 28 Feb 2018 10:49:57 +0100 Subject: [PATCH 2/3] Remove duplicate options from IdleNotifier Remove options that are now contained in RuneLiteConfig from idle notifier. Signed-off-by: Tomas Slusny --- .../idlenotifier/IdleNotifierConfig.java | 33 -------------- .../idlenotifier/IdleNotifierPlugin.java | 44 +++++-------------- 2 files changed, 12 insertions(+), 65 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/idlenotifier/IdleNotifierConfig.java b/runelite-client/src/main/java/net/runelite/client/plugins/idlenotifier/IdleNotifierConfig.java index f6cdda5d19..8b0c47c655 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/idlenotifier/IdleNotifierConfig.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/idlenotifier/IdleNotifierConfig.java @@ -35,39 +35,6 @@ import net.runelite.client.config.ConfigItem; ) public interface IdleNotifierConfig extends Config { - @ConfigItem( - keyName = "tray", - name = "Send Tray Notification", - description = "Toggles tray notifications", - position = 2 - ) - default boolean sendTrayNotification() - { - return true; - } - - @ConfigItem( - keyName = "focused", - name = "Notify When Focused", - description = "Toggles idle notifications for when the client is focused", - position = 3 - ) - default boolean alertWhenFocused() - { - return false; - } - - @ConfigItem( - keyName = "request", - name = "Request Window Focus", - description = "Toggles window focus request", - position = 4 - ) - default boolean requestFocus() - { - return true; - } - @ConfigItem( keyName = "timeout", name = "Idle Timeout (ms)", diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/idlenotifier/IdleNotifierPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/idlenotifier/IdleNotifierPlugin.java index e5101721aa..cc8475ef67 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/idlenotifier/IdleNotifierPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/idlenotifier/IdleNotifierPlugin.java @@ -25,6 +25,12 @@ */ package net.runelite.client.plugins.idlenotifier; +import com.google.common.eventbus.Subscribe; +import com.google.inject.Provides; +import java.time.Duration; +import java.time.Instant; +import javax.inject.Inject; +import net.runelite.api.Actor; import static net.runelite.api.AnimationID.COOKING_FIRE; import static net.runelite.api.AnimationID.COOKING_RANGE; import static net.runelite.api.AnimationID.CRAFTING_GLASSBLOWING; @@ -90,12 +96,6 @@ import static net.runelite.api.AnimationID.WOODCUTTING_IRON; import static net.runelite.api.AnimationID.WOODCUTTING_MITHRIL; import static net.runelite.api.AnimationID.WOODCUTTING_RUNE; import static net.runelite.api.AnimationID.WOODCUTTING_STEEL; -import com.google.common.eventbus.Subscribe; -import com.google.inject.Provides; -import java.time.Duration; -import java.time.Instant; -import javax.inject.Inject; -import net.runelite.api.Actor; import net.runelite.api.Client; import net.runelite.api.GameState; import net.runelite.api.Player; @@ -107,7 +107,6 @@ import net.runelite.client.Notifier; import net.runelite.client.config.ConfigManager; import net.runelite.client.plugins.Plugin; import net.runelite.client.plugins.PluginDescriptor; -import net.runelite.client.ui.ClientUI; @PluginDescriptor( name = "Idle notifier" @@ -120,9 +119,6 @@ public class IdleNotifierPlugin extends Plugin @Inject private Notifier notifier; - @Inject - private ClientUI gui; - @Inject private Client client; @@ -283,32 +279,32 @@ public class IdleNotifierPlugin extends Plugin if (checkIdleLogout()) { - sendNotification("[" + local.getName() + "] is about to log out from idling too long!"); + notifier.notify("[" + local.getName() + "] is about to log out from idling too long!"); } if (check6hrLogout()) { - sendNotification("[" + local.getName() + "] is about to log out from being online for 6 hours!"); + notifier.notify("[" + local.getName() + "] is about to log out from being online for 6 hours!"); } if (checkAnimationIdle(waitDuration, local)) { - sendNotification("[" + local.getName() + "] is now idle!"); + notifier.notify("[" + local.getName() + "] is now idle!"); } if (checkOutOfCombat(waitDuration, local)) { - sendNotification("[" + local.getName() + "] is now out of combat!"); + notifier.notify("[" + local.getName() + "] is now out of combat!"); } if (checkLowHitpoints(waitDuration)) { - sendNotification("[" + local.getName() + "] has low hitpoints!"); + notifier.notify("[" + local.getName() + "] has low hitpoints!"); } if (checkLowPrayer(waitDuration)) { - sendNotification("[" + local.getName() + "] has low prayer!"); + notifier.notify("[" + local.getName() + "] has low prayer!"); } } @@ -452,22 +448,6 @@ public class IdleNotifierPlugin extends Plugin return false; } - private void sendNotification(String message) - { - if (!config.alertWhenFocused() && gui.isFocused()) - { - return; - } - if (config.requestFocus()) - { - gui.requestFocus(); - } - if (config.sendTrayNotification()) - { - notifier.notify(message); - } - } - private void resetTimers() { // Reset animation idle timer From a386dab3f2ddab272ae916387df8781e362c8bb6 Mon Sep 17 00:00:00 2001 From: Tomas Slusny Date: Wed, 28 Feb 2018 10:55:35 +0100 Subject: [PATCH 3/3] Remove notification settings from NMZ Remove notification settings from NMZ that are now contained in RuneLiteConfig. Signed-off-by: Tomas Slusny --- .../nightmarezone/NightmareZoneConfig.java | 40 +++++-------------- .../nightmarezone/NightmareZonePlugin.java | 20 +--------- 2 files changed, 11 insertions(+), 49 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/nightmarezone/NightmareZoneConfig.java b/runelite-client/src/main/java/net/runelite/client/plugins/nightmarezone/NightmareZoneConfig.java index cdc1143e88..11107fb402 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/nightmarezone/NightmareZoneConfig.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/nightmarezone/NightmareZoneConfig.java @@ -37,23 +37,12 @@ import net.runelite.client.config.ConfigItem; public interface NightmareZoneConfig extends Config { @ConfigItem( - keyName = "tray", - name = "Send Tray Notification", - description = "Toggles tray notifications", + keyName = "moveoverlay", + name = "Override NMZ overlay", + description = "Overrides the overlay so it doesn't conflict with other RuneLite plugins", position = 1 ) - default boolean sendTrayNotification() - { - return true; - } - - @ConfigItem( - keyName = "request", - name = "Request Window Focus", - description = "Toggles window focus request", - position = 2 - ) - default boolean requestFocus() + default boolean moveOverlay() { return true; } @@ -62,29 +51,18 @@ public interface NightmareZoneConfig extends Config keyName = "overloadnotification", name = "Overload notification", description = "Toggles notifications when your overload runs out", - position = 3 + position = 2 ) default boolean overloadNotification() { return true; } - @ConfigItem( - keyName = "moveoverlay", - name = "Override NMZ overlay", - description = "Overrides the overlay so it doesn't conflict with other RuneLite plugins", - position = 4 - ) - default boolean moveOverlay() - { - return true; - } - @ConfigItem( keyName = "absorptionnotification", name = "Absorption notification", description = "Toggles notifications when your absorption points gets below your threshold", - position = 5 + position = 3 ) default boolean absorptionNotification() { @@ -95,7 +73,7 @@ public interface NightmareZoneConfig extends Config keyName = "absorptionthreshold", name = "Absorption Threshold", description = "The amount of absorption points to send a notification at", - position = 6 + position = 4 ) default int absorptionThreshold() { @@ -106,7 +84,7 @@ public interface NightmareZoneConfig extends Config keyName = "absorptioncoloroverthreshold", name = "Color above threshold", description = "Configures the color for the absorption widget when above the threshold", - position = 7 + position = 5 ) default Color absorptionColorAboveThreshold() { @@ -117,7 +95,7 @@ public interface NightmareZoneConfig extends Config keyName = "absorptioncolorbelowthreshold", name = "Color below threshold", description = "Configures the color for the absorption widget when below the threshold", - position = 8 + position = 6 ) default Color absorptionColorBelowThreshold() { diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/nightmarezone/NightmareZonePlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/nightmarezone/NightmareZonePlugin.java index 3bb680868c..15a5c3cff9 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/nightmarezone/NightmareZonePlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/nightmarezone/NightmareZonePlugin.java @@ -38,7 +38,6 @@ import net.runelite.client.Notifier; import net.runelite.client.config.ConfigManager; import net.runelite.client.plugins.Plugin; import net.runelite.client.plugins.PluginDescriptor; -import net.runelite.client.ui.ClientUI; import net.runelite.client.ui.overlay.Overlay; @PluginDescriptor( @@ -51,9 +50,6 @@ public class NightmareZonePlugin extends Plugin @Inject private Notifier notifier; - @Inject - private ClientUI gui; - @Inject private Client client; @@ -117,7 +113,7 @@ public class NightmareZonePlugin extends Plugin String msg = event.getMessage().replaceAll("<[^>]*>", " "); //remove color and linebreaks if (msg.contains("The effects of overload have worn off, and you feel normal again.")) { - sendNotification("Your overload has worn off"); + notifier.notify("Your overload has worn off"); } } @@ -129,7 +125,7 @@ public class NightmareZonePlugin extends Plugin { if (absorptionPoints < config.absorptionThreshold()) { - sendNotification("Absorption points below: " + config.absorptionThreshold()); + notifier.notify("Absorption points below: " + config.absorptionThreshold()); absorptionNotificationSend = true; } } @@ -146,16 +142,4 @@ public class NightmareZonePlugin extends Plugin { return Arrays.equals(client.getMapRegions(), NMZ_MAP_REGION); } - - private void sendNotification(String message) - { - if (!gui.isFocused() && config.requestFocus()) - { - gui.requestFocus(); - } - if (config.sendTrayNotification()) - { - notifier.notify(message); - } - } }