forked from RepoMirrors/baritone
Fix additional TrayIcon creation and support Mac notifs
This commit is contained in:
parent
2ea66ea8fc
commit
c578d5c1a3
|
@ -17,6 +17,8 @@
|
||||||
|
|
||||||
package baritone.utils;
|
package baritone.utils;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.SystemUtils;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
@ -28,30 +30,32 @@ import java.io.IOException;
|
||||||
*/
|
*/
|
||||||
public class NotificationHelper {
|
public class NotificationHelper {
|
||||||
|
|
||||||
|
private static TrayIcon trayIcon;
|
||||||
|
|
||||||
public static void notify(String text, boolean error) {
|
public static void notify(String text, boolean error) {
|
||||||
if (System.getProperty("os.name").contains("Linux")) {
|
if (SystemUtils.IS_OS_WINDOWS) {
|
||||||
|
windows(text, error);
|
||||||
|
} else if (SystemUtils.IS_OS_MAC_OSX) {
|
||||||
|
mac(text);
|
||||||
|
} else if (SystemUtils.IS_OS_LINUX) {
|
||||||
linux(text);
|
linux(text);
|
||||||
} else {
|
|
||||||
notification(text, error);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void notification(String text, boolean error) {
|
private static void windows(String text, boolean error) {
|
||||||
if (SystemTray.isSupported()) {
|
if (SystemTray.isSupported()) {
|
||||||
try {
|
try {
|
||||||
SystemTray tray = SystemTray.getSystemTray();
|
if (trayIcon == null) {
|
||||||
Image image = Toolkit.getDefaultToolkit().createImage("");
|
SystemTray tray = SystemTray.getSystemTray();
|
||||||
|
Image image = Toolkit.getDefaultToolkit().createImage("");
|
||||||
|
|
||||||
TrayIcon trayIcon = new TrayIcon(image, "Baritone");
|
trayIcon = new TrayIcon(image, "Baritone");
|
||||||
trayIcon.setImageAutoSize(true);
|
trayIcon.setImageAutoSize(true);
|
||||||
trayIcon.setToolTip("Baritone");
|
trayIcon.setToolTip("Baritone");
|
||||||
tray.add(trayIcon);
|
tray.add(trayIcon);
|
||||||
|
|
||||||
if (error) {
|
|
||||||
trayIcon.displayMessage("Baritone", text, TrayIcon.MessageType.ERROR);
|
|
||||||
} else {
|
|
||||||
trayIcon.displayMessage("Baritone", text, TrayIcon.MessageType.INFO);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
trayIcon.displayMessage("Baritone", text, error ? TrayIcon.MessageType.ERROR : TrayIcon.MessageType.INFO);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -60,10 +64,20 @@ public class NotificationHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void mac(String text) {
|
||||||
|
ProcessBuilder processBuilder = new ProcessBuilder();
|
||||||
|
processBuilder.command("osascript", "-e", "display notification \"" + text + "\" with title \"Baritone\"");
|
||||||
|
try {
|
||||||
|
processBuilder.start();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// The only way to display notifications on linux is to use the java-gnome library,
|
// The only way to display notifications on linux is to use the java-gnome library,
|
||||||
// or send notify-send to shell with a ProcessBuilder. Unfortunately the java-gnome
|
// or send notify-send to shell with a ProcessBuilder. Unfortunately the java-gnome
|
||||||
// library is licenced under the GPL, see (https://en.wikipedia.org/wiki/Java-gnome)
|
// library is licenced under the GPL, see (https://en.wikipedia.org/wiki/Java-gnome)
|
||||||
public static void linux(String text) {
|
private static void linux(String text) {
|
||||||
ProcessBuilder processBuilder = new ProcessBuilder();
|
ProcessBuilder processBuilder = new ProcessBuilder();
|
||||||
processBuilder.command("notify-send", "-a", "Baritone", text);
|
processBuilder.command("notify-send", "-a", "Baritone", text);
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in New Issue