Fix new tab icon color not updating sometimes

This commit is contained in:
Pete Schaffner
2024-04-05 21:12:11 +02:00
parent b947ed0070
commit 620c0f9450

View File

@ -167,8 +167,6 @@ class TerminalWindow: NSWindow {
backgroundColor.luminance < 0.05 backgroundColor.luminance < 0.05
} }
private var newTabButtonImage: NSImage? = nil
private var newTabButtonImageLayer: VibrantLayer? = nil private var newTabButtonImageLayer: VibrantLayer? = nil
func updateTabBar() { func updateTabBar() {
@ -208,16 +206,11 @@ class TerminalWindow: NSWindow {
guard let newTabButtonImageView: NSImageView = newTabButton.subviews.first(where: { guard let newTabButtonImageView: NSImageView = newTabButton.subviews.first(where: {
$0 as? NSImageView != nil $0 as? NSImageView != nil
}) as? NSImageView else { return } }) as? NSImageView else { return }
guard let newTabButtonImage = newTabButtonImageView.image else { return }
if newTabButtonImage == nil {
newTabButtonImage = newTabButtonImageView.image
}
guard let newTabButtonImage else { return } if newTabButtonImageLayer == nil {
let isLightTheme = backgroundColor.isLightColor
let isLightTheme = backgroundColor.isLightColor
if newTabButtonImageLayer == nil {
let fillColor: NSColor = isLightTheme ? .black.withAlphaComponent(0.85) : .white.withAlphaComponent(0.85) let fillColor: NSColor = isLightTheme ? .black.withAlphaComponent(0.85) : .white.withAlphaComponent(0.85)
let newImage = NSImage(size: newTabButtonImage.size, flipped: false) { rect in let newImage = NSImage(size: newTabButtonImage.size, flipped: false) { rect in
newTabButtonImage.draw(in: rect) newTabButtonImage.draw(in: rect)
@ -234,12 +227,9 @@ class TerminalWindow: NSWindow {
newTabButtonImageLayer = imageLayer newTabButtonImageLayer = imageLayer
} }
newTabButtonImageView.layer?.sublayers?.first(where: { $0.className == "VibrantLayer" })?.removeFromSuperlayer() newTabButtonImageView.isHidden = true
newTabButtonImageView.layer?.addSublayer(newTabButtonImageLayer!) newTabButton.layer?.sublayers?.first(where: { $0.className == "VibrantLayer" })?.removeFromSuperlayer()
newTabButtonImageView.image = nil newTabButton.layer?.addSublayer(newTabButtonImageLayer!)
// When we nil out the original image, the image view's frame resizes and repositions
// slightly, so we need to reset it to make sure our new image doesn't shift quickly.
newTabButtonImageView.frame = newTabButton.bounds
} }
private func updateTabsForVeryDarkBackgrounds() { private func updateTabsForVeryDarkBackgrounds() {