Sources/OrgPresentation/AppIcons.swift
cmc App icon picker in Settings ▸ Appearance; Dock icon follows the appearance
ed75375eb5 1 month ago29 lines · 1269 bytes
1/// The app icons `scripts/make-icon.swift` draws, by id, in its order.
2public enum AppIcons {
3 public static let ids = [
4 "default", "midnight", "paper", "org", "sunset", "forest", "mono", "rainbow", "outline", "terminal",
5 "unicorn", "unicorn-night", "unicorn-pastel",
6 ]
7
8 private static func words(_ id: String) -> [String] { id.split(separator: "-").map { $0.prefix(1).uppercased() + $0.dropFirst() } }
9
10 public static func name(_ id: String) -> String { words(id).joined(separator: " ") }
11
12 /// The iOS alternate icon's name; nil for the primary icon.
13 public static func alternateName(_ id: String) -> String? {
14 id == "default" ? nil : "AppIcon-" + words(id).joined()
15 }
16
17 public static func id(alternateName: String?) -> String {
18 ids.first { self.alternateName($0) == alternateName && alternateName != nil } ?? "default"
19 }
20}
21
22extension AppIcons {
23 /// The Mac's Dock icon file for `id` in an appearance, in `Contents/Resources/IconPreviews`;
24 /// nil for the default, which is the bundle's own icon.
25 public static func dockFile(_ id: String, dark: Bool) -> String? {
26 guard id != "default", ids.contains(id) else { return nil }
27 return "\(id)-\(dark ? "dark" : "light")"
28 }
29}