One of the new features in OSX Mojave is dark mode, which allows the user to pick either the traditional light theme, or select a dark theme system wide.
I know how to theme the interface, but i'm wondering if its possible to detect if the user has dark mode enabled?
From research I found this article
https://stackoverflow.com/questions/33477294/menubar-icon-for-dark-mode-on-os-x-in-java/33477375
This suggests using inline java code might work. Although this appears to be executing an external process which might bring other issues.
I can't get this working, but i have only limited knowledge on running inline Java.
Anyone know how I might check if dark or light is selected?
I know how to theme the interface, but i'm wondering if its possible to detect if the user has dark mode enabled?
From research I found this article
https://stackoverflow.com/questions/33477294/menubar-icon-for-dark-mode-on-os-x-in-java/33477375
This suggests using inline java code might work. Although this appears to be executing an external process which might bring other issues.
I can't get this working, but i have only limited knowledge on running inline Java.
Anyone know how I might check if dark or light is selected?
B4X:
private 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 proc = Runtime.getRuntime().exec(new String[] {"defaults", "read", "-g", "AppleInterfaceStyle"});
proc.waitFor(100, TimeUnit.MILLISECONDS);
return proc.exitValue() == 0;
} catch (IOException | InterruptedException | IllegalThreadStateException ex) {
// IllegalThreadStateException thrown by proc.exitValue(), if process didn't terminate
LOG.warn("Could not determine, whether 'dark mode' is being used. Falling back to default (light) mode.");
return false;
}
}