mirror of
https://github.com/danbee/persephone
synced 2025-03-04 08:39:11 +00:00
Change colour of borders depending on dark/light mode
This commit is contained in:
parent
a61ecc6c40
commit
a251fe18fe
@ -9,7 +9,9 @@
|
|||||||
import Cocoa
|
import Cocoa
|
||||||
|
|
||||||
class AlbumItem: NSCollectionViewItem {
|
class AlbumItem: NSCollectionViewItem {
|
||||||
let albumCoverBorderColor = NSColor.init(calibratedWhite: 1, alpha: 0.1)
|
let borderColorLight = NSColor.black.withAlphaComponent(0.1).cgColor
|
||||||
|
let borderColorDark = NSColor.white.withAlphaComponent(0.1).cgColor
|
||||||
|
var observer: NSKeyValueObservation?
|
||||||
|
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
@ -18,7 +20,13 @@ class AlbumItem: NSCollectionViewItem {
|
|||||||
albumCoverView.wantsLayer = true
|
albumCoverView.wantsLayer = true
|
||||||
albumCoverView.layer?.cornerRadius = 3
|
albumCoverView.layer?.cornerRadius = 3
|
||||||
albumCoverView.layer?.borderWidth = 1
|
albumCoverView.layer?.borderWidth = 1
|
||||||
albumCoverView.layer?.borderColor = albumCoverBorderColor.cgColor
|
setAppearance()
|
||||||
|
|
||||||
|
if #available(OSX 10.14, *) {
|
||||||
|
observer = NSApp.observe(\.effectiveAppearance) { (app, _) in
|
||||||
|
self.setAppearance()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func setAlbum(_ album: MPDClient.Album) {
|
func setAlbum(_ album: MPDClient.Album) {
|
||||||
@ -26,6 +34,17 @@ class AlbumItem: NSCollectionViewItem {
|
|||||||
albumArtist.stringValue = album.artist
|
albumArtist.stringValue = album.artist
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func setAppearance() {
|
||||||
|
if #available(OSX 10.14, *) {
|
||||||
|
let darkMode = NSApp.effectiveAppearance.bestMatch(from:
|
||||||
|
[.darkAqua, .aqua]) == .darkAqua
|
||||||
|
|
||||||
|
albumCoverView.layer?.borderColor = darkMode ? borderColorDark : borderColorLight
|
||||||
|
} else {
|
||||||
|
albumCoverView.layer?.borderColor = borderColorLight
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@IBOutlet var albumCoverView: NSImageView!
|
@IBOutlet var albumCoverView: NSImageView!
|
||||||
@IBOutlet var albumTitle: NSTextField!
|
@IBOutlet var albumTitle: NSTextField!
|
||||||
@IBOutlet var albumArtist: NSTextField!
|
@IBOutlet var albumArtist: NSTextField!
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user