Skip to content

Commit

Permalink
More reliable dark mode detection on macOS 10.15.
Browse files Browse the repository at this point in the history
  • Loading branch information
weisJ committed Apr 20, 2020
1 parent da8813a commit 61c2b49
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion macos/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ library {
compileTask.get().apply {
dependsOn(macPath)
compilerArgs.addAll("-x", "objective-c++")
compilerArgs.addAll("-mmacosx-version-min=10.10")
compilerArgs.addAll("-mmacosx-version-min=10.14")
compilerArgs.addJavaFrameworks()
source.from(
file("src/main/objectiveCpp/DarkMode.mm")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

public class MacOSThemeMonitorService implements ThemeMonitorService {

private static final boolean loaded = SystemInfo.isMacOSYosemite && MacOSNative.loadLibrary();
private static final boolean loaded = SystemInfo.isMacOSMojave && MacOSNative.loadLibrary();

@Override
public boolean isDarkThemeEnabled() {
Expand Down
7 changes: 3 additions & 4 deletions macos/src/main/objectiveCpp/DarkMode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,9 @@ - (void)notificationEvent:(NSNotification *)notification {
Java_com_github_weisj_darkmode_platform_macos_MacOSNative_isDarkThemeEnabled(JNIEnv *env, jclass obj) {
JNF_COCOA_ENTER(env);
if(@available(macOS 10.14, *)) {
NSString *interfaceStyle = [[NSUserDefaults standardUserDefaults] stringForKey:KEY_APPLE_INTERFACE_STYLE];
// interfaceStyle can be nil (light mode) or "Dark" (dark mode).
BOOL isDark = [VALUE_DARK caseInsensitiveCompare:interfaceStyle] == NSOrderedSame;
return (jboolean) isDark;
NSAppearanceName appearanceName = [[NSApp effectiveAppearance]
bestMatchFromAppearanceWithNames:@[NSAppearanceNameAqua, NSAppearanceNameDarkAqua]];
return (jboolean) [appearanceName isEqualToString:NSAppearanceNameDarkAqua];
} else {
return (jboolean) NO;
}
Expand Down

0 comments on commit 61c2b49

Please sign in to comment.