2
+ − 1 #include "sys/osx/dark_theme.h"
+ − 2 #import <Cocoa/Cocoa.h>
+ − 3
9
+ − 4 namespace osx {
+ − 5
+ − 6 bool DarkThemeAvailable() {
5
+ − 7 if (@available(macOS 10.14, *))
+ − 8 return true;
+ − 9 else
+ − 10 return false;
2
+ − 11 }
+ − 12
9
+ − 13 bool IsInDarkTheme() {
+ − 14 if (@available(macOS 10.14, *)) {
15
+ − 15 auto appearance = [NSApp.effectiveAppearance
+ − 16 bestMatchFromAppearancesWithNames:@[ NSAppearanceNameAqua, NSAppearanceNameDarkAqua ]];
9
+ − 17 return [appearance isEqualToString:NSAppearanceNameDarkAqua];
+ − 18 }
+ − 19 return false;
2
+ − 20 }
+ − 21
9
+ − 22 void SetToDarkTheme() {
+ − 23 // https://stackoverflow.com/questions/55925862/how-can-i-set-my-os-x-application-theme-in-code
+ − 24 if (@available(macOS 10.14, *)) {
15
+ − 25 [NSApp setAppearance:[NSAppearance appearanceNamed:NSAppearanceNameDarkAqua]];
9
+ − 26 }
2
+ − 27 }
+ − 28
9
+ − 29 void SetToLightTheme() {
+ − 30 // https://stackoverflow.com/questions/55925862/how-can-i-set-my-os-x-application-theme-in-code
+ − 31 if (__builtin_available(macOS 10.14, *)) {
15
+ − 32 [NSApp setAppearance:[NSAppearance appearanceNamed:NSAppearanceNameAqua]];
9
+ − 33 }
2
+ − 34 }
+ − 35
9
+ − 36 void SetToAutoTheme() {
+ − 37 if (@available(macOS 10.14, *)) {
+ − 38 [NSApp setAppearance:nil];
+ − 39 }
2
+ − 40 }
9
+ − 41
+ − 42 } // namespace osx