mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-04-19 07:15:54 -04:00
Handle retina system tray icon
This commit is contained in:
parent
f8c4ad27b7
commit
8149611e0b
@ -22,6 +22,7 @@ import io.bitsquare.btc.UserAgent;
|
||||
import io.bitsquare.btc.WalletService;
|
||||
import io.bitsquare.gui.ViewCB;
|
||||
import io.bitsquare.persistence.Persistence;
|
||||
import io.bitsquare.util.Utilities;
|
||||
import io.bitsquare.util.spring.JOptCommandLinePropertySource;
|
||||
|
||||
import java.nio.file.Paths;
|
||||
@ -127,16 +128,13 @@ public class BitsquareEnvironment extends StandardEnvironment {
|
||||
|
||||
|
||||
private static String defaultUserDataDir() {
|
||||
String os = System.getProperty("os.name").toLowerCase();
|
||||
|
||||
if (os.contains("win"))
|
||||
if (Utilities.isWindows())
|
||||
return System.getenv("APPDATA");
|
||||
|
||||
if (os.contains("mac"))
|
||||
else if (Utilities.isOSX())
|
||||
return Paths.get(System.getProperty("user.home"), "Library", "Application Support").toString();
|
||||
|
||||
// *nix
|
||||
return Paths.get(System.getProperty("user.home"), ".local", "share").toString();
|
||||
else
|
||||
// *nix
|
||||
return Paths.get(System.getProperty("user.home"), ".local", "share").toString();
|
||||
}
|
||||
|
||||
private static String appDataDir(String userDataDir, String appName) {
|
||||
|
@ -19,6 +19,7 @@ package io.bitsquare.gui;
|
||||
|
||||
import io.bitsquare.BitsquareException;
|
||||
import io.bitsquare.gui.util.ImageUtil;
|
||||
import io.bitsquare.util.Utilities;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
@ -76,16 +77,26 @@ public class SystemTray {
|
||||
popupMenu.addSeparator();
|
||||
popupMenu.add(exitItem);
|
||||
|
||||
String path = ImageUtil.isRetina() ? ICON_HI_RES : ICON_LO_RES;
|
||||
String path;
|
||||
if (Utilities.isOSX())
|
||||
path = ImageUtil.isRetina() ? ICON_HI_RES : ICON_LO_RES;
|
||||
else
|
||||
path = ICON_HI_RES;
|
||||
|
||||
try {
|
||||
BufferedImage trayIconImage = ImageIO.read(getClass().getResource(path));
|
||||
int trayIconWidth = new TrayIcon(trayIconImage).getSize().width;
|
||||
TrayIcon trayIcon = new TrayIcon(trayIconImage.getScaledInstance(trayIconWidth, -1, Image.SCALE_SMOOTH));
|
||||
TrayIcon trayIcon = new TrayIcon(trayIconImage);
|
||||
// On Windows and Linux the icon needs to be scaled
|
||||
// On OSX we get the correct size from the provided image
|
||||
if (!Utilities.isOSX()) {
|
||||
int trayIconWidth = trayIcon.getSize().width;
|
||||
trayIcon = new TrayIcon(trayIconImage.getScaledInstance(trayIconWidth, -1, Image.SCALE_SMOOTH));
|
||||
}
|
||||
|
||||
trayIcon.setPopupMenu(popupMenu);
|
||||
trayIcon.setToolTip("Bitsquare: The decentralized bitcoin exchange");
|
||||
|
||||
java.awt.SystemTray self = java.awt.SystemTray.getSystemTray();
|
||||
self.add(trayIcon);
|
||||
java.awt.SystemTray.getSystemTray().add(trayIcon);
|
||||
} catch (AWTException e1) {
|
||||
log.error("Icon could not be added to system tray.", e1);
|
||||
} catch (IOException e2) {
|
||||
|
@ -17,6 +17,8 @@
|
||||
|
||||
package io.bitsquare.gui.components;
|
||||
|
||||
import io.bitsquare.util.Utilities;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -34,8 +36,8 @@ public class SystemNotification {
|
||||
public static void openInfoNotification(String title, String message) {
|
||||
// On windows it causes problems with the hidden stage used in the hansolo Notification implementation
|
||||
// Lets deactivate it for the moment and fix that with a more native-like or real native solution later.
|
||||
String os = System.getProperty("os.name").toLowerCase();
|
||||
if (!os.contains("win"))
|
||||
// Lets deactivate it for Linux as well, as it is not much tested yet
|
||||
if (Utilities.isOSX())
|
||||
notifier.notify(NotificationBuilder.create().title(title).message(message).build());
|
||||
}
|
||||
}
|
||||
|
@ -52,6 +52,22 @@ public class Utilities {
|
||||
return gson.toJson(object);
|
||||
}
|
||||
|
||||
public static boolean isWindows() {
|
||||
return getOSName().contains("win");
|
||||
}
|
||||
|
||||
public static boolean isOSX() {
|
||||
return getOSName().contains("mac");
|
||||
}
|
||||
|
||||
public static boolean isLinux() {
|
||||
return getOSName().contains("darwin");
|
||||
}
|
||||
|
||||
private static String getOSName() {
|
||||
return System.getProperty("os.name").toLowerCase();
|
||||
}
|
||||
|
||||
public static <T> T jsonToObject(String jsonString, Class<T> classOfT) {
|
||||
Gson gson =
|
||||
new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE).setPrettyPrinting().create();
|
||||
|
Loading…
x
Reference in New Issue
Block a user