Skip to content

Commit

Permalink
Merge pull request #2492 from ben-kaufman/system-tray-dark-mode-mac
Browse files Browse the repository at this point in the history
Fix system tray visibility for dark mode Mac
  • Loading branch information
ManfredKarrer authored Mar 3, 2019
2 parents ce109da + 26a710d commit 67eed82
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
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.

0 comments on commit 67eed82

Please sign in to comment.