Files
openclaw/apps/macos/Sources/OpenClaw/SessionMenuLabelView.swift
Peter Steinberger af326b98d7 fix(macos): avoid SwiftUI macro plugin dependency (#105768)
* fix(macos): avoid SwiftUI macro plugin dependency

* fix(macos): scope chat previews to iOS

* chore(i18n): refresh native source locations

* fix(macos): preserve explicit environment keys in formatter

* chore(pr): keep changelog release-owned
2026-07-12 17:40:41 -07:00

62 lines
2.3 KiB
Swift

import SwiftUI
// Keep this explicit for SwiftPM toolchains where SwiftUI macro plugins are unavailable.
// swiftformat:disable environmentEntry
private struct MenuItemHighlightedKey: EnvironmentKey {
static let defaultValue = false
}
extension EnvironmentValues {
var menuItemHighlighted: Bool {
get { self[MenuItemHighlightedKey.self] }
set { self[MenuItemHighlightedKey.self] = newValue }
}
}
// swiftformat:enable environmentEntry
struct SessionMenuLabelView: View {
let row: SessionRow
let width: CGFloat
@Environment(\.menuItemHighlighted) private var isHighlighted
private let paddingLeading: CGFloat = 22
private let paddingTrailing: CGFloat = 14
private let barHeight: CGFloat = 6
var body: some View {
VStack(alignment: .leading, spacing: 8) {
ContextUsageBar(
usedTokens: self.row.tokens.total,
contextTokens: self.row.tokens.contextTokens,
width: max(1, self.width - (self.paddingLeading + self.paddingTrailing)),
height: self.barHeight)
HStack(alignment: .firstTextBaseline, spacing: 2) {
Text(self.row.label)
.font(.caption.weight(self.row.key == "main" ? .semibold : .regular))
.foregroundStyle(MenuItemHighlightColors.primary(self.isHighlighted))
.lineLimit(1)
.truncationMode(.middle)
.layoutPriority(1)
Spacer(minLength: 4)
Text("\(self.row.tokens.contextSummaryShort) · \(self.row.ageText)")
.font(.caption.monospacedDigit())
.foregroundStyle(MenuItemHighlightColors.secondary(self.isHighlighted))
.lineLimit(1)
.fixedSize(horizontal: true, vertical: false)
.layoutPriority(2)
Image(systemName: "chevron.right")
.font(.caption.weight(.semibold))
.foregroundStyle(MenuItemHighlightColors.secondary(self.isHighlighted))
.padding(.leading, 2)
}
}
.padding(.vertical, 10)
.padding(.leading, self.paddingLeading)
.padding(.trailing, self.paddingTrailing)
}
}