Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix system tray visibility for dark mode Mac #2492

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions common/src/main/java/bisq/common/util/Utilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,21 @@ public static ScheduledThreadPoolExecutor getScheduledThreadPoolExecutor(String
return executor;
}

/**
* @return true if <code>defaults read -g AppleInterfaceStyle</code> has an exit status of <code>0</code> (i.e. _not_ returning "key not found").
*/
public static boolean isMacMenuBarDarkMode() {
try {
// check for exit status only. Once there are more modes than "dark" and "default", we might need to analyze string contents..
final Process process = Runtime.getRuntime().exec(new String[] {"defaults", "read", "-g", "AppleInterfaceStyle"});
process.waitFor(100, TimeUnit.MILLISECONDS);
return process.exitValue() == 0;
} catch (IOException | InterruptedException | IllegalThreadStateException ex) {
// IllegalThreadStateException thrown by proc.exitValue(), if process didn't terminate
return false;
}
}

public static boolean isUnix() {
return isOSX() || isLinux() || getOSName().contains("freebsd");
}
Expand Down
8 changes: 7 additions & 1 deletion desktop/src/main/java/bisq/desktop/app/SystemTray.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public class SystemTray {

private static final String ICON_HI_RES = "/images/system_tray_icon@2x.png";
private static final String ICON_LO_RES = "/images/system_tray_icon.png";
private static final String ICON_HI_RES_WHITE = "/images/system_tray_icon@2x_white.png";
private static final String ICON_LO_RES_WHITE = "/images/system_tray_icon_white.png";
private static final String ICON_WINDOWS_LO_RES = "/images/system_tray_icon_windows.png";
private static final String ICON_WINDOWS_HI_RES = "/images/system_tray_icon_windows@2x.png";
private static final String ICON_LINUX = "/images/system_tray_icon_linux.png";
Expand Down Expand Up @@ -97,7 +99,11 @@ private void init() {

String path;
if (Utilities.isOSX())
path = ImageUtil.isRetina() ? ICON_HI_RES : ICON_LO_RES;
if (Utilities.isMacMenuBarDarkMode())
path = ImageUtil.isRetina() ? ICON_HI_RES_WHITE : ICON_LO_RES_WHITE;
else
path = ImageUtil.isRetina() ? ICON_HI_RES : ICON_LO_RES;

else if (Utilities.isWindows())
path = ImageUtil.isRetina() ? ICON_WINDOWS_HI_RES : ICON_WINDOWS_LO_RES;
else
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.