Skip to content

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

chore: 调整菜单栏图标配置

Bob8ae5b1762d50
diff --git a/CodexBar/AppSettingsView.swift b/CodexBar/AppSettingsView.swift
index 04b8359..a43ce41 100644
--- a/CodexBar/AppSettingsView.swift
+++ b/CodexBar/AppSettingsView.swift
@@ -155,7 +155,7 @@ private extension AppSettingsView {
.animation(Metrics.statusAnimation, value: appUpdater.availableUpdateMessage != nil)
}
- /// 版本行优先显示更新状态, 没有动态消息时回退到当前版本号
+ // 版本行优先显示更新状态, 没有动态消息时回退到当前版本号
var versionStatus: (text: String, isVersionLabel: Bool) {
if let message = appUpdater.settingsStatusMessage ?? appUpdater.availableUpdateMessage {
return (message, false)
diff --git a/CodexBar/CodexBarApp.swift b/CodexBar/CodexBarApp.swift
index 7cc30e5..f20202c 100644
--- a/CodexBar/CodexBarApp.swift
+++ b/CodexBar/CodexBarApp.swift
@@ -18,7 +18,7 @@ nonisolated extension Bundle {
object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String
}
- /// `v1.2.3` 形式的版本文案; 缺失时回退 `--`
+ // `v1.2.3` 形式的版本文案; 缺失时回退 `--`
var displayVersionLabel: String {
guard let version = shortVersionString else { return "--" }
return "v\(version)"
diff --git a/CodexBar/CodexCLIResolver.swift b/CodexBar/CodexCLIResolver.swift
index ba94139..764e292 100644
--- a/CodexBar/CodexCLIResolver.swift
+++ b/CodexBar/CodexCLIResolver.swift
@@ -31,7 +31,7 @@ nonisolated struct CodexCLIInstallations: Sendable, Equatable {
let globalPath: String?
let bundledPath: String?
- /// 与启动优先级一致: 全局优先, 回退内置
+ // 与启动优先级一致: 全局优先, 回退内置
var activeSource: CodexCLIExecutableSource? {
if globalPath != nil { return .global }
if bundledPath != nil { return .bundled }
@@ -54,7 +54,7 @@ nonisolated enum CodexCLIResolver {
try command(from: resolveInstallations(environment: environment))
}
- /// 从已解析的安装信息派生命令, 避免重复扫描 PATH
+ // 从已解析的安装信息派生命令, 避免重复扫描 PATH
static func command(from installations: CodexCLIInstallations) throws -> AppServerCommand {
guard let source = installations.activeSource,
let path = installations.path(for: source) else {
diff --git a/CodexBar/CodexCLIVersionService.swift b/CodexBar/CodexCLIVersionService.swift
index 3da1588..9a8fb64 100644
--- a/CodexBar/CodexCLIVersionService.swift
+++ b/CodexBar/CodexCLIVersionService.swift
@@ -43,14 +43,14 @@ nonisolated struct CodexCLIVersionItem: Equatable, Identifiable, Sendable {
}
}
-/// 合并磁盘探测版本和当前 app-server 握手版本
+// 合并磁盘探测版本和当前 app-server 握手版本
nonisolated struct CodexCLIVersionDisplay: Equatable {
let source: CodexCLIExecutableSource
let isCurrent: Bool
let displayVersion: String
let hasVersion: Bool
let path: String?
- /// 当前会话尚未重连到新安装版本时显示的新版本号
+ // 当前会话尚未重连到新安装版本时显示的新版本号
let newerInstalledVersion: String?
init(item: CodexCLIVersionItem, connection: CodexCLIConnectionInfo?) {
diff --git a/CodexBar/CodexQuotaModels.swift b/CodexBar/CodexQuotaModels.swift
index 5e6cf9b..ec89211 100644
--- a/CodexBar/CodexQuotaModels.swift
+++ b/CodexBar/CodexQuotaModels.swift
@@ -162,7 +162,7 @@ nonisolated struct CodexUsageSnapshot: Equatable {
let summary: UsageSummary
let dailyBuckets: [DailyUsageBucket]
- /// 给热力图生成按周排列的最近日期网格, 每列从周日开始
+ // 给热力图生成按周排列的最近日期网格, 每列从周日开始
func recentWeekGrid(columnCount: Int, endingDaysAgo: Int = 0, today: Date = Date()) -> [DailyUsageBucket?] {
guard columnCount > 0 else {
return []
@@ -257,7 +257,7 @@ nonisolated extension CodexQuotaSnapshot {
)
}
- /// 展示顺序: 顶层 rateLimits 指向的主 limit 置顶, 其余按名称排序
+ // 展示顺序: 顶层 rateLimits 指向的主 limit 置顶, 其余按名称排序
private static func orderedSnapshots(
from response: AccountRateLimitsResponse
) -> [(limitId: String, snapshot: RateLimitSnapshot)] {
@@ -334,12 +334,12 @@ nonisolated enum CodexStatusError: LocalizedError {
}
}
- /// codex app-server 未登录
+ // codex app-server 未登录
var isAuthenticationRequired: Bool {
serverErrorMessageContains("codex account authentication required")
}
- /// codex app-server 不支持的方法
+ // codex app-server 不支持的方法
var isUnsupportedMethod: Bool {
switch self {
case .unsupportedMethod:
@@ -357,7 +357,7 @@ nonisolated enum CodexStatusError: LocalizedError {
return !isAuthenticationRequired && !isUnsupportedMethod
}
- /// 连接断开、超时、无法解析都需要重建 app-server 会话
+ // 连接断开、超时、无法解析都需要重建 app-server 会话
var isTransportFailure: Bool {
switch self {
case .serverConnectionClosed, .serverTimeout, .invalidServerResponse:
diff --git a/CodexBar/CodexStatusService.swift b/CodexBar/CodexStatusService.swift
index de22b0c..b5e4061 100644
--- a/CodexBar/CodexStatusService.swift
+++ b/CodexBar/CodexStatusService.swift
@@ -1,6 +1,6 @@
import Foundation
-/// UI 只关心可展示数据、未登录、初始化失败; 更细的错误保留在交互日志中
+// UI 只关心可展示数据、未登录、初始化失败; 更细的错误保留在交互日志中
nonisolated enum CodexFetchOutcome {
case data(CodexQuotaSnapshot)
case notLoggedIn
@@ -13,7 +13,7 @@ private enum ConnectionResolution {
case initializationFailed
}
-/// 单接口读取结果按后续动作分类: 跳过、刷新认证、重建连接
+// 单接口读取结果按后续动作分类: 跳过、刷新认证、重建连接
private enum ReadResult<Value> {
case value(Value)
case skipped(ReadSkipReason)
@@ -62,7 +62,7 @@ nonisolated private extension ReadResult {
return nil
}
- /// 认证刷新后仍是 authRequired/broken 则上抛, 其余原样返回交给调用方按缓存策略处理
+ // 认证刷新后仍是 authRequired/broken 则上抛, 其余原样返回交给调用方按缓存策略处理
func resultAfterAuthAttempt() throws -> ReadResult<Value> {
switch self {
case .value, .skipped:
@@ -75,7 +75,7 @@ nonisolated private extension ReadResult {
}
}
-/// 维持一条 codex app-server stdio 会话, 复用失败后按需重建
+// 维持一条 codex app-server stdio 会话, 复用失败后按需重建
nonisolated final class CodexStatusService: @unchecked Sendable {
private static let requestTimeout: TimeInterval = 20
// 定期回收连接, 让后台升级后的 codex 二进制有机会生效
@@ -116,7 +116,7 @@ nonisolated final class CodexStatusService: @unchecked Sendable {
}
}
- /// 复用连接出现传输故障时只重建重试一次, 避免故障状态下反复拉起进程
+ // 复用连接出现传输故障时只重建重试一次, 避免故障状态下反复拉起进程
private func resolveOutcomeOnQueue(allowRebuild: Bool) -> CodexFetchOutcome {
switch ensureConnection() {
case .notLoggedIn:
@@ -185,7 +185,7 @@ nonisolated final class CodexStatusService: @unchecked Sendable {
return connection.commandInfo
}
- /// 额度与用量独立读取; 认证失败全程只刷新一次 token, 传输故障交给外层重建连接
+ // 额度与用量独立读取; 认证失败全程只刷新一次 token, 传输故障交给外层重建连接
private func fetchData(using connection: AppServerConnection, refreshAccountInfo: Bool) throws -> CodexQuotaSnapshot {
var didRefresh = false
@@ -261,7 +261,7 @@ nonisolated final class CodexStatusService: @unchecked Sendable {
return snapshot
}
- /// 新值更新缓存; 本轮请求失败则回退到缓存并标记陈旧; 方法不支持/认证/断连一律视为无数据
+ // 新值更新缓存; 本轮请求失败则回退到缓存并标记陈旧; 方法不支持/认证/断连一律视为无数据
private func cachedRead<Value>(
_ result: ReadResult<Value>,
cache: inout Value?
@@ -323,7 +323,7 @@ nonisolated final class CodexStatusService: @unchecked Sendable {
}
}
- /// 初始化失败与未登录在这里分流; 两者都不复用本次新建的进程
+ // 初始化失败与未登录在这里分流; 两者都不复用本次新建的进程
private static func openConnection(
command: AppServerCommand,
environment: [String: String],
@@ -416,7 +416,7 @@ nonisolated final class CodexStatusService: @unchecked Sendable {
return version
}
- /// userAgent 形如 "codex_bar/0.139.0 (...)"; 取首个 token 中 "/" 之后的运行版本号
+ // userAgent 形如 "codex_bar/0.139.0 (...)"; 取首个 token 中 "/" 之后的运行版本号
private nonisolated static func serverVersion(fromUserAgent userAgent: String?) -> String? {
guard let firstToken = userAgent?.split(separator: " ").first,
let slashIndex = firstToken.firstIndex(of: "/") else {
diff --git a/CodexBar/CodexStatusViewModel.swift b/CodexBar/CodexStatusViewModel.swift
index e0892e0..47d729b 100644
--- a/CodexBar/CodexStatusViewModel.swift
+++ b/CodexBar/CodexStatusViewModel.swift
@@ -1,7 +1,7 @@
import Combine
import Foundation
-/// UI 级状态; 更细的连接和接口错误由服务层归并到日志
+// UI 级状态; 更细的连接和接口错误由服务层归并到日志
nonisolated enum CodexLoadState: Equatable {
case loading
case loaded
diff --git a/CodexBar/HostingWindowController.swift b/CodexBar/HostingWindowController.swift
index 05975b2..6811fee 100644
--- a/CodexBar/HostingWindowController.swift
+++ b/CodexBar/HostingWindowController.swift
@@ -1,6 +1,6 @@
import AppKit
-/// 承载 SwiftUI 内容的单窗口控制器基类, 统一懒创建、居中与置顶逻辑
+// 承载 SwiftUI 内容的单窗口控制器基类, 统一懒创建、居中与置顶逻辑
@MainActor
class HostingWindowController {
let screenProvider: () -> NSScreen?
diff --git a/CodexBar/RequestLog.swift b/CodexBar/RequestLog.swift
index d39bebe..72c6c7e 100644
--- a/CodexBar/RequestLog.swift
+++ b/CodexBar/RequestLog.swift
@@ -1,8 +1,8 @@
import Combine
import Foundation
-/// JSON-RPC 交互日志: 带 id 的请求先记录为进行, 响应或错误到达后回填到同一条
-/// `initialized` 这类无 id 请求没有响应可等, 单独记录为空响应
+// JSON-RPC 交互日志: 带 id 的请求先记录为进行, 响应或错误到达后回填到同一条
+// `initialized` 这类无 id 请求没有响应可等, 单独记录为空响应
nonisolated struct RequestLogEntry: Identifiable, Equatable {
enum Kind {
case pending
@@ -20,7 +20,7 @@ nonisolated struct RequestLogEntry: Identifiable, Equatable {
var detail: String?
}
-/// 常驻日志存储, 写入来自后台队列, storage 用锁保护, SwiftUI 通知切回主线程发送
+// 常驻日志存储, 写入来自后台队列, storage 用锁保护, SwiftUI 通知切回主线程发送
nonisolated final class RequestLogStore: ObservableObject, @unchecked Sendable {
static let shared = RequestLogStore()
@@ -144,7 +144,7 @@ nonisolated final class RequestLogStore: ObservableObject, @unchecked Sendable {
}
}
- /// 合法 JSON 重新序列化为稳定、未转义斜杠的日志文本; 非 JSON 错误消息保持原样
+ // 合法 JSON 重新序列化为稳定、未转义斜杠的日志文本; 非 JSON 错误消息保持原样
private static func normalized(_ text: String) -> String {
let readableText = jsonNormalized(text) ?? text
guard readableText.count > maxDetailLength else {
diff --git a/CodexBar/StatusItemController.swift b/CodexBar/StatusItemController.swift
index 877a05f..2645da4 100644
--- a/CodexBar/StatusItemController.swift
+++ b/CodexBar/StatusItemController.swift
@@ -47,8 +47,8 @@ private final class StatusItemController: NSObject {
private var cancellables = Set<AnyCancellable>()
private var lastHasError: Bool?
- private static let normalImage = NSImage(systemSymbolName: "person.fill.checkmark", accessibilityDescription: nil)
- private static let errorImage = NSImage(systemSymbolName: "person.fill.xmark", accessibilityDescription: nil)
+ private static let normalImage = makeStatusImage("person.fill.checkmark")
+ private static let errorImage = makeStatusImage("person.fill.xmark")
init(viewModel: CodexStatusViewModel, appUpdater: AppUpdater) {
self.viewModel = viewModel
@@ -56,6 +56,18 @@ private final class StatusItemController: NSObject {
super.init()
}
+ private static func makeStatusImage(_ symbolName: String) -> NSImage? {
+ let configuration = NSImage.SymbolConfiguration(
+ pointSize: 16,
+ weight: .regular,
+ scale: .medium
+ )
+ let image = NSImage(systemSymbolName: symbolName, accessibilityDescription: nil)?
+ .withSymbolConfiguration(configuration)
+ image?.isTemplate = true
+ return image
+ }
+
func install() {
configureStatusButton()
configurePopover()