Update window border.

This commit is contained in:
2025-02-09 14:45:44 -08:00
parent 8527371945
commit 25ef392634
2 changed files with 17 additions and 9 deletions

View File

@@ -86,14 +86,6 @@ func systemImage(_ name: String, _ size: NSFont.TextStyle, _ scale: NSImage.Symb
.withSymbolConfiguration(NSImage.SymbolConfiguration(textStyle: size, scale: scale).applying(configuration))
}
func isDirectory(atPath path: String) -> Bool {
var isDir: ObjCBool = false
if FileManager.default.fileExists(atPath: path, isDirectory: &isDir) {
return isDir.boolValue
}
return false
}
extension String {
// This converts string to UInt as a fourCharCode
public var fourCharCodeValue: Int {

View File

@@ -44,7 +44,6 @@ class SearchViewController: NSViewController, NSTextFieldDelegate, NSPopoverDele
effect.wantsLayer = true
effect.layer?.masksToBounds = true
effect.layer?.borderColor = NSColor.labelColor.withAlphaComponent(0.2).cgColor
effect.layer?.borderWidth = 1
effect.layer?.cornerRadius = windowCornerRadius
@@ -167,11 +166,16 @@ class SearchViewController: NSViewController, NSTextFieldDelegate, NSPopoverDele
override func viewDidLoad() {
super.viewDidLoad()
// NOTE: This needs removeObserver on deinit?
DistributedNotificationCenter.default.addObserver(self, selector: #selector(osThemeChanged(sender:)), name: NSNotification.Name(rawValue: "AppleInterfaceThemeChangedNotification"), object: nil)
// Initialize an array of reusable cells.
for _ in 0..<maxItems {
programsListCells.append(ProgramsTableViewCell())
}
updateViewsBasedOnTheme()
view.wantsLayer = true
view.layer?.backgroundColor = NSColor.clear.cgColor
@@ -362,4 +366,16 @@ class SearchViewController: NSViewController, NSTextFieldDelegate, NSPopoverDele
programsTableViewSelection = programsTableView.selectedRow
}
}
@objc func osThemeChanged(sender: NSNotification) {
updateViewsBasedOnTheme()
}
@objc func updateViewsBasedOnTheme() {
if NSApp.windows.first?.effectiveAppearance.bestMatch(from: [.darkAqua, .vibrantDark]) == .darkAqua { // dark
backgroundView.layer?.borderColor = NSColor.white.withAlphaComponent(0.2).cgColor
} else { // light
backgroundView.layer?.borderColor = NSColor.black.withAlphaComponent(0.2).cgColor
}
}
}