From c0913f2f7cd8899dd09630ab8e905e559f05061a Mon Sep 17 00:00:00 2001 From: Trevor Date: Sat, 8 Feb 2020 16:38:11 -0500 Subject: [PATCH] client: add notification fired event --- .../java/net/runelite/client/Notifier.java | 9 ++++- .../client/events/NotificationFired.java | 35 +++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 runelite-client/src/main/java/net/runelite/client/events/NotificationFired.java 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 83cf8c0a3b..5a61dd592a 100644 --- a/runelite-client/src/main/java/net/runelite/client/Notifier.java +++ b/runelite-client/src/main/java/net/runelite/client/Notifier.java @@ -64,6 +64,8 @@ import net.runelite.client.chat.ChatMessageManager; import net.runelite.client.chat.QueuedMessage; import net.runelite.client.config.FlashNotification; import net.runelite.client.config.RuneLiteConfig; +import net.runelite.client.eventbus.EventBus; +import net.runelite.client.events.NotificationFired; import net.runelite.client.ui.ClientUI; import net.runelite.client.util.OSType; @@ -107,6 +109,7 @@ public class Notifier private final ClientUI clientUI; private final ScheduledExecutorService executorService; private final ChatMessageManager chatMessageManager; + private final EventBus eventBus; private final Path notifyIconPath; private final boolean terminalNotifierAvailable; private Instant flashStart; @@ -118,13 +121,15 @@ public class Notifier final Client client, final RuneLiteConfig runeliteConfig, final ScheduledExecutorService executorService, - final ChatMessageManager chatMessageManager) + final ChatMessageManager chatMessageManager, + final EventBus eventBus) { this.client = client; this.clientUI = clientUI; this.runeLiteConfig = runeliteConfig; this.executorService = executorService; this.chatMessageManager = chatMessageManager; + this.eventBus = eventBus; this.notifyIconPath = RuneLite.RUNELITE_DIR.toPath().resolve("icon.png"); // First check if we are running in launcher @@ -142,6 +147,8 @@ public class Notifier public void notify(String message, TrayIcon.MessageType type) { + eventBus.post(new NotificationFired(message, type)); + if (!runeLiteConfig.sendNotificationsWhenFocused() && clientUI.isFocused()) { return; diff --git a/runelite-client/src/main/java/net/runelite/client/events/NotificationFired.java b/runelite-client/src/main/java/net/runelite/client/events/NotificationFired.java new file mode 100644 index 0000000000..ecf1ffaf2d --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/events/NotificationFired.java @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2020, Trevor + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.client.events; + +import java.awt.TrayIcon; +import lombok.Value; + +@Value +public class NotificationFired +{ + final String message; + final TrayIcon.MessageType type; +}