Sources/OrgPresentation/AppIcons.swift
46 lines · 1937 bytes
1import Foundation
2
3/// The app icons `scripts/make-icon.swift` draws, by id, in its order.
4public enum AppIcons {
5 public static let ids = [
6 "default", "midnight", "paper", "org", "sunset", "forest", "mono", "rainbow", "outline", "terminal",
7 "unicorn", "unicorn-night", "unicorn-pastel",
8 ]
9
10 private static func words(_ id: String) -> [String] { id.split(separator: "-").map { $0.prefix(1).uppercased() + $0.dropFirst() } }
11
12 /// The icon's name in the user's language.
13 public static func name(_ id: String) -> String {
14 switch id {
15 case "default": String(localized: "Default")
16 case "midnight": String(localized: "Midnight")
17 case "paper": String(localized: "Paper")
18 case "sunset": String(localized: "Sunset")
19 case "forest": String(localized: "Forest")
20 case "rainbow": String(localized: "Rainbow")
21 case "outline": String(localized: "Outline")
22 case "unicorn": String(localized: "Unicorn")
23 case "unicorn-night": String(localized: "Unicorn Night")
24 case "unicorn-pastel": String(localized: "Unicorn Pastel")
25 default: words(id).joined(separator: " ")
26 }
27 }
28
29 /// The iOS alternate icon's name; nil for the primary icon.
30 public static func alternateName(_ id: String) -> String? {
31 id == "default" ? nil : "AppIcon-" + words(id).joined()
32 }
33
34 public static func id(alternateName: String?) -> String {
35 ids.first { self.alternateName($0) == alternateName && alternateName != nil } ?? "default"
36 }
37}
38
39extension AppIcons {
40 /// The Mac's Dock icon file for `id` in an appearance, in `Contents/Resources/IconPreviews`;
41 /// nil for the default, which is the bundle's own icon.
42 public static func dockFile(_ id: String, dark: Bool) -> String? {
43 guard id != "default", ids.contains(id) else { return nil }
44 return "\(id)-\(dark ? "dark" : "light")"
45 }
46}