macOS: fix icon style not updating on Tahoe

This commit is contained in:
Lukas
2026-04-08 13:12:37 +02:00
parent 853183e911
commit 363cb9560e

View File

@@ -82,7 +82,7 @@ class DockTilePlugin: NSObject, NSDockTilePlugIn {
/// Reset the application icon and dock tile icon to the default.
private func resetIcon(dockTile: NSDockTile) {
let appBundlePath = self.ghosttyAppURL?.path
let appIcon: NSImage
let appIcon: NSImage?
if #available(macOS 26.0, *) {
// Reset to the default (glassy) icon.
if let appBundlePath {
@@ -93,21 +93,8 @@ class DockTilePlugin: NSObject, NSDockTilePlugIn {
// Use the `Blueprint` icon to distinguish Debug from Release builds.
appIcon = pluginBundle.image(forResource: "BlueprintImage")!
#else
// Get the composed icon from the app bundle.
if let appBundlePath,
let iconRep = NSWorkspace.shared.icon(forFile: appBundlePath)
.bestRepresentation(
for: CGRect(origin: .zero, size: dockTile.size),
context: nil,
hints: nil
) {
appIcon = NSImage(size: dockTile.size)
appIcon.addRepresentation(iconRep)
} else {
// If something unexpected happens on macOS 26,
// fall back to a bundled icon.
appIcon = pluginBundle.image(forResource: "AppIconImage")!
}
// Reset to Ghostty.icon
appIcon = nil
#endif
} else {
// Use the bundled icon to keep the corner radius consistent with pre-Tahoe apps.
@@ -126,9 +113,14 @@ class DockTilePlugin: NSObject, NSDockTilePlugIn {
}
private extension NSDockTile {
func setIcon(_ newIcon: NSImage) {
func setIcon(_ newIcon: NSImage?) {
// Update the Dock tile on the main thread.
DispatchQueue.main.async {
guard let newIcon else {
self.contentView = nil
self.display()
return
}
let iconView = NSImageView(frame: CGRect(origin: .zero, size: self.size))
iconView.wantsLayer = true
iconView.image = newIcon