CodexBar 是一个 macOS 菜单栏应用,用于查看本机 Codex 账号状态、额度、Token 用量、详细统计信息
Swift appkitcodexcodex-clideveloper-toolsmacosmacos-appmenu-bar-appopenai-codexproductivityswiftswiftuiusage-tracker
fix: 调整额度条布局
Bobc67cec4a632f
diff --git a/AGENTS.md b/AGENTS.mdindex aee59d1..34d00ff 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -64,7 +64,7 @@ git status --short- 平台: SwiftUI + AppKit + MVVM, 最低 macOS 15.0。- 应用形态: `LSUIElement` 菜单栏应用, 无 Dock 图标、无主窗口。- 外部依赖: Sparkle(SwiftPM)。-- 当前 build settings: `MACOSX_DEPLOYMENT_TARGET = 15.0`, `MARKETING_VERSION = 2.0.0`, `CURRENT_PROJECT_VERSION = 10`, `SWIFT_DEFAULT_ACTOR_ISOLATION = MainActor`。+- 当前 build settings: `MACOSX_DEPLOYMENT_TARGET = 15.0`, `MARKETING_VERSION = 2.4.4`, `CURRENT_PROJECT_VERSION = 20`, `SWIFT_DEFAULT_ACTOR_ISOLATION = MainActor`。- App Sandbox 必须保持关闭(`ENABLE_APP_SANDBOX = NO`), 因为应用要启动本机 Codex CLI/APP 内置 CLI, 并读取真实 macOS 用户的 Codex 登录状态。- 工程使用 `PBXFileSystemSynchronizedRootGroup`; 新增或删除 `CodexBar/` 下 Swift 文件通常无需改 `project.pbxproj`。只有依赖、target/build settings 或资源归属变更才改 Xcode 工程文件。- Swift 源码按目录组织: `App/`、`Controllers/`、`Models/`、`Services/`、`Views/`。不要把新 Swift 文件直接放回 `CodexBar/` 根层。@@ -173,10 +173,10 @@ Popover:- `LiquidGlassStyle.swift` 是自绘玻璃效果, 不是 macOS 原生 `.glassEffect`; 没有明确设计要求时不要切换。- 账号图标双击触发刷新。邮箱文本双击切换模糊。- 计划名是右侧加粗纯文字; `planBadgeTint(for:)` 优先级: enterprise -> team/business -> pro -> plus -> edu -> free -> 默认 cyan。-- 额度条展示剩余百分比, 颜色按 20% 一档: 红、橙、黄、薄荷、绿。+- 额度条展示剩余百分比, 固定为 50 个胶囊, 每个胶囊宽 `3.5`, 间距 `1.5`, 高 `12`; 颜色按 20% 一档: 红、橙、黄、薄荷、绿。- 无 quota 数据时显示 `--` / `暂无数据`, 并使用占位色。- `rateLimits` 或 `usage` 使用旧缓存时, 对应区域通过 `.markStale(true)` 降低透明度到 0.55, 不降低饱和度; 下一轮对应接口成功后恢复正常透明度。-- 重置时间格式是 `MM-dd HH:mm`。+- 重置时间格式是 `MM-dd HH:mm`, 在额度行最右侧对齐。- 更新时间行显示倒计时圆环、「数据更新时间」和 `HH:mm:ss`。- 倒计时只在 popover 可见时用 `TimelineView` 每秒 tick; 普通 tick 不做连续动画, 仅刷新起点变化时播放恢复动画。- token 区域显示「单日峰值」和「全时累计」; `TokenCountText` 对 1K 以下显示完整整数, 1K 起显示 K/M/B。@@ -258,8 +258,8 @@ fix: 修复 Codex 状态刷新Tag:-- tag 名格式 `v{MARKETING_VERSION}`, 例如 `v2.0.0`。-- 使用附注 tag: `git tag -a v2.0.0 -m "Release v2.0.0"`。+- tag 名格式 `v{MARKETING_VERSION}`, 例如 `v2.4.4`。+- 使用附注 tag: `git tag -a v2.4.4 -m "Release v2.4.4"`。## 最终检查diff --git a/CLAUDE.md b/CLAUDE.mdindex 5a3da25..f5d14ae 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -50,7 +50,7 @@ CodexStatusService (JSON-RPC over `codex app-server --listen stdio://`)WorkflowHookEventRecorder (--hook-event 子进程)→ WorkflowStatsStorage (events/YYYY-MM-DD.jsonl / daily.jsonl,~/Library/Application Support/CodexBar/HookEvents/)→ WorkflowStatsService → WorkflowStatsViewModel- → UsageSummaryView / UsageHeatmap (统计只在热力图 tooltip 中展示)+ → UsageSummaryView / UsageHeatmap (统计只在热力图侧边详情面板中展示)```- 设置开关只能追加/移除 CodexBar 自己的 Hook 处理器,绝不破坏用户已有 Hook。diff --git a/CodexBar/Views/Menu/QuotaRow.swift b/CodexBar/Views/Menu/QuotaRow.swiftindex f16a5b0..3e014a1 100644--- a/CodexBar/Views/Menu/QuotaRow.swift+++ b/CodexBar/Views/Menu/QuotaRow.swift@@ -11,7 +11,6 @@ struct QuotaRow: View {.frame(width: Metrics.labelWidth, alignment: .leading)SegmentedQuotaBar(percent: displayPercent)- .frame(height: Metrics.barHeight)Text(percentText).font(.caption.monospacedDigit().weight(.semibold))@@ -19,12 +18,15 @@ struct QuotaRow: View {.lineLimit(1).frame(width: Metrics.percentWidth, alignment: .leading)+ Spacer(minLength: 0)+Text(resetText).font(.caption2.monospacedDigit()).foregroundStyle(.secondary).lineLimit(1).frame(width: Metrics.resetWidth, alignment: .trailing)}+ .frame(maxWidth: .infinity, alignment: .leading)}}@@ -32,7 +34,6 @@ private extension QuotaRow {enum Metrics {static let spacing: CGFloat = 8static let labelWidth: CGFloat = 52- static let barHeight: CGFloat = 12static let percentWidth: CGFloat = 32static let resetWidth: CGFloat = 76}@@ -105,35 +106,32 @@ private struct SegmentedQuotaBar: View {let percent: Int?var body: some View {- GeometryReader { proxy in- let segmentWidth = segmentWidth(for: proxy.size.width)- let filledSegments = filledSegments()- let filledColor = QuotaBarPalette.filledColor(for: percent)-- HStack(spacing: Metrics.segmentSpacing) {- ForEach(0..<Metrics.segmentCount, id: \.self) { index in- Capsule(style: .continuous)- .fill(index < filledSegments ? filledColor : QuotaBarPalette.placeholderColor)- .frame(width: segmentWidth, height: proxy.size.height)- }+ let filledColor = QuotaBarPalette.filledColor(for: percent)++ HStack(spacing: Metrics.segmentSpacing) {+ ForEach(0..<Metrics.segmentCount, id: \.self) { index in+ Capsule(style: .continuous)+ .fill(index < filledSegments ? filledColor : QuotaBarPalette.placeholderColor)+ .frame(width: Metrics.segmentWidth, height: Metrics.segmentHeight)}}+ .frame(width: Metrics.totalWidth, height: Metrics.segmentHeight, alignment: .leading)}}private extension SegmentedQuotaBar {enum Metrics {static let segmentCount = 50- static let segmentSpacing: CGFloat = 2- }-- func segmentWidth(for width: CGFloat) -> CGFloat {- let availableWidth = max(width, 0)- let totalSpacing = CGFloat(Metrics.segmentCount - 1) * Metrics.segmentSpacing- return max(0, (availableWidth - totalSpacing) / CGFloat(Metrics.segmentCount))+ static let segmentWidth: CGFloat = 3.5+ static let segmentSpacing: CGFloat = 1.5+ static let segmentHeight: CGFloat = 12++ static var totalWidth: CGFloat {+ CGFloat(segmentCount) * segmentWidth + CGFloat(segmentCount - 1) * segmentSpacing+ }}- func filledSegments() -> Int {+ var filledSegments: Int {guard let percent else {return 0}diff --git a/Docs/DevelopmentGuide.md b/Docs/DevelopmentGuide.mdindex def0ed0..22c752b 100644--- a/Docs/DevelopmentGuide.md+++ b/Docs/DevelopmentGuide.md@@ -115,7 +115,7 @@ App 退出时, `applicationWillTerminate` 调用 `StatusItemController.uninstall- 设置状态为 `opening`, 准备透明度淡入- 显示 `NSPopover`, 把 `PopoverVisibilityState.isVisible` 设为 `true`- 调用 `refreshWorkflowStatsIfHookEnabled(performMaintenance: false)`, 只读取已有 `daily.jsonl`, 不做重维护-- 安装 `PopoverDismissMonitor`+- 安装 `PopoverDismissMonitor`, 监听 popover window 并只将 popover window 置前和设为 key window- 执行 0.24 秒淡入- 延迟 160 ms 后调用 `viewModel.refreshIfNeeded()`@@ -123,7 +123,9 @@ App 退出时, `applicationWillTerminate` 调用 `StatusItemController.uninstall- 移除本地和全局事件监听- 将 `isVisible` 设为 `false`, 让倒计时停止 `TimelineView` 每秒 tick+- 临时禁止设置窗口和日志窗口成为 key window, 避免关闭 popover 时 AppKit 把这些辅助窗口提到前面- 默认执行 0.18 秒淡出, 无法淡出时直接关闭+- popover 关闭后延迟 120 ms 恢复设置窗口和日志窗口的 key window 能力`PopoverDismissMonitor` 监听这些 dismiss 条件:@@ -136,7 +138,9 @@ App 退出时, `applicationWillTerminate` 调用 `StatusItemController.uninstallCommand-Space 不直接关闭 popover, 只短暂抑制 600 ms 内的 active 变化关闭逻辑, 避免 Spotlight 或系统搜索抢焦点时误关弹窗。-设置窗口和日志窗口都继承 `HostingWindowController` 的行为: 懒创建, 关闭后不释放, 重新打开复用, 按当前屏幕居中, 重新打开时移动到当前桌面并置前+设置窗口和日志窗口都继承 `HostingWindowController` 的行为: 懒创建, 关闭后不释放, 重新打开复用, 按当前屏幕居中, 重新打开对应入口时只移动和置前对应窗口。++设置窗口和日志窗口使用 `AuxiliaryHostingWindow`; 窗口可以成为 key window, 但不能成为 main window。通过快捷键打开或关闭 popover 时, 只激活并置前 popover, 不主动置前已有的设置窗口或日志窗口。## 5. Codex 状态刷新流程@@ -501,8 +505,9 @@ flowchart TD额度区:- 多个 limit 间用 `LiquidGlassDivider` 分隔-- 每个 quota window 展示标签, 50 段电量条, 剩余百分比和重置时间-- 重置时间格式为 `MM-dd HH:mm`+- 每个 quota window 展示标签, 50 个固定胶囊组成的电量条, 剩余百分比和重置时间+- 胶囊宽度为 `3.5`, 间距为 `1.5`, 高度为 `12`+- 重置时间格式为 `MM-dd HH:mm`, 在额度行最右侧对齐- 无数据时百分比和重置时间显示 `--`, 电量条用占位色- stale 数据通过 `.markStale(true)` 降低透明度到 0.55