@@ -66,6 +66,12 @@ import Cocoa
6666 */
6767 @objc ( colorFromColorSet: )
6868 class func fromColorSet( name: String ) -> NSColor ?
69+ {
70+ return NSColor . fromColorSet ( name: name, forView: nil )
71+ }
72+
73+ @objc ( colorFromColorSet: forView: )
74+ class func fromColorSet( name: String , forView view: NSView ? ) -> NSColor ?
6975 {
7076 if name. hasPrefix ( " NS " )
7177 {
@@ -116,7 +122,7 @@ import Cocoa
116122
117123 if var l = lightness, abs ( hsl. lightness - l ) > 0.001
118124 {
119- if isDarkModeOn ( )
125+ if isDarkModeOn ( forView : view )
120126 {
121127 var found = false
122128
@@ -147,7 +153,7 @@ import Cocoa
147153 return pair. color? . byChangingLightness ( l )
148154 }
149155
150- if isDarkModeOn ( ) , let variant = pair. variant
156+ if isDarkModeOn ( forView : view ) , let variant = pair. variant
151157 {
152158 return variant
153159 }
@@ -542,11 +548,28 @@ import Cocoa
542548 return ( h, s, l )
543549 }
544550
545- @nonobjc private class func isDarkModeOn( ) -> Bool
551+ @nonobjc private class func isDarkModeOn( forView view : NSView ? ) -> Bool
546552 {
547553 if #available( macOS 10 . 14 , * )
548554 {
549- if NSApp != nil && NSApp . effectiveAppearance. name == NSAppearance . Name. darkAqua
555+ let name = view? . effectiveAppearance. name ?? NSApp . effectiveAppearance. name
556+
557+ if name == . darkAqua
558+ {
559+ return true
560+ }
561+
562+ if name == . vibrantDark
563+ {
564+ return true
565+ }
566+
567+ if name == . accessibilityHighContrastDarkAqua
568+ {
569+ return true
570+ }
571+
572+ if name == . accessibilityHighContrastVibrantDark
550573 {
551574 return true
552575 }
0 commit comments