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 auto appearance =
|
|
16 [NSApp.effectiveAppearance bestMatchFromAppearancesWithNames:@[
|
|
17 NSAppearanceNameAqua, NSAppearanceNameDarkAqua
|
|
18 ]];
|
|
19 return [appearance isEqualToString:NSAppearanceNameDarkAqua];
|
|
20 }
|
|
21 return false;
|
2
|
22 }
|
|
23
|
9
|
24 void SetToDarkTheme() {
|
|
25 // https://stackoverflow.com/questions/55925862/how-can-i-set-my-os-x-application-theme-in-code
|
|
26 if (@available(macOS 10.14, *)) {
|
|
27 [NSApp setAppearance:[NSAppearance
|
|
28 appearanceNamed:NSAppearanceNameDarkAqua]];
|
|
29 }
|
2
|
30 }
|
|
31
|
9
|
32 void SetToLightTheme() {
|
|
33 // https://stackoverflow.com/questions/55925862/how-can-i-set-my-os-x-application-theme-in-code
|
|
34 if (__builtin_available(macOS 10.14, *)) {
|
|
35 [NSApp
|
|
36 setAppearance:[NSAppearance appearanceNamed:NSAppearanceNameAqua]];
|
|
37 }
|
2
|
38 }
|
|
39
|
9
|
40 void SetToAutoTheme() {
|
|
41 if (@available(macOS 10.14, *)) {
|
|
42 [NSApp setAppearance:nil];
|
|
43 }
|
2
|
44 }
|
9
|
45
|
|
46 } // namespace osx
|