Something went wrong. Try again.
Monorepo for Aesthetic.Computer aesthetic.computer
Something went wrong. Try again.
1.5 kB · 46 lines
Swift
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647import Foundation
enum JukeSource: Int, CaseIterable { case local, aesthetic, spotify, appleMusic
var fixedLabel: String? { switch self { case .local: return nil case .aesthetic: return "Aesthetic" case .spotify: return "Spotify" case .appleMusic: return "Apple Music" } }
var canDetachRecords: Bool { switch self { case .local, .aesthetic: return true case .spotify, .appleMusic: return false } }
func label(machineName: String = JukeSource.machineName) -> String { fixedLabel ?? Self.shortMachineName(machineName) }
static var machineName: String { Host.current().localizedName ?? ProcessInfo.processInfo.hostName }
static func shortMachineName(_ raw: String) -> String { var name = raw.trimmingCharacters(in: .whitespacesAndNewlines) for suffix in [".localdomain", ".local"] where name.lowercased().hasSuffix(suffix) { name.removeLast(suffix.count) break } guard !name.isEmpty else { return "This Mac" } if let macRange = name.range(of: "MacBook ", options: [.caseInsensitive, .backwards]) { let suffix = name[macRange.upperBound...].trimmingCharacters(in: .whitespaces) if !suffix.isEmpty { return suffix } } if let last = name.split(separator: " ").last, name.count > 18 { return String(last) } return name }}