Add support for native notifications
Replace current TrayIcon notifications with system-native notifications. Supports most of the operating systems (the important ones are Windows, Linux and OS X). Resolves: #230 Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
This commit is contained in:
@@ -75,6 +75,17 @@
|
||||
<artifactId>gson</artifactId>
|
||||
<version>2.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>fr.jcgay.send-notification</groupId>
|
||||
<artifactId>send-notification</artifactId>
|
||||
<version>0.14.0</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>com.squareup.okhttp</groupId>
|
||||
<artifactId>okhttp</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.pushingpixels</groupId>
|
||||
<artifactId>substance</artifactId>
|
||||
@@ -92,7 +103,7 @@
|
||||
<version>1.16.18</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>net.runelite</groupId>
|
||||
<artifactId>api</artifactId>
|
||||
@@ -115,7 +126,7 @@
|
||||
<artifactId>http-api</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
|
||||
@@ -43,6 +43,7 @@ import java.io.FileInputStream;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.inject.Singleton;
|
||||
@@ -51,6 +52,12 @@ import javax.swing.JPopupMenu;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.UnsupportedLookAndFeelException;
|
||||
|
||||
import fr.jcgay.notification.Application;
|
||||
import fr.jcgay.notification.Icon;
|
||||
import fr.jcgay.notification.Notification;
|
||||
import fr.jcgay.notification.Notifier;
|
||||
import fr.jcgay.notification.SendNotification;
|
||||
import joptsimple.OptionParser;
|
||||
import joptsimple.OptionSet;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -74,8 +81,10 @@ public class RuneLite
|
||||
public static final File PROFILES_DIR = new File(RUNELITE_DIR, "profiles");
|
||||
public static final File SESSION_FILE = new File(RUNELITE_DIR, "session");
|
||||
public static final File PLUGIN_DIR = new File(RUNELITE_DIR, "plugins");
|
||||
public static final String APP_NAME = "RuneLite";
|
||||
|
||||
public static Image ICON;
|
||||
public static Icon NOTIFY_ICON;
|
||||
|
||||
private static Injector injector;
|
||||
|
||||
@@ -106,11 +115,16 @@ public class RuneLite
|
||||
|
||||
private AccountSession accountSession;
|
||||
|
||||
private Notifier notifier;
|
||||
|
||||
|
||||
static
|
||||
{
|
||||
try
|
||||
{
|
||||
ICON = ImageIO.read(ClientUI.class.getResourceAsStream("/runelite.png"));
|
||||
final URL icon = ClientUI.class.getResource("/runelite.png");
|
||||
ICON = ImageIO.read(icon.openStream());
|
||||
NOTIFY_ICON = Icon.create(icon, APP_NAME);
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
@@ -162,6 +176,16 @@ public class RuneLite
|
||||
|
||||
eventBus.register(menuManager);
|
||||
|
||||
// Setup the notifier
|
||||
notifier = new SendNotification()
|
||||
.setApplication(Application
|
||||
.builder()
|
||||
.icon(NOTIFY_ICON)
|
||||
.name(APP_NAME)
|
||||
.id(APP_NAME)
|
||||
.build())
|
||||
.initNotifier();
|
||||
|
||||
// Load the plugins, but does not start them yet.
|
||||
// This will initialize configuration
|
||||
pluginManager.loadCorePlugins();
|
||||
@@ -184,11 +208,11 @@ public class RuneLite
|
||||
{
|
||||
if (!Strings.isNullOrEmpty(extra))
|
||||
{
|
||||
gui.setTitle("RuneLite " + properties.getVersion() + " " + extra);
|
||||
gui.setTitle(APP_NAME + " " + properties.getVersion() + " " + extra);
|
||||
}
|
||||
else
|
||||
{
|
||||
gui.setTitle("RuneLite " + properties.getVersion());
|
||||
gui.setTitle(APP_NAME + " " + properties.getVersion());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -201,7 +225,7 @@ public class RuneLite
|
||||
|
||||
SystemTray systemTray = SystemTray.getSystemTray();
|
||||
|
||||
trayIcon = new TrayIcon(ICON, "RuneLite");
|
||||
trayIcon = new TrayIcon(ICON, APP_NAME);
|
||||
trayIcon.setImageAutoSize(true);
|
||||
|
||||
try
|
||||
@@ -390,7 +414,18 @@ public class RuneLite
|
||||
|
||||
public void notify(String message, TrayIcon.MessageType type)
|
||||
{
|
||||
getTrayIcon().displayMessage("RuneLite", message, type);
|
||||
final Notification.Level notificationLevel = Notification.Level
|
||||
.valueOf((TrayIcon.MessageType.NONE.equals(type)
|
||||
? TrayIcon.MessageType.INFO
|
||||
: type).toString());
|
||||
|
||||
notifier.send(Notification.builder()
|
||||
.title(APP_NAME)
|
||||
.message(message)
|
||||
.icon(NOTIFY_ICON)
|
||||
.level(notificationLevel)
|
||||
.build());
|
||||
|
||||
Toolkit.getDefaultToolkit().beep();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user