Mercurial > minori
diff src/sys/osx/dark_theme.cc @ 280:9b6e12c14a1e
chore: merge
author | Paper <paper@paper.us.eu.org> |
---|---|
date | Mon, 06 May 2024 17:23:30 -0400 |
parents | 22f9aacf6ac1 |
children |
line wrap: on
line diff
--- a/src/sys/osx/dark_theme.cc Fri Apr 19 13:24:06 2024 -0400 +++ b/src/sys/osx/dark_theme.cc Mon May 06 17:23:30 2024 -0400 @@ -22,22 +22,27 @@ CFBundleRef appkit_bundle = CFBundleGetBundleWithIdentifier(kAppKitBundleID); if (!appkit_bundle) return false; - - NSAppearanceNameAqua = - *reinterpret_cast<CFStringRef*>(CFBundleGetDataPointerForName(appkit_bundle, CFSTR("NSAppearanceNameAqua"))); - if (!NSAppearanceNameAqua) + + auto aqua_appearance = reinterpret_cast<CFStringRef*>(CFBundleGetDataPointerForName(appkit_bundle, CFSTR("NSAppearanceNameAqua"))); + if (!aqua_appearance) return false; + NSAppearanceNameAqua = *aqua_appearance; - NSAppearanceNameDarkAqua = *reinterpret_cast<CFStringRef*>( + auto dark_aqua_appearance = reinterpret_cast<CFStringRef*>( CFBundleGetDataPointerForName(appkit_bundle, CFSTR("NSAppearanceNameDarkAqua"))); - if (!NSAppearanceNameDarkAqua) + if (!dark_aqua_appearance) return false; + NSAppearanceNameDarkAqua = *dark_aqua_appearance; return true; } bool DarkThemeAvailable() { - return (__builtin_available(macOS 10.14, *)); + if (__builtin_available(macOS 10.14, *)) { + return true; + } else { + return false; + } } bool IsInDarkTheme() { @@ -56,6 +61,8 @@ // NSApplication* app = [NSApplication sharedApplication]; const id app = cls_send(objc_getClass("NSApplication"), sel_getUid("sharedApplication")); + if (!app) + return false; // NSAppearance* effectiveAppearance = [app effectiveAppearance]; const id effectiveAppearance = obj_send(app, sel_getUid("effectiveAppearance")); @@ -86,6 +93,8 @@ // NSApplication* app = [NSApplication sharedApplication]; const id app = cls_send(objc_getClass("NSApplication"), sel_getUid("sharedApplication")); + if (!app) + return false; // NSAppearance* appearance = [NSAppearance appearanceNamed: NSAppearanceNameDarkAqua]; const id appearance = @@ -109,6 +118,8 @@ // NSApplication* app = [NSApplication sharedApplication]; const id app = cls_send(objc_getClass("NSApplication"), sel_getUid("sharedApplication")); + if (!app) + return false; // NSAppearance* appearance = [NSAppearance appearanceNamed: NSAppearanceNameDarkAqua]; const id appearance = cls_send(objc_getClass("NSAppearance"), sel_getUid("appearanceNamed:"), NSAppearanceNameAqua); @@ -126,6 +137,8 @@ // NSApplication* app = [NSApplication sharedApplication]; const id app = cls_send(objc_getClass("NSApplication"), sel_getUid("sharedApplication")); + if (!app) + return; // [app setAppearance: null]; obj_send(app, sel_getUid("setAppearance:"), nullptr);