mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-04-19 14:00:29 +00:00
38 lines
1.2 KiB
Swift
38 lines
1.2 KiB
Swift
import AppKit
|
|
|
|
extension UserDefaults {
|
|
private static let customIconKeyOld = "CustomGhosttyIcon"
|
|
private static let customIconKeyNew = "CustomGhosttyIcon2"
|
|
|
|
var appIcon: AppIcon? {
|
|
get {
|
|
// Always remove our old pre-docktileplugin values.
|
|
defer {
|
|
removeObject(forKey: Self.customIconKeyOld)
|
|
}
|
|
|
|
// If we have an old, pre-docktileplugin value, then we parse the
|
|
// the old value (try) and set it.
|
|
if let previous = string(forKey: Self.customIconKeyOld), let newIcon = AppIcon(string: previous) {
|
|
// update new storage once
|
|
self.appIcon = newIcon
|
|
return newIcon
|
|
}
|
|
|
|
// Check if we have the new key for our dock tile plugin format.
|
|
guard let data = data(forKey: Self.customIconKeyNew) else {
|
|
return nil
|
|
}
|
|
return try? JSONDecoder().decode(AppIcon.self, from: data)
|
|
}
|
|
|
|
set {
|
|
guard let newData = try? JSONEncoder().encode(newValue) else {
|
|
return
|
|
}
|
|
|
|
set(newData, forKey: Self.customIconKeyNew)
|
|
}
|
|
}
|
|
}
|