mirror of
https://github.com/openclaw/openclaw.git
synced 2026-02-18 16:17:30 +00:00
49 lines
1.4 KiB
Swift
49 lines
1.4 KiB
Swift
import Foundation
|
|
import UIKit
|
|
|
|
enum NodeDisplayName {
|
|
private static let genericNames: Set<String> = ["iOS Node", "iPhone Node", "iPad Node"]
|
|
|
|
static func isGeneric(_ name: String) -> Bool {
|
|
Self.genericNames.contains(name)
|
|
}
|
|
|
|
static func defaultValue(for interfaceIdiom: UIUserInterfaceIdiom) -> String {
|
|
switch interfaceIdiom {
|
|
case .phone:
|
|
return "iPhone Node"
|
|
case .pad:
|
|
return "iPad Node"
|
|
default:
|
|
return "iOS Node"
|
|
}
|
|
}
|
|
|
|
static func resolve(
|
|
existing: String?,
|
|
deviceName: String,
|
|
interfaceIdiom: UIUserInterfaceIdiom
|
|
) -> String {
|
|
let trimmedExisting = existing?.trimmingCharacters(in: .whitespacesAndNewlines) ?? ""
|
|
if !trimmedExisting.isEmpty, !Self.isGeneric(trimmedExisting) {
|
|
return trimmedExisting
|
|
}
|
|
|
|
let trimmedDevice = deviceName.trimmingCharacters(in: .whitespacesAndNewlines)
|
|
if let normalized = Self.normalizedDeviceName(trimmedDevice) {
|
|
return normalized
|
|
}
|
|
|
|
return Self.defaultValue(for: interfaceIdiom)
|
|
}
|
|
|
|
private static func normalizedDeviceName(_ deviceName: String) -> String? {
|
|
guard !deviceName.isEmpty else { return nil }
|
|
let lower = deviceName.lowercased()
|
|
if lower.contains("iphone") || lower.contains("ipad") || lower.contains("ios") {
|
|
return deviceName
|
|
}
|
|
return nil
|
|
}
|
|
}
|