Skip to content

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

fix: 修复菜单栏徽章图标动画卡顿

Bob9b4083bbaeca
diff --git a/AGENTS.md b/AGENTS.md
index 07be3ba..316c9d6 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -44,7 +44,7 @@ CodexBar 是面向 macOS 15+ 的 `LSUIElement` 菜单栏应用,使用 Swift 6,
- 标题、独立列表项、编号项和表格单元格行末不加标点
- 如果一行以 Markdown 格式的链接或行内代码结尾,后面不加任何标点;链接或行内代码位于句中时仍按句子结构使用中文标点
- Markdown 语法、代码块、命令、路径、URL、版本号和程序标识符内部的符号保持原样
-- 如果某句话的作用只是防止被质疑,而不是推进论证,请删除
+- 如果某句话的作用只是防止被质疑,而不是推进论证,请删除这句话
## 架构与编码约定
diff --git a/CodexBar/Models/CodexActivityModels.swift b/CodexBar/Models/CodexActivityModels.swift
index a891208..cd1de9a 100644
--- a/CodexBar/Models/CodexActivityModels.swift
+++ b/CodexBar/Models/CodexActivityModels.swift
@@ -165,7 +165,7 @@ nonisolated struct CodexActivitySnapshot: Equatable {
return [mostRecentCompletion?.completedAt, mostRecentTermination?.terminatedAt]
.compactMap(\.self)
.max()?
- .addingTimeInterval(30)
+ .addingTimeInterval(10)
}
}
diff --git a/CodexBar/Views/Menu/StatusItemIconView.swift b/CodexBar/Views/Menu/StatusItemIconView.swift
index 29de963..36c5907 100644
--- a/CodexBar/Views/Menu/StatusItemIconView.swift
+++ b/CodexBar/Views/Menu/StatusItemIconView.swift
@@ -41,8 +41,10 @@ final class StatusItemIconHostingView: NSHostingView<StatusItemIconView> {
struct StatusItemIconView: View {
@ObservedObject var presentation: StatusItemIconPresentation
+ @Environment(\.displayScale) private var displayScale
static let size = NSSize(width: 26, height: 22)
+ private static var symbolImages: [String: [CGFloat: CGImage]] = [:]
var body: some View {
let state = presentation.state
@@ -63,32 +65,68 @@ struct StatusItemIconView: View {
.opacity(state.isStale ? 0.55 : 1)
.animation(.easeInOut(duration: 0.3), value: state.showsQuota)
- // 基线固定人物主体, 徽章的下伸部分不参与居中计算
- Color.clear
- .frame(width: Self.size.width, height: Self.size.height)
- .alignmentGuide(.firstTextBaseline) { _ in 18 }
- .overlay(alignment: .centerFirstTextBaseline) {
- Image(systemName: state.symbolName)
- .font(.system(size: 14, weight: .regular))
- .symbolRenderingMode(.monochrome)
- .foregroundStyle(.primary)
- .contentTransition(.symbolEffect(
- .replace.magic(fallback: .downUp.byLayer),
- options: .nonRepeating
- ))
- .animation(.default, value: state.symbolName)
- }
- .scaleEffect(
- state.showsQuota ? 1 : 16.0 / 14.0,
- anchor: UnitPoint(x: 0.5, y: 18.0 / 22.0)
- )
- .offset(y: state.showsQuota ? 0 : -1)
- .opacity(state.showsQuota && state.isStale ? 0.75 : 1)
+ ZStack {
+ symbolImage(named: state.symbolName)
+ .id(state.symbolName)
+ .transition(.opacity.combined(with: .scale(
+ scale: 0.75,
+ anchor: UnitPoint(x: 0.5, y: 18.0 / 22.0)
+ )))
+ }
+ .animation(.easeInOut(duration: 0.2), value: state.symbolName)
+ .scaleEffect(
+ state.showsQuota ? 1 : 16.0 / 14.0,
+ anchor: UnitPoint(x: 0.5, y: 18.0 / 22.0)
+ )
+ .offset(y: state.showsQuota ? 0 : -1)
+ .opacity(state.showsQuota && state.isStale ? 0.75 : 1)
}
.animation(.easeInOut(duration: 0.2), value: state.showsQuota)
.frame(width: Self.size.width, height: Self.size.height)
.allowsHitTesting(false)
}
+
+ @ViewBuilder
+ private func symbolImage(named name: String) -> some View {
+ let scale = ceil(max(displayScale, 1) * 16 / 14)
+ if let image = Self.rasterizedSymbol(named: name, displayScale: displayScale, scale: scale) {
+ Image(decorative: image, scale: scale)
+ .renderingMode(.template)
+ .foregroundStyle(.primary)
+ } else {
+ Self.symbolContent(named: name)
+ .foregroundStyle(.primary)
+ }
+ }
+
+ private static func rasterizedSymbol(named name: String, displayScale: CGFloat, scale: CGFloat) -> CGImage? {
+ if let image = symbolImages[name]?[displayScale] {
+ return image
+ }
+
+ // 只在符号或屏幕倍率首次出现时栅格化, 缩放过程复用普通图片
+ let renderer = ImageRenderer(content: symbolContent(named: name)
+ .foregroundStyle(.white)
+ .environment(\.displayScale, displayScale))
+ renderer.scale = scale
+ guard let image = renderer.cgImage else {
+ return nil
+ }
+ symbolImages[name, default: [:]][displayScale] = image
+ return image
+ }
+
+ private static func symbolContent(named name: String) -> some View {
+ // 基线固定人物主体, 徽章的下伸部分不参与居中计算
+ Color.clear
+ .frame(width: size.width, height: size.height)
+ .alignmentGuide(.firstTextBaseline) { _ in 18 }
+ .overlay(alignment: .centerFirstTextBaseline) {
+ Image(systemName: name)
+ .font(.system(size: 14, weight: .regular))
+ .symbolRenderingMode(.monochrome)
+ }
+ }
}
private nonisolated struct StatusItemQuotaArc: Shape {
diff --git a/Config/Version.xcconfig b/Config/Version.xcconfig
index 51544fb..ec396f3 100644
--- a/Config/Version.xcconfig
+++ b/Config/Version.xcconfig
@@ -1,2 +1,2 @@
-MARKETING_VERSION = 3.7.4
-CURRENT_PROJECT_VERSION = 88
+MARKETING_VERSION = 3.7.5
+CURRENT_PROJECT_VERSION = 89
diff --git a/Docs/DeveloperGuide/activity-monitor.md b/Docs/DeveloperGuide/activity-monitor.md
index 14d65b3..4e0ce35 100644
--- a/Docs/DeveloperGuide/activity-monitor.md
+++ b/Docs/DeveloperGuide/activity-monitor.md
@@ -296,7 +296,7 @@ subagent 的 turn ID 属于 subagent 自己,父任务只能通过共享 sessio
等待批准 > 运行中 > 最近完成 > 最近中断 > 空闲
```
-菜单栏同样优先展示等待批准和运行中任务;没有活跃任务时,从完成与终止记录中选择最新一条,显示到结束时间后 30 秒。任务中心的终态记录保留 10 分钟,terminal 去重记忆保留 24 小时。
+菜单栏同样优先展示等待批准和运行中任务;没有活跃任务时,从完成与终止记录中选择最新一条,显示到结束时间后 10 秒。任务中心的终态记录保留 10 分钟,terminal 去重记忆保留 24 小时。
快照由以下模块消费:
@@ -320,7 +320,7 @@ monitor 每秒检查 rollout,并在清理 deadline 到达时刷新。
### 清理采用最近 deadline
-monitor 管理 terminal grace、活动保留、历史保留、terminal 去重和保护记录过期。菜单栏完成或终止提示的 30 秒到期由 `StatusItemController` 独立管理,不为提示到期重新发布活动快照。
+monitor 管理 terminal grace、活动保留、历史保留、terminal 去重和保护记录过期。菜单栏完成或终止提示的 10 秒到期由 `StatusItemController` 独立管理,不为提示到期重新发布活动快照。
清理任务只等待最近的未来 deadline,到点处理后安排下一次。
diff --git a/Docs/DeveloperGuide/architecture.md b/Docs/DeveloperGuide/architecture.md
index 401cdee..dab1b23 100644
--- a/Docs/DeveloperGuide/architecture.md
+++ b/Docs/DeveloperGuide/architecture.md
@@ -218,7 +218,7 @@ Hook + rollout --------> CodexActivityMonitor --------> UI
| app-server connection | 请求时检查 1 小时复用上限 | 后续请求重建连接时使用磁盘上的 binary |
| app-server supplemental cache | 当前账户内 | 避免跨账户串值 |
| Hook live bootstrap window | 24 小时 | 覆盖可能仍在运行的长任务 |
-| 菜单栏完成或终止提示 | 30 秒 | 最新终态的短时反馈 |
+| 菜单栏完成或终止提示 | 10 秒 | 最新终态的短时反馈 |
| 任务中心 terminal 历史 | 10 分钟 | 提供近期上下文但不长期占用 UI |
| terminal 去重记忆 | 24 小时 | 防止迟到 Hook 或 rollout 复活旧任务 |
| Hook 原始和日聚合 | 210 天 | 支持长期统计和重建 |
diff --git a/Docs/DeveloperGuide/ui-and-lifecycle.md b/Docs/DeveloperGuide/ui-and-lifecycle.md
index 234bdb3..8949513 100644
--- a/Docs/DeveloperGuide/ui-and-lifecycle.md
+++ b/Docs/DeveloperGuide/ui-and-lifecycle.md
@@ -51,10 +51,10 @@ UI 使用 SwiftUI 声明内容,由 AppKit Controller 管理窗口。
图标优先级是:
```text
-账户异常 > 等待批准 > 运行中 > 最近 30 秒内的完成或终止 > 空闲
+账户异常 > 等待批准 > 运行中 > 最近 10 秒内的完成或终止 > 空闲
```
-`CodexActivitySnapshot.statusItemActivity(at:)` 在没有活跃任务时按结束时间选择最新终态。`StatusItemController` 按结束时间加 30 秒安排到期任务,到期后恢复普通人形;系统唤醒时按当前时间重算,状态变化和卸载时取消旧任务。
+`CodexActivitySnapshot.statusItemActivity(at:)` 在没有活跃任务时按结束时间选择最新终态。`StatusItemController` 按结束时间加 10 秒安排到期任务,到期后恢复普通人形;系统唤醒时按当前时间重算,状态变化和卸载时取消旧任务。
### 分离图标与 tooltip 状态
@@ -62,7 +62,8 @@ UI 使用 SwiftUI 声明内容,由 AppKit Controller 管理窗口。
- 活跃任务持续时间每分钟变化,只更新 tooltip
- 额度过期但仍展示缓存时,图标和进度使用降低后的 alpha
-- `StatusItemIconView` 在符号名称变化时使用 `.replace.magic(fallback: .downUp.byLayer)` 非重复替换动画
+- `StatusItemIconView` 按符号名称和屏幕倍率缓存预渲染图片,缩放时复用图片,避免带徽章符号实时渲染时的卡顿
+- 符号名称变化时,新旧图片在 0.2 秒内交叉淡入淡出,并在 75% 与完整大小之间缩放;只切换额度显隐时不触发图片替换
- 额度显隐在 0.3 秒内将彩色圆弧从零绘制到当前额度,或从当前额度收回到零,底轨独立淡入淡出
- 人物按符号基线对齐,隐藏额度时恢复正常大小;大小和位置在 0.2 秒内过渡
- 关闭额度时保留最后的额度和配色供收回动画使用,零额度与缺失额度保持不同语义
@@ -283,7 +284,8 @@ app-server 状态默认每 60 秒检查刷新。主面板打开后约 160 ms 调
## 手动验证矩阵
- 左键打开主面板,右键和 Control 点击打开上下文菜单
-- 菜单栏符号随任务状态切换,最新终态在结束 30 秒后恢复空闲,跨睡眠唤醒后按当前时间显示
+- 菜单栏符号随任务状态切换,最新终态在结束 10 秒后恢复空闲,跨睡眠唤醒后按当前时间显示
+- 普通人物与四种任务徽章之间切换时过渡完整,快速连续切换后显示最新状态;带徽章时反复切换额度显隐仍保持流畅,首次显示和唤醒重算不播放过渡
- 切换额度圆弧显隐时动画完整,零额度保留底轨,缓存额度变淡
- 防睡眠生效时太阳徽标仅在“动画效果”开启且所属面板展示期间旋转;关闭动画效果后保留静态太阳,再次开启后仅可见宿主恢复旋转;冷启动后不打开面板、关闭后继续运行任务时均无持续旋转开销;重开、快速开关和 popover 与 fallback 切换后均保持每 2 秒一圈的匀速旋转,任务结束后徽标消失
- 代理密码显隐切换时淡化正常,输入内容、选区和焦点保留
diff --git a/Docs/UserGuide/main-panel.md b/Docs/UserGuide/main-panel.md
index d90e071..2e14596 100644
--- a/Docs/UserGuide/main-panel.md
+++ b/Docs/UserGuide/main-panel.md
@@ -12,11 +12,11 @@ CodexBar 用人物图标和可选额度圆弧表达账户、任务和额度状
| 斜杠人形 | 未登录、初始化失败或缺少可信额度与用量数据 |
| 时钟徽章 | 至少有一个任务正在运行 |
| 钥匙徽章 | 至少有一个任务正在等待用户批准 |
-| 盾牌勾徽章 | 任务刚刚完成,显示 30 秒 |
-| 盾牌感叹号徽章 | 任务刚刚被终止,显示 30 秒 |
+| 盾牌勾徽章 | 任务刚刚完成,显示 10 秒 |
+| 盾牌感叹号徽章 | 任务刚刚被终止,显示 10 秒 |
| 人物上方的缺口圆弧 | 所选额度窗口的剩余比例,颜色与面板百分比一致 |
-多个状态同时存在时,账户异常优先,其次是等待批准、运行中,最后是最近 30 秒内的完成或终止;两种结束记录按时间选择最新的一条。
+多个状态同时存在时,账户异常优先,其次是等待批准、运行中,最后是最近 10 秒内的完成或终止;两种结束记录按时间选择最新的一条。
隐藏额度圆弧时,人物图标会放大。
diff --git a/Docs/en/DeveloperGuide/activity-monitor.md b/Docs/en/DeveloperGuide/activity-monitor.md
index e91f0f7..8c3ab5d 100644
--- a/Docs/en/DeveloperGuide/activity-monitor.md
+++ b/Docs/en/DeveloperGuide/activity-monitor.md
@@ -296,7 +296,7 @@ The activity card selects content through `primaryActivity` in this order:
Waiting for approval > Running > Recently completed > Recently terminated > Idle
```
-The menu bar also prioritizes waiting and running tasks. With no active tasks, it selects the latest completion or termination until 30 seconds after the end timestamp. Task Center retains terminal records for 10 minutes; terminal deduplication memory lasts 24 hours.
+The menu bar also prioritizes waiting and running tasks. With no active tasks, it selects the latest completion or termination until 10 seconds after the end timestamp. Task Center retains terminal records for 10 minutes; terminal deduplication memory lasts 24 hours.
The snapshot feeds:
@@ -320,7 +320,7 @@ All lists sort by most recent time first and then display UUID string. Stable or
### Cleanup Uses the Nearest Deadline
-The monitor manages terminal grace, activity retention, history retention, terminal deduplication, and protection-record expiration. `StatusItemController` independently manages the 30-second completion or termination indication; its expiration does not republish the activity snapshot.
+The monitor manages terminal grace, activity retention, history retention, terminal deduplication, and protection-record expiration. `StatusItemController` independently manages the 10-second completion or termination indication; its expiration does not republish the activity snapshot.
The cleanup task waits for the nearest future deadline, processes it, then schedules the next.
diff --git a/Docs/en/DeveloperGuide/architecture.md b/Docs/en/DeveloperGuide/architecture.md
index ddfd42c..9c23622 100644
--- a/Docs/en/DeveloperGuide/architecture.md
+++ b/Docs/en/DeveloperGuide/architecture.md
@@ -218,7 +218,7 @@ State lifetimes are:
| app-server connection | A 1-hour reuse limit checked on requests | Later requests rebuild with the binary on disk |
| app-server supplemental cache | Current account only | Prevents values from leaking across accounts |
| Hook live bootstrap window | 24 hours | Covers long-running tasks that may still be active |
-| Menu bar completion or termination | 30 seconds | Brief feedback for the latest terminal state |
+| Menu bar completion or termination | 10 seconds | Brief feedback for the latest terminal state |
| Task Center terminal history | 10 minutes | Provides recent context without occupying the UI indefinitely |
| Terminal deduplication memory | 24 hours | Prevents late Hook or rollout data from reviving old tasks |
| Raw Hook data and daily aggregations | 210 days | Supports long-term metrics and rebuilding |
diff --git a/Docs/en/DeveloperGuide/ui-and-lifecycle.md b/Docs/en/DeveloperGuide/ui-and-lifecycle.md
index ae956a5..bd47ee9 100644
--- a/Docs/en/DeveloperGuide/ui-and-lifecycle.md
+++ b/Docs/en/DeveloperGuide/ui-and-lifecycle.md
@@ -51,10 +51,10 @@ The status icon combines app-server loading state, the menu bar rate-limit setti
Icon priority is:
```text
-Account error > Waiting for approval > Running > Latest completion or termination within 30 seconds > Idle
+Account error > Waiting for approval > Running > Latest completion or termination within 10 seconds > Idle
```
-When no tasks are active, `CodexActivitySnapshot.statusItemActivity(at:)` selects the latest terminal timestamp. `StatusItemController` schedules expiration 30 seconds after that timestamp, then restores the plain person. It recalculates on wake and cancels the old task on state changes or uninstall.
+When no tasks are active, `CodexActivitySnapshot.statusItemActivity(at:)` selects the latest terminal timestamp. `StatusItemController` schedules expiration 10 seconds after that timestamp, then restores the plain person. It recalculates on wake and cancels the old task on state changes or uninstall.
### Separating Icon State from Tooltip State
@@ -62,7 +62,8 @@ When no tasks are active, `CodexActivitySnapshot.statusItemActivity(at:)` select
- Minute-by-minute duration updates affect only the tooltip
- Cached quota dims the symbol and arc
-- Symbol-name changes use nonrepeating `.replace.magic(fallback: .downUp.byLayer)` transitions
+- `StatusItemIconView` caches rasterized images by symbol name and display scale, reusing them during scaling to avoid stuttering from live rendering of badged symbols
+- Symbol-name changes crossfade the old and new images over 0.2 seconds while scaling between 75% and full size; quota visibility changes alone do not replace the image
- Showing or hiding quota animates the colored arc between zero and the current percentage over 0.3 seconds; the track fades independently
- Symbols share a baseline; hiding quota restores normal size with a 0.2-second size and position transition
- Hiding quota retains its last percentage and color for retraction; zero and unavailable quota remain distinct
@@ -283,7 +284,8 @@ Release scripts require Developer ID, signing, and notarization credentials and
## Manual Validation Matrix
- Left-click opens the main panel; right-click and Control-click open the context menu
-- Menu bar symbols follow task state; terminal feedback expires 30 seconds after the task ends and is recalculated on wake
+- Menu bar symbols follow task state; terminal feedback expires 10 seconds after the task ends and is recalculated on wake
+- Transitions between the plain person and all four task badges complete correctly, rapid changes settle on the latest state, and toggling quota visibility stays smooth with badges; initial presentation and wake reconciliation do not animate
- Quota-arc visibility animates, zero quota retains the track, and cached quota dims
- The sun badge rotates only while sleep prevention is active, Animation Effects is enabled, and its host panel is presented; disabling Animation Effects preserves a static sun, and enabling it again resumes rotation only in the visible host; no continuous rotation work occurs before the first opening or while tasks continue after closing; reopening, rapid toggling, and switching between popover and fallback hosts preserve a constant speed of one revolution every 2 seconds, and the badge disappears when tasks end
- Password reveal transitions preserve text, selection, and focus
diff --git a/Docs/en/UserGuide/main-panel.md b/Docs/en/UserGuide/main-panel.md
index e2d9fbe..9a705b2 100644
--- a/Docs/en/UserGuide/main-panel.md
+++ b/Docs/en/UserGuide/main-panel.md
@@ -12,11 +12,11 @@ CodexBar combines a person symbol with an optional circular rate-limit arc:
| Slashed person | You are signed out, initialization failed, or trusted rate-limit and usage data is unavailable |
| Clock badge | At least one task is running |
| Key badge | At least one task is waiting for approval |
-| Shield with a checkmark | A task finished within the last 30 seconds |
-| Shield with an exclamation mark | A task was terminated within the last 30 seconds |
+| Shield with a checkmark | A task finished within the last 10 seconds |
+| Shield with an exclamation mark | A task was terminated within the last 10 seconds |
| Circular arc with a bottom gap | Remaining percentage in the selected rate-limit window, using the same colors as the panel |
-Account errors take priority, followed by waiting for approval, running, and the latest completion or termination within 30 seconds. The most recent timestamp determines which terminal state appears.
+Account errors take priority, followed by waiting for approval, running, and the latest completion or termination within 10 seconds. The most recent timestamp determines which terminal state appears.
The person symbol grows when the quota arc is hidden.
diff --git a/appcast.xml b/appcast.xml
index daaeee9..0586c20 100644
--- a/appcast.xml
+++ b/appcast.xml
@@ -7,6 +7,15 @@
<link>https://codexbar.zabrian.app/appcast.xml</link>
<description>CodexBar appcast feed</description>
<language>zh-CN</language>
+ <item>
+ <title>CodexBar.app 3.7.5</title>
+ <sparkle:version>89</sparkle:version>
+ <sparkle:shortVersionString>3.7.5</sparkle:shortVersionString>
+ <sparkle:minimumSystemVersion>15.0</sparkle:minimumSystemVersion>
+ <sparkle:releaseNotesLink>https://codexbar.zabrian.app/notes#3.7.5</sparkle:releaseNotesLink>
+ <pubDate>Fri, 11 Sep 2026 17:22:09 +0800</pubDate>
+ <enclosure url="https://codexbar.zabrian.app/download/CodexBar-v3.7.5.dmg" sparkle:edSignature="porWGsr98IczjP6WR8JN4a5MViD4hZjHpV3YpjcAPNFizSdTfMbXlkJDYIVwTW7RD4cL2EWOIWIYa0G7CaZyDg==" length="7947703" type="application/octet-stream"/>
+ </item>
<item>
<title>CodexBar.app 3.7.4</title>
<sparkle:version>88</sparkle:version>