summaryrefslogtreecommitdiff
path: root/macos/Sources/Features/Colorized Ghostty Icon/ColorizedGhosttyIconImage.swift
blob: 8a461699fbbdcb82b01469776aeb5751dc0a4bbe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import SwiftUI

extension View {
    /// Returns the ghostty icon to use for views.
    func ghosttyIconImage() -> Image {
        #if os(macOS)
        // If we have a specific icon set, then use that
        if let delegate = NSApplication.shared.delegate as? AppDelegate,
           let nsImage = delegate.appIcon {
            return Image(nsImage: nsImage)
        }

        // Grab the icon from the running application. This is the best way
        // I've found so far to get the proper icon for our current icon
        // tinting and so on with macOS Tahoe
        if let icon = NSRunningApplication.current.icon {
            return Image(nsImage: icon)
        }

        // Get our defined application icon image.
        if let nsImage = NSApp.applicationIconImage {
            return Image(nsImage: nsImage)
        }
        #endif

        // Fall back to a static representation
        return Image("AppIconImage")
    }
}