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