fix(mac): align node details
This commit is contained in:
@@ -23,9 +23,7 @@ struct NodeMenuEntryFormatter {
|
|||||||
entry.text.nonEmpty ?? self.primaryName(entry)
|
entry.text.nonEmpty ?? self.primaryName(entry)
|
||||||
}
|
}
|
||||||
|
|
||||||
static func detailText(_ entry: InstanceInfo) -> String {
|
static func detailLeft(_ entry: InstanceInfo) -> String {
|
||||||
var parts: [String] = []
|
|
||||||
|
|
||||||
var modeLabel: String?
|
var modeLabel: String?
|
||||||
if self.isGateway(entry) {
|
if self.isGateway(entry) {
|
||||||
modeLabel = "gateway"
|
modeLabel = "gateway"
|
||||||
@@ -36,34 +34,26 @@ struct NodeMenuEntryFormatter {
|
|||||||
let base = modeLabel ?? "node"
|
let base = modeLabel ?? "node"
|
||||||
modeLabel = "\(base) v\(version)"
|
modeLabel = "\(base) v\(version)"
|
||||||
}
|
}
|
||||||
if let modeLabel { parts.append(modeLabel) }
|
|
||||||
|
|
||||||
if let ip = entry.ip?.nonEmpty {
|
if let modeLabel { return modeLabel }
|
||||||
parts.append(ip)
|
|
||||||
} else if let platform = entry.platform?.nonEmpty {
|
|
||||||
parts.append(platform)
|
|
||||||
}
|
|
||||||
|
|
||||||
if parts.isEmpty, let text = entry.text.nonEmpty {
|
if let text = entry.text.nonEmpty {
|
||||||
let trimmed = text
|
let trimmed = text
|
||||||
.replacingOccurrences(of: "Node: ", with: "")
|
.replacingOccurrences(of: "Node: ", with: "")
|
||||||
.replacingOccurrences(of: "Gateway: ", with: "")
|
.replacingOccurrences(of: "Gateway: ", with: "")
|
||||||
let candidates = trimmed
|
let candidates = trimmed
|
||||||
.components(separatedBy: " · ")
|
.components(separatedBy: " · ")
|
||||||
.filter { !$0.hasPrefix("mode ") && !$0.hasPrefix("reason ") }
|
.filter { !$0.hasPrefix("mode ") && !$0.hasPrefix("reason ") }
|
||||||
if !candidates.isEmpty {
|
if let first = candidates.first, !first.isEmpty { return first }
|
||||||
parts.append(contentsOf: candidates.prefix(2))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if parts.isEmpty {
|
return entry.ageDescription
|
||||||
parts.append(entry.ageDescription)
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if parts.count > 2 {
|
static func detailRight(_ entry: InstanceInfo) -> String? {
|
||||||
parts = Array(parts.prefix(2))
|
if let ip = entry.ip?.nonEmpty { return ip }
|
||||||
}
|
if let platform = entry.platform?.nonEmpty { return platform }
|
||||||
return parts.joined(separator: " / ")
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
static func leadingSymbol(_ entry: InstanceInfo) -> String {
|
static func leadingSymbol(_ entry: InstanceInfo) -> String {
|
||||||
@@ -119,11 +109,23 @@ struct NodeMenuRowView: View {
|
|||||||
.lineLimit(1)
|
.lineLimit(1)
|
||||||
.truncationMode(.middle)
|
.truncationMode(.middle)
|
||||||
|
|
||||||
Text(NodeMenuEntryFormatter.detailText(self.entry))
|
HStack(spacing: 8) {
|
||||||
.font(.caption)
|
Text(NodeMenuEntryFormatter.detailLeft(self.entry))
|
||||||
.foregroundStyle(self.secondaryColor)
|
.font(.caption)
|
||||||
.lineLimit(1)
|
.foregroundStyle(self.secondaryColor)
|
||||||
.truncationMode(.middle)
|
.lineLimit(1)
|
||||||
|
.truncationMode(.middle)
|
||||||
|
|
||||||
|
Spacer(minLength: 0)
|
||||||
|
|
||||||
|
if let right = NodeMenuEntryFormatter.detailRight(self.entry) {
|
||||||
|
Text(right)
|
||||||
|
.font(.caption.monospacedDigit())
|
||||||
|
.foregroundStyle(self.secondaryColor)
|
||||||
|
.lineLimit(1)
|
||||||
|
.truncationMode(.middle)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
.frame(maxWidth: .infinity, alignment: .leading)
|
.frame(maxWidth: .infinity, alignment: .leading)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user