Skip to content

CodexBar 是一个 macOS 菜单栏应用,用于查看本机 Codex 账号状态、额度、Token 用量、详细统计信息

fix: 优化玻璃样式与计划颜色

Bob03865d077086
diff --git a/CodexBar/AppSettingsView.swift b/CodexBar/AppSettingsView.swift
index a43ce41..3137df0 100644
--- a/CodexBar/AppSettingsView.swift
+++ b/CodexBar/AppSettingsView.swift
@@ -20,7 +20,7 @@ struct AppSettingsView: View {
codexVersionSection
}
.padding(Metrics.panelPadding)
- .liquidGlassSurface(cornerRadius: Metrics.panelCornerRadius, tint: .cyan)
+ .liquidGlassSurface(cornerRadius: Metrics.panelCornerRadius)
HStack(alignment: .center, spacing: 12) {
quitButton
@@ -30,7 +30,7 @@ struct AppSettingsView: View {
}
.animation(Metrics.statusAnimation, value: loginItemSettings.errorMessage)
.padding(Metrics.panelPadding)
- .liquidGlassSurface(cornerRadius: Metrics.panelCornerRadius, tint: .red)
+ .liquidGlassSurface(cornerRadius: Metrics.panelCornerRadius)
}
.padding(Metrics.padding)
.frame(width: Metrics.windowWidth)
@@ -41,7 +41,6 @@ struct AppSettingsView: View {
bottomTrailing: Metrics.surfaceCornerRadius,
topTrailing: 0
),
- tint: .cyan,
isOuterSurface: true
)
.onAppear {
diff --git a/CodexBar/CodexStatusMenuView.swift b/CodexBar/CodexStatusMenuView.swift
index 9d46832..431f015 100644
--- a/CodexBar/CodexStatusMenuView.swift
+++ b/CodexBar/CodexStatusMenuView.swift
@@ -19,7 +19,7 @@ struct CodexStatusMenuView: View {
content
}
.padding(Metrics.padding)
- .liquidGlassSurface(cornerRadius: Metrics.surfaceCornerRadius, tint: .cyan, isOuterSurface: true)
+ .liquidGlassSurface(cornerRadius: Metrics.surfaceCornerRadius, isOuterSurface: true)
.animation(Metrics.statusAnimation, value: viewModel.loadState)
.onChange(of: viewModel.snapshot?.account.email) { _, _ in
isEmailBlurred = false
@@ -73,7 +73,7 @@ private extension CodexStatusMenuView {
updatedAtRow(for: snapshot)
.padding(.horizontal, Metrics.panelPadding)
.padding(.vertical, 7)
- .liquidGlassSurface(cornerRadius: Metrics.panelCornerRadius, tint: .mint)
+ .liquidGlassSurface(cornerRadius: Metrics.panelCornerRadius)
}
var statusAccountCard: some View {
@@ -103,7 +103,7 @@ private extension CodexStatusMenuView {
}
.padding(.horizontal, Metrics.panelPadding)
.padding(.vertical, 8)
- .liquidGlassSurface(cornerRadius: Metrics.panelCornerRadius, tint: .cyan)
+ .liquidGlassSurface(cornerRadius: Metrics.panelCornerRadius)
}
var statusDisplay: (text: String?, color: Color) {
@@ -127,7 +127,7 @@ private extension CodexStatusMenuView {
var emptyPanel: some View {
emptyView
.padding(Metrics.panelPadding)
- .liquidGlassSurface(cornerRadius: Metrics.panelCornerRadius, tint: .cyan)
+ .liquidGlassSurface(cornerRadius: Metrics.panelCornerRadius)
}
func quotaLimitsView(_ limits: [CodexQuotaLimitSnapshot], isStale: Bool) -> some View {
@@ -142,7 +142,7 @@ private extension CodexStatusMenuView {
}
.markStale(isStale)
.padding(Metrics.panelPadding)
- .liquidGlassSurface(cornerRadius: Metrics.panelCornerRadius, tint: .green)
+ .liquidGlassSurface(cornerRadius: Metrics.panelCornerRadius)
}
func quotaLimitSection(_ limit: CodexQuotaLimitSnapshot) -> some View {
@@ -165,7 +165,7 @@ private extension CodexStatusMenuView {
accountRow(title: title, isEmail: isEmail, plan: plan)
.padding(.horizontal, Metrics.panelPadding)
.padding(.vertical, 8)
- .liquidGlassSurface(cornerRadius: Metrics.panelCornerRadius, tint: .cyan)
+ .liquidGlassSurface(cornerRadius: Metrics.panelCornerRadius)
}
func accountRow(title: String, isEmail: Bool = false, plan: String? = nil) -> some View {
@@ -253,12 +253,12 @@ private extension CodexStatusMenuView {
}
static let planTintRules: [(keywords: [String], tint: Color)] = [
- (["enterprise"], .green),
- (["team", "business"], .orange),
- (["pro"], .purple),
- (["plus"], .blue),
- (["edu"], .teal),
- (["free"], .secondary)
+ (["enterprise"], Color(hex: 0x15803D)),
+ (["team", "business"], Color(hex: 0xD97706)),
+ (["pro"], Color(hex: 0xC026D3)),
+ (["plus"], Color(hex: 0x2563EB)),
+ (["edu"], Color(hex: 0x0891B2)),
+ (["free"], Color(hex: 0x64748B))
]
static let timeFormatter: DateFormatter = {
diff --git a/CodexBar/LiquidGlassStyle.swift b/CodexBar/LiquidGlassStyle.swift
index b5af83e..e60d07b 100644
--- a/CodexBar/LiquidGlassStyle.swift
+++ b/CodexBar/LiquidGlassStyle.swift
@@ -8,12 +8,19 @@ extension Color {
// 某些自定义 View 需要具体 Color, 不能直接使用 .primary/.secondary 这类 ShapeStyle
static let codexLabel = Color(nsColor: .labelColor)
static let codexSecondaryLabel = Color(nsColor: .secondaryLabelColor)
+
+ init(hex: Int) {
+ self.init(
+ red: Double((hex >> 16) & 0xFF) / 255.0,
+ green: Double((hex >> 8) & 0xFF) / 255.0,
+ blue: Double(hex & 0xFF) / 255.0
+ )
+ }
}
extension View {
func liquidGlassSurface(
cornerRadius: CGFloat,
- tint: Color,
isOuterSurface: Bool = false
) -> some View {
liquidGlassSurface(
@@ -23,20 +30,17 @@ extension View {
bottomTrailing: cornerRadius,
topTrailing: cornerRadius
),
- tint: tint,
isOuterSurface: isOuterSurface
)
}
func liquidGlassSurface(
cornerRadii: RectangleCornerRadii,
- tint: Color,
isOuterSurface: Bool = false
) -> some View {
background {
LiquidGlassSurface(
cornerRadii: cornerRadii,
- tint: tint,
isOuterSurface: isOuterSurface
)
}
@@ -75,7 +79,6 @@ struct LiquidGlassDivider: View {
private struct LiquidGlassSurface: View {
let cornerRadii: RectangleCornerRadii
- let tint: Color
let isOuterSurface: Bool
@Environment(\.colorScheme) private var colorScheme
@@ -87,33 +90,33 @@ private struct LiquidGlassSurface: View {
.fill(baseFill)
shape
- .fill(
- LinearGradient(
- colors: [
- .white.opacity(isOuterSurface ? 0.18 : 0.24),
- tint.opacity(isOuterSurface ? 0.08 : 0.12),
- .clear
- ],
- startPoint: .topLeading,
- endPoint: .bottomTrailing
- )
- )
+ .fill(highlightFill)
.blendMode(.plusLighter)
+ LiquidGlassFrostedTexture(isOuterSurface: isOuterSurface)
+ .clipShape(shape)
+
shape
.strokeBorder(
- LinearGradient(
- colors: [
- .white.opacity(isOuterSurface ? 0.44 : 0.36),
- tint.opacity(0.24),
- .primary.opacity(0.08)
- ],
- startPoint: .topLeading,
- endPoint: .bottomTrailing
- ),
+ borderColor,
lineWidth: isOuterSurface ? 1.0 : 0.8
)
+ shape
+ .strokeBorder(rimHighlightColor, lineWidth: rimLineWidth)
+ .shadow(
+ color: rimLightShadowColor,
+ radius: isOuterSurface ? 0.5 : 1.0,
+ x: 0,
+ y: isOuterSurface ? -0.2 : -0.4
+ )
+ .shadow(
+ color: rimDarkShadowColor,
+ radius: isOuterSurface ? 0.8 : 1.3,
+ x: 0,
+ y: isOuterSurface ? 0.6 : 1.0
+ )
+
LiquidGlassSpecular(cornerRadii: cornerRadii)
.opacity(isOuterSurface ? 0.82 : 0.64)
}
@@ -137,15 +140,32 @@ private struct LiquidGlassSurface: View {
)
}
- private var baseFill: LinearGradient {
- LinearGradient(
- colors: [
- baseColor.opacity(isOuterSurface ? 1 : 0.94),
- baseColor.opacity(isOuterSurface ? 0.88 : 0.78)
- ],
- startPoint: .topLeading,
- endPoint: .bottomTrailing
- )
+ private var baseFill: Color {
+ baseColor.opacity(0.6)
+ }
+
+ private var highlightFill: Color {
+ .white.opacity(isOuterSurface ? 0.12 : 0.14)
+ }
+
+ private var borderColor: Color {
+ .white.opacity(isOuterSurface ? 0.34 : 0.28)
+ }
+
+ private var rimHighlightColor: Color {
+ .white.opacity(isOuterSurface ? 0.36 : 0.50)
+ }
+
+ private var rimLightShadowColor: Color {
+ .white.opacity(colorScheme == .dark ? 0.05 : 0.20)
+ }
+
+ private var rimDarkShadowColor: Color {
+ .black.opacity(colorScheme == .dark ? 0.28 : 0.12)
+ }
+
+ private var rimLineWidth: CGFloat {
+ isOuterSurface ? 0.8 : 1.1
}
private var baseColor: Color {
@@ -181,6 +201,56 @@ private struct LiquidGlassSurface: View {
}
}
+private struct LiquidGlassFrostedTexture: View {
+ let isOuterSurface: Bool
+ @Environment(\.colorScheme) private var colorScheme
+
+ var body: some View {
+ Canvas(opaque: false, rendersAsynchronously: true) { context, size in
+ let step: CGFloat = isOuterSurface ? 4 : 3
+ let columns = max(Int((size.width / step).rounded(.up)), 0)
+ let rows = max(Int((size.height / step).rounded(.up)), 0)
+ let baseOpacity = colorScheme == .dark ? 0.035 : 0.045
+ let outerScale = isOuterSurface ? 0.75 : 1
+
+ for row in 0..<rows {
+ for column in 0..<columns {
+ let sample = Self.noise(column: column, row: row)
+ let isHighlight = sample >= 0.5
+ let strength = isHighlight ? (sample - 0.5) * 2 : (0.5 - sample) * 2
+ let opacity = baseOpacity * strength * outerScale
+ let color: Color
+ if isHighlight {
+ color = Color.white.opacity(opacity)
+ } else {
+ color = Color.black.opacity(opacity * (colorScheme == .dark ? 0.24 : 0.16))
+ }
+ let rect = CGRect(
+ x: CGFloat(column) * step,
+ y: CGFloat(row) * step,
+ width: 1,
+ height: 1
+ )
+
+ context.fill(Path(rect), with: .color(color))
+ }
+ }
+ }
+ .allowsHitTesting(false)
+ }
+
+ private nonisolated static func noise(column: Int, row: Int) -> Double {
+ var value = UInt64(column) &* 0x9E3779B185EBCA87
+ value ^= UInt64(row) &* 0xC2B2AE3D27D4EB4F
+ value ^= value >> 33
+ value &*= 0xFF51AFD7ED558CCD
+ value ^= value >> 33
+ value &*= 0xC4CEB9FE1A85EC53
+ value ^= value >> 33
+ return Double(value & 0xFFFF) / Double(0xFFFF)
+ }
+}
+
private struct LiquidGlassCapsule: View {
let tint: Color
@Environment(\.colorScheme) private var colorScheme
@@ -207,6 +277,10 @@ private struct LiquidGlassCapsule: View {
Capsule(style: .continuous)
.strokeBorder(.white.opacity(colorScheme == .dark ? 0.22 : 0.34), lineWidth: 0.7)
}
+ .overlay {
+ LiquidGlassFrostedTexture(isOuterSurface: false)
+ .clipShape(Capsule(style: .continuous))
+ }
}
private var baseFill: LinearGradient {
diff --git a/CodexBar/QuotaRow.swift b/CodexBar/QuotaRow.swift
index e1965af..6491ed3 100644
--- a/CodexBar/QuotaRow.swift
+++ b/CodexBar/QuotaRow.swift
@@ -97,20 +97,12 @@ private enum QuotaBarPalette {
}
}
- static let placeholderColor = color(hex: 0xE5E7EB)
- private static let green = color(hex: 0x22C55E)
- private static let teal = color(hex: 0x14B8A6)
- private static let yellow = color(hex: 0xEAB308)
- private static let orange = color(hex: 0xFF7A59)
- private static let red = color(hex: 0xEF4444)
-
- private static func color(hex: Int) -> Color {
- Color(
- red: Double((hex >> 16) & 0xFF) / 255.0,
- green: Double((hex >> 8) & 0xFF) / 255.0,
- blue: Double(hex & 0xFF) / 255.0
- )
- }
+ static let placeholderColor = Color(hex: 0xE5E7EB)
+ private static let green = Color(hex: 0x16A085)
+ private static let teal = Color(hex: 0x5DADE2)
+ private static let yellow = Color(hex: 0xF5B041)
+ private static let orange = Color(hex: 0xFF7A59)
+ private static let red = Color(hex: 0xEE3F3F)
}
private struct SegmentedQuotaBar: View {
@@ -135,7 +127,7 @@ private struct SegmentedQuotaBar: View {
private extension SegmentedQuotaBar {
enum Metrics {
- static let segmentCount = 33
+ static let segmentCount = 50
static let segmentSpacing: CGFloat = 2
}
diff --git a/CodexBar/UsageHeatmap.swift b/CodexBar/UsageHeatmap.swift
index a55043d..0ce65d7 100644
--- a/CodexBar/UsageHeatmap.swift
+++ b/CodexBar/UsageHeatmap.swift
@@ -20,7 +20,7 @@ struct UsageSummaryView: View {
}
.markStale(isStale)
.padding(10)
- .liquidGlassSurface(cornerRadius: 8, tint: .blue)
+ .liquidGlassSurface(cornerRadius: 8)
.onAppear {
hoveredDay = nil
}
@@ -312,6 +312,6 @@ private struct UsageHeatmapTooltip: View {
.padding(.horizontal, 7)
.padding(.vertical, 5)
.frame(width: UsageHeatmap.Metrics.tooltipWidth, alignment: .leading)
- .liquidGlassSurface(cornerRadius: 7, tint: .blue)
+ .liquidGlassSurface(cornerRadius: 7)
}
}