Merge pull request #2492 from ben-kaufman/system-tray-dark-mode-mac

Fix system tray visibility for dark mode Mac
This commit is contained in:
Manfred Karrer 2019-03-03 18:56:55 -05:00 committed by GitHub
commit 67eed82a8a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 1 deletions

View File

@ -155,6 +155,21 @@ public class Utilities {
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");
}

View File

@ -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";
@ -97,7 +99,11 @@ public class SystemTray {
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

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB