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>
|
<artifactId>gson</artifactId>
|
||||||
<version>2.4</version>
|
<version>2.4</version>
|
||||||
</dependency>
|
</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>
|
<dependency>
|
||||||
<groupId>org.pushingpixels</groupId>
|
<groupId>org.pushingpixels</groupId>
|
||||||
<artifactId>substance</artifactId>
|
<artifactId>substance</artifactId>
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ import java.io.FileInputStream;
|
|||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
|
import java.net.URL;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
@@ -51,6 +52,12 @@ import javax.swing.JPopupMenu;
|
|||||||
import javax.swing.SwingUtilities;
|
import javax.swing.SwingUtilities;
|
||||||
import javax.swing.UIManager;
|
import javax.swing.UIManager;
|
||||||
import javax.swing.UnsupportedLookAndFeelException;
|
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.OptionParser;
|
||||||
import joptsimple.OptionSet;
|
import joptsimple.OptionSet;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
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 PROFILES_DIR = new File(RUNELITE_DIR, "profiles");
|
||||||
public static final File SESSION_FILE = new File(RUNELITE_DIR, "session");
|
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 File PLUGIN_DIR = new File(RUNELITE_DIR, "plugins");
|
||||||
|
public static final String APP_NAME = "RuneLite";
|
||||||
|
|
||||||
public static Image ICON;
|
public static Image ICON;
|
||||||
|
public static Icon NOTIFY_ICON;
|
||||||
|
|
||||||
private static Injector injector;
|
private static Injector injector;
|
||||||
|
|
||||||
@@ -106,11 +115,16 @@ public class RuneLite
|
|||||||
|
|
||||||
private AccountSession accountSession;
|
private AccountSession accountSession;
|
||||||
|
|
||||||
|
private Notifier notifier;
|
||||||
|
|
||||||
|
|
||||||
static
|
static
|
||||||
{
|
{
|
||||||
try
|
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)
|
catch (IOException ex)
|
||||||
{
|
{
|
||||||
@@ -162,6 +176,16 @@ public class RuneLite
|
|||||||
|
|
||||||
eventBus.register(menuManager);
|
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.
|
// Load the plugins, but does not start them yet.
|
||||||
// This will initialize configuration
|
// This will initialize configuration
|
||||||
pluginManager.loadCorePlugins();
|
pluginManager.loadCorePlugins();
|
||||||
@@ -184,11 +208,11 @@ public class RuneLite
|
|||||||
{
|
{
|
||||||
if (!Strings.isNullOrEmpty(extra))
|
if (!Strings.isNullOrEmpty(extra))
|
||||||
{
|
{
|
||||||
gui.setTitle("RuneLite " + properties.getVersion() + " " + extra);
|
gui.setTitle(APP_NAME + " " + properties.getVersion() + " " + extra);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
gui.setTitle("RuneLite " + properties.getVersion());
|
gui.setTitle(APP_NAME + " " + properties.getVersion());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -201,7 +225,7 @@ public class RuneLite
|
|||||||
|
|
||||||
SystemTray systemTray = SystemTray.getSystemTray();
|
SystemTray systemTray = SystemTray.getSystemTray();
|
||||||
|
|
||||||
trayIcon = new TrayIcon(ICON, "RuneLite");
|
trayIcon = new TrayIcon(ICON, APP_NAME);
|
||||||
trayIcon.setImageAutoSize(true);
|
trayIcon.setImageAutoSize(true);
|
||||||
|
|
||||||
try
|
try
|
||||||
@@ -390,7 +414,18 @@ public class RuneLite
|
|||||||
|
|
||||||
public void notify(String message, TrayIcon.MessageType type)
|
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();
|
Toolkit.getDefaultToolkit().beep();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user