CodexBar 是一个 macOS 菜单栏应用,用于查看本机 Codex 账号状态、额度、Token 用量、详细统计信息
Swift appkitcodexcodex-clideveloper-toolsmacosmacos-appmenu-bar-appopenai-codexproductivityswiftswiftuiusage-tracker
feat: 接入 Sparkle 自动更新
Bobe08415046b01
diff --git a/AGENTS.md b/AGENTS.mdindex 5e1300e..3257af8 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -17,6 +17,8 @@ CodexBar 是一个 macOS 菜单栏应用,用来展示当前本机 Codex 账号- 应用运行时每分钟自动刷新,即使弹窗未打开也会刷新。- 双击账号图标可手动刷新。- 按住 Option/Alt 点击菜单栏图标时,才展示设置区。设置区为单行布局:左侧「开机自动启动」开关,右侧「退出」按钮,不展示刷新按钮。+- 更新时间行右侧展示当前 App 版本(`App 版本: v{version} ({build})`),双击该文案触发 Sparkle 检查更新;检查期间该位置改为状态文案,3 秒后自动复位。+- 集成 Sparkle 自动更新:启动时按 `SUScheduledCheckInterval`(Info.plist 配置,当前 3600 秒)后台静默检查,用户也可手动触发。- 没有通知功能:不监听 `account/rateLimits/updated`,不发送 macOS 本地通知(该功能已整体移除,不要恢复)。- 弹窗错误只展示普通错误文案,不包含 Debug 明细或环境变量模拟入口。@@ -77,6 +79,16 @@ Xcode target 已关闭 App Sandbox,因为应用需要启动本机 Codex CLI如果既找不到全局 Codex CLI,也找不到 Codex.app 内置二进制,弹窗会展示 `找不到 Codex CLI 或 Codex App` 错误。+## 自动更新(Sparkle)++应用通过 Sparkle 框架(SwiftPM 依赖)实现自动更新,由 `AppUpdater`(`@MainActor`、`ObservableObject`)封装:++- `CodexBarApp` 创建 `@StateObject AppUpdater()` 并以 `environmentObject` 注入弹窗,`RateLimitsMenuView` 通过 `@EnvironmentObject` 读取。+- 初始化时先校验 Info.plist 的 `SUFeedURL`(必须为 http/https)和 `SUPublicEDKey`(非空),任一缺失则**不创建** `SPUStandardUpdaterController`。此时双击版本文案展示「未配置更新资源」,方便 Debug/未签名构建下静默降级。+- 配置齐全时创建 `SPUStandardUpdaterController(startingUpdater: true)`,`AppUpdater` 自身作为 `SPUUpdaterDelegate`。+- `statusMessage` 是唯一发布的 UI 状态,由 `showStatusMessage` 设置并在 3 秒后用一个可取消的 `Task` 自动清空(新消息会先取消旧 Task)。状态文案:`正在检查更新`、`未配置更新资源`、`发现新版本 v{x}`、`已是最新版本`。+- 当前 Info.plist 配置:`SUFeedURL = https://codexbar.zabrian.app/appcast.xml`,`SUScheduledCheckInterval = 3600`。+## 代码组织- `CodexBarApp.swift`:应用入口,创建 `RateLimitsViewModel`,配置 `MenuBarExtra`。@@ -87,10 +99,14 @@ Xcode target 已关闭 App Sandbox,因为应用需要启动本机 Codex CLI- `RateLimitsMenuView.swift`:点击菜单栏后的弹窗内容,含未登录橙色提示和设置区。- `QuotaRow.swift`:额度行和分段进度条。- `LoginItemSettings.swift`:使用 `SMAppService.mainApp` 管理开机自启。-- `Assets.xcassets/AppIcon.appiconset`:App 图标资源,白底黑色中心符号使用 `timelapse`。-- `Scripts/create-dmg.sh`:将项目根目录下导出的 `.app` 打包成拖拽安装 DMG。+- `AppUpdater.swift`:封装 Sparkle 更新检查、状态文案与 `SPUUpdaterDelegate` 回调。+- `Resources/Info.plist`:应用 Info.plist,含 `SUFeedURL`、`SUPublicEDKey`、`SUScheduledCheckInterval` 等 Sparkle 配置(`INFOPLIST_FILE` 指向此处)。+- `Resources/Assets.xcassets/AppIcon.appiconset`:App 图标资源,白底黑色中心符号使用 `timelapse`。+- `Scripts/create-dmg.sh`:将项目根目录下导出的 `.app` 打包成拖拽安装 DMG,结尾提示用 `update-appcast.sh` 更新 appcast。+- `Scripts/update-appcast.sh`:对 DMG 签名(Sparkle `sign_update`)并把版本条目写入 `Updates/appcast.xml`。+- `Updates/appcast.xml`:Sparkle appcast feed 源文件,发布时由 `update-appcast.sh` 维护。-工程使用文件系统同步组(`PBXFileSystemSynchronizedRootGroup`),新增/删除源文件无需修改 `project.pbxproj`。+工程使用文件系统同步组(`PBXFileSystemSynchronizedRootGroup`),新增/删除源文件无需修改 `project.pbxproj`。源码与资源已统一收纳在 `CodexBar/` 下(资源在 `CodexBar/Resources/`)。Sparkle 通过 SwiftPM 引入,依赖变更才需改 `project.pbxproj`。## UI 约定@@ -103,6 +119,7 @@ Xcode target 已关闭 App Sandbox,因为应用需要启动本机 Codex CLI- 分段条展示剩余额度,剩余额度计算方式是 `100 - usedPercent`。- 额度行标签示例:`300` 分钟显示 `5 小时`,`10080` 分钟显示 `7 天`;缺少 `windowDurationMins` 时再回退到默认文案。- 重置时间格式使用 `MM-dd HH:mm`;更新时间格式使用 `HH:mm:ss`。+- 版本文案格式 `App 版本: v{CFBundleShortVersionString} ({CFBundleVersion})`,用 `monospacedDigit` 字体、`lineLimit(1)`;有 `statusMessage` 时优先展示状态文案。读取 Info.plist 统一用 `Bundle.main.object(forInfoDictionaryKey:)`。- token 数按 `M`、`B` 紧凑单位展示;token 贡献墙使用蓝色方块,7 行 30 列布局,单日用量越高颜色越深## 错误展示约定@@ -135,6 +152,14 @@ Scripts/create-dmg.sh脚本会自动查找当前目录下唯一的 `.app`,根据 Xcode target 的 `MARKETING_VERSION` 生成 `CodexBar-v{version}.dmg`。脚本会在 DMG 中放入 `CodexBar.app` 和 `Applications -> /Applications` 快捷方式,并写入 Finder 布局:app 在左侧,Applications 在右侧。若有多个工程或 scheme,可用 `XCODE_PROJECT`、`XCODE_SCHEME` 环境变量指定。+打包 DMG 后用 `update-appcast.sh` 更新 Sparkle appcast:++```bash+Scripts/update-appcast.sh CodexBar-v1.2.0.dmg # 省略参数时自动取根目录下唯一 .dmg+```++脚本流程:用 Sparkle `sign_update`(PATH 中没有则在 DerivedData 内查找)对 DMG 签名得到 `edSignature` 和长度,从 `xcodebuild -showBuildSettings` 读取 `MARKETING_VERSION`/`CURRENT_PROJECT_VERSION`,生成 `<item>` 并插入 `Updates/appcast.xml`(按 `sparkle:version` 去重同版本旧条目,插在 `<language>` 之后),最后用 `xmllint` 校验。常用环境变量:`DOWNLOAD_BASE_URL`、`RELEASE_NOTES_BASE_URL`、`INCLUDE_RELEASE_NOTES`、`MINIMUM_SYSTEM_VERSION`、`SIGN_UPDATE`、`APPCAST_PATH`。发布时需把 DMG 上传到 `SUFeedURL` 对应的下载站点,并发布更新后的 `appcast.xml`。+## Git 远端当前远端仓库:diff --git a/CodexBar.xcodeproj/project.pbxproj b/CodexBar.xcodeproj/project.pbxprojindex 3bb6c41..92ed637 100644--- a/CodexBar.xcodeproj/project.pbxproj+++ b/CodexBar.xcodeproj/project.pbxproj@@ -6,13 +6,30 @@objectVersion = 77;objects = {+/* Begin PBXBuildFile section */+ C42A52F12FDACDEC004A2B53 /* Sparkle in Frameworks */ = {isa = PBXBuildFile; productRef = C42A52F02FDACDEC004A2B53 /* Sparkle */; };+/* End PBXBuildFile section */+/* Begin PBXFileReference section */C4A0FD952FD9302E000263A7 /* CodexBar.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = CodexBar.app; sourceTree = BUILT_PRODUCTS_DIR; };/* End PBXFileReference section */+/* Begin PBXFileSystemSynchronizedBuildFileExceptionSet section */+ C42A52F22FDAD000004A2B53 /* Exceptions for "CodexBar" folder in "CodexBar" target */ = {+ isa = PBXFileSystemSynchronizedBuildFileExceptionSet;+ membershipExceptions = (+ Resources/Info.plist,+ );+ target = C4A0FD942FD9302E000263A7 /* CodexBar */;+ };+/* End PBXFileSystemSynchronizedBuildFileExceptionSet section */+/* Begin PBXFileSystemSynchronizedRootGroup section */C4A0FD972FD9302E000263A7 /* CodexBar */ = {isa = PBXFileSystemSynchronizedRootGroup;+ exceptions = (+ C42A52F22FDAD000004A2B53 /* Exceptions for "CodexBar" folder in "CodexBar" target */,+ );path = CodexBar;sourceTree = "<group>";};@@ -23,6 +40,7 @@isa = PBXFrameworksBuildPhase;buildActionMask = 2147483647;files = (+ C42A52F12FDACDEC004A2B53 /* Sparkle in Frameworks */,);runOnlyForDeploymentPostprocessing = 0;};@@ -65,6 +83,7 @@);name = CodexBar;packageProductDependencies = (+ C42A52F02FDACDEC004A2B53 /* Sparkle */,);productName = CodexBar;productReference = C4A0FD952FD9302E000263A7 /* CodexBar.app */;@@ -94,6 +113,9 @@);mainGroup = C4A0FD8C2FD9302E000263A7;minimizedProjectReferenceProxies = 1;+ packageReferences = (+ C42A52EF2FDACDEC004A2B53 /* XCRemoteSwiftPackageReference "Sparkle" */,+ );preferredProjectObjectVersion = 77;productRefGroup = C4A0FD962FD9302E000263A7 /* Products */;projectDirPath = "";@@ -255,15 +277,15 @@COMBINE_HIDPI_IMAGES = YES;CURRENT_PROJECT_VERSION = 1;DEVELOPMENT_TEAM = 4KJ362VJW5;+ ENABLE_APP_INTENTS_METADATA_GENERATION = NO;ENABLE_APP_SANDBOX = NO;ENABLE_HARDENED_RUNTIME = YES;ENABLE_PREVIEWS = YES;ENABLE_USER_SELECTED_FILES = NO;- GENERATE_INFOPLIST_FILE = YES;+ GENERATE_INFOPLIST_FILE = NO;+ INFOPLIST_FILE = CodexBar/Resources/Info.plist;INFOPLIST_KEY_CFBundleDisplayName = CodexBar;INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.developer-tools";- INFOPLIST_KEY_LSUIElement = YES;- INFOPLIST_KEY_NSHumanReadableCopyright = "Copyright © 2026 Bob. All rights reserved.";LD_RUNPATH_SEARCH_PATHS = ("$(inherited)","@executable_path/../Frameworks",@@ -292,15 +314,15 @@COMBINE_HIDPI_IMAGES = YES;CURRENT_PROJECT_VERSION = 1;DEVELOPMENT_TEAM = 4KJ362VJW5;+ ENABLE_APP_INTENTS_METADATA_GENERATION = NO;ENABLE_APP_SANDBOX = NO;ENABLE_HARDENED_RUNTIME = YES;ENABLE_PREVIEWS = YES;ENABLE_USER_SELECTED_FILES = NO;- GENERATE_INFOPLIST_FILE = YES;+ GENERATE_INFOPLIST_FILE = NO;+ INFOPLIST_FILE = CodexBar/Resources/Info.plist;INFOPLIST_KEY_CFBundleDisplayName = CodexBar;INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.developer-tools";- INFOPLIST_KEY_LSUIElement = YES;- INFOPLIST_KEY_NSHumanReadableCopyright = "Copyright © 2026 Bob. All rights reserved.";LD_RUNPATH_SEARCH_PATHS = ("$(inherited)","@executable_path/../Frameworks",@@ -341,6 +363,25 @@defaultConfigurationName = Release;};/* End XCConfigurationList section */++/* Begin XCRemoteSwiftPackageReference section */+ C42A52EF2FDACDEC004A2B53 /* XCRemoteSwiftPackageReference "Sparkle" */ = {+ isa = XCRemoteSwiftPackageReference;+ repositoryURL = "https://github.com/sparkle-project/Sparkle";+ requirement = {+ kind = upToNextMajorVersion;+ minimumVersion = 2.9.3;+ };+ };+/* End XCRemoteSwiftPackageReference section */++/* Begin XCSwiftPackageProductDependency section */+ C42A52F02FDACDEC004A2B53 /* Sparkle */ = {+ isa = XCSwiftPackageProductDependency;+ package = C42A52EF2FDACDEC004A2B53 /* XCRemoteSwiftPackageReference "Sparkle" */;+ productName = Sparkle;+ };+/* End XCSwiftPackageProductDependency section */};rootObject = C4A0FD8D2FD9302E000263A7 /* Project object */;}diff --git a/CodexBar/AppUpdater.swift b/CodexBar/AppUpdater.swiftnew file mode 100644index 0000000..eaef939--- /dev/null+++ b/CodexBar/AppUpdater.swift@@ -0,0 +1,77 @@+//+// AppUpdater.swift+// CodexBar+//+// Created by Bob on 2026-06-11.+//++import Combine+import Sparkle+import SwiftUI++@MainActor+final class AppUpdater: NSObject, ObservableObject {+ @Published private(set) var statusMessage: String?++ private var updaterController: SPUStandardUpdaterController?+ private var clearStatusMessageTask: Task<Void, Never>?++ init(bundle: Bundle = .main) {+ super.init()++ guard Self.hasUsableSparkleConfiguration(in: bundle) else {+ return+ }++ updaterController = SPUStandardUpdaterController(+ startingUpdater: true,+ updaterDelegate: self,+ userDriverDelegate: nil+ )+ }++ func checkForUpdates() {+ guard let updaterController else {+ showStatusMessage("未配置更新资源")+ return+ }++ showStatusMessage("正在检查更新")+ updaterController.checkForUpdates(nil)+ }++ private func showStatusMessage(_ message: String) {+ clearStatusMessageTask?.cancel()+ statusMessage = message++ clearStatusMessageTask = Task { [weak self] in+ try? await Task.sleep(for: .seconds(3))+ guard !Task.isCancelled else { return }+ self?.statusMessage = nil+ }+ }++ private static func hasUsableSparkleConfiguration(in bundle: Bundle) -> Bool {+ guard+ let feedURLString = bundle.object(forInfoDictionaryKey: "SUFeedURL") as? String,+ let feedURL = URL(string: feedURLString),+ ["https", "http"].contains(feedURL.scheme?.lowercased()),+ let publicKey = bundle.object(forInfoDictionaryKey: "SUPublicEDKey") as? String,+ !publicKey.isEmpty+ else {+ return false+ }++ return true+ }+}++extension AppUpdater: SPUUpdaterDelegate {+ func updater(_ updater: SPUUpdater, didFindValidUpdate item: SUAppcastItem) {+ showStatusMessage("发现新版本 v\(item.displayVersionString)")+ }++ func updaterDidNotFindUpdate(_ updater: SPUUpdater, error: Error) {+ showStatusMessage("已是最新版本")+ }+}diff --git a/CodexBar/CodexBarApp.swift b/CodexBar/CodexBarApp.swiftindex 82d0f8e..d7b2037 100644--- a/CodexBar/CodexBarApp.swift+++ b/CodexBar/CodexBarApp.swift@@ -10,11 +10,13 @@ import SwiftUI@mainstruct CodexBarApp: App {@StateObject private var viewModel = RateLimitsViewModel()+ @StateObject private var appUpdater = AppUpdater()var body: some Scene {MenuBarExtra {RateLimitsMenuView(viewModel: viewModel).frame(width: RateLimitsMenuView.menuWidth)+ .environmentObject(appUpdater)} label: {MenuBarStatusView(viewModel: viewModel)}diff --git a/CodexBar/RateLimitsMenuView.swift b/CodexBar/RateLimitsMenuView.swiftindex 80fcd51..f3e3c63 100644--- a/CodexBar/RateLimitsMenuView.swift+++ b/CodexBar/RateLimitsMenuView.swift@@ -12,6 +12,7 @@ struct RateLimitsMenuView: View {static let menuWidth: CGFloat = Metrics.padding * 2 + UsageHeatmap.Metrics.totalWidth@ObservedObject var viewModel: RateLimitsViewModel+ @EnvironmentObject private var appUpdater: AppUpdater@StateObject private var loginItemSettings = LoginItemSettings()@State private var showsControls = false@@ -154,6 +155,14 @@ private extension RateLimitsMenuView {.foregroundStyle(.secondary)Spacer()++ Text(appUpdater.statusMessage ?? Self.appVersionLabel)+ .font(.caption2.monospacedDigit())+ .foregroundStyle(.secondary)+ .lineLimit(1)+ .onTapGesture(count: 2) {+ appUpdater.checkForUpdates()+ }}}@@ -207,6 +216,12 @@ private extension RateLimitsMenuView {formatter.dateFormat = "HH:mm:ss"return formatter}()++ static let appVersionLabel: String = {+ let version = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String ?? "--"+ let build = Bundle.main.object(forInfoDictionaryKey: "CFBundleVersion") as? String ?? "-"+ return "App 版本: v\(version) (\(build))"+ }()}private struct UsageSummaryView: View {diff --git a/CodexBar/Assets.xcassets/AccentColor.colorset/Contents.json b/CodexBar/Resources/Assets.xcassets/AccentColor.colorset/Contents.jsonsimilarity index 100%rename from CodexBar/Assets.xcassets/AccentColor.colorset/Contents.jsonrename to CodexBar/Resources/Assets.xcassets/AccentColor.colorset/Contents.jsondiff --git a/CodexBar/Assets.xcassets/AppIcon.appiconset/Contents.json b/CodexBar/Resources/Assets.xcassets/AppIcon.appiconset/Contents.jsonsimilarity index 100%rename from CodexBar/Assets.xcassets/AppIcon.appiconset/Contents.jsonrename to CodexBar/Resources/Assets.xcassets/AppIcon.appiconset/Contents.jsondiff --git a/CodexBar/Assets.xcassets/AppIcon.appiconset/icon_128x128.png b/CodexBar/Resources/Assets.xcassets/AppIcon.appiconset/icon_128x128.pngsimilarity index 100%rename from CodexBar/Assets.xcassets/AppIcon.appiconset/icon_128x128.pngrename to CodexBar/Resources/Assets.xcassets/AppIcon.appiconset/icon_128x128.pngdiff --git a/CodexBar/Assets.xcassets/AppIcon.appiconset/[email protected] b/CodexBar/Resources/Assets.xcassets/AppIcon.appiconset/[email protected]similarity index 100%rename from CodexBar/Assets.xcassets/AppIcon.appiconset/[email protected]rename to CodexBar/Resources/Assets.xcassets/AppIcon.appiconset/[email protected]diff --git a/CodexBar/Assets.xcassets/AppIcon.appiconset/icon_16x16.png b/CodexBar/Resources/Assets.xcassets/AppIcon.appiconset/icon_16x16.pngsimilarity index 100%rename from CodexBar/Assets.xcassets/AppIcon.appiconset/icon_16x16.pngrename to CodexBar/Resources/Assets.xcassets/AppIcon.appiconset/icon_16x16.pngdiff --git a/CodexBar/Assets.xcassets/AppIcon.appiconset/[email protected] b/CodexBar/Resources/Assets.xcassets/AppIcon.appiconset/[email protected]similarity index 100%rename from CodexBar/Assets.xcassets/AppIcon.appiconset/[email protected]rename to CodexBar/Resources/Assets.xcassets/AppIcon.appiconset/[email protected]diff --git a/CodexBar/Assets.xcassets/AppIcon.appiconset/icon_256x256.png b/CodexBar/Resources/Assets.xcassets/AppIcon.appiconset/icon_256x256.pngsimilarity index 100%rename from CodexBar/Assets.xcassets/AppIcon.appiconset/icon_256x256.pngrename to CodexBar/Resources/Assets.xcassets/AppIcon.appiconset/icon_256x256.pngdiff --git a/CodexBar/Assets.xcassets/AppIcon.appiconset/[email protected] b/CodexBar/Resources/Assets.xcassets/AppIcon.appiconset/[email protected]similarity index 100%rename from CodexBar/Assets.xcassets/AppIcon.appiconset/[email protected]rename to CodexBar/Resources/Assets.xcassets/AppIcon.appiconset/[email protected]diff --git a/CodexBar/Assets.xcassets/AppIcon.appiconset/icon_32x32.png b/CodexBar/Resources/Assets.xcassets/AppIcon.appiconset/icon_32x32.pngsimilarity index 100%rename from CodexBar/Assets.xcassets/AppIcon.appiconset/icon_32x32.pngrename to CodexBar/Resources/Assets.xcassets/AppIcon.appiconset/icon_32x32.pngdiff --git a/CodexBar/Assets.xcassets/AppIcon.appiconset/[email protected] b/CodexBar/Resources/Assets.xcassets/AppIcon.appiconset/[email protected]similarity index 100%rename from CodexBar/Assets.xcassets/AppIcon.appiconset/[email protected]rename to CodexBar/Resources/Assets.xcassets/AppIcon.appiconset/[email protected]diff --git a/CodexBar/Assets.xcassets/AppIcon.appiconset/icon_512x512.png b/CodexBar/Resources/Assets.xcassets/AppIcon.appiconset/icon_512x512.pngsimilarity index 100%rename from CodexBar/Assets.xcassets/AppIcon.appiconset/icon_512x512.pngrename to CodexBar/Resources/Assets.xcassets/AppIcon.appiconset/icon_512x512.pngdiff --git a/CodexBar/Assets.xcassets/AppIcon.appiconset/[email protected] b/CodexBar/Resources/Assets.xcassets/AppIcon.appiconset/[email protected]similarity index 100%rename from CodexBar/Assets.xcassets/AppIcon.appiconset/[email protected]rename to CodexBar/Resources/Assets.xcassets/AppIcon.appiconset/[email protected]diff --git a/CodexBar/Assets.xcassets/Contents.json b/CodexBar/Resources/Assets.xcassets/Contents.jsonsimilarity index 100%rename from CodexBar/Assets.xcassets/Contents.jsonrename to CodexBar/Resources/Assets.xcassets/Contents.jsondiff --git a/CodexBar/Resources/Info.plist b/CodexBar/Resources/Info.plistnew file mode 100644index 0000000..435709d--- /dev/null+++ b/CodexBar/Resources/Info.plist@@ -0,0 +1,40 @@+<?xml version="1.0" encoding="UTF-8"?>+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">+<plist version="1.0">+ <dict>+ <key>CFBundleDevelopmentRegion</key>+ <string>$(DEVELOPMENT_LANGUAGE)</string>+ <key>CFBundleDisplayName</key>+ <string>CodexBar</string>+ <key>CFBundleExecutable</key>+ <string>$(EXECUTABLE_NAME)</string>+ <key>CFBundleIconName</key>+ <string>AppIcon</string>+ <key>CFBundleIdentifier</key>+ <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>+ <key>CFBundleInfoDictionaryVersion</key>+ <string>6.0</string>+ <key>CFBundleName</key>+ <string>$(PRODUCT_NAME)</string>+ <key>CFBundlePackageType</key>+ <string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>+ <key>CFBundleShortVersionString</key>+ <string>$(MARKETING_VERSION)</string>+ <key>CFBundleVersion</key>+ <string>$(CURRENT_PROJECT_VERSION)</string>+ <key>LSApplicationCategoryType</key>+ <string>public.app-category.developer-tools</string>+ <key>LSMinimumSystemVersion</key>+ <string>$(MACOSX_DEPLOYMENT_TARGET)</string>+ <key>LSUIElement</key>+ <true/>+ <key>NSHumanReadableCopyright</key>+ <string>Copyright © 2026 Bob. All rights reserved.</string>+ <key>SUFeedURL</key>+ <string>https://codexbar.zabrian.app/appcast.xml</string>+ <key>SUPublicEDKey</key>+ <string>+WFjXIWjnAjygvAeNTiaRslDT54EyyLT4F1yIihISSM=</string>+ <key>SUScheduledCheckInterval</key>+ <integer>3600</integer>+ </dict>+</plist>diff --git a/README.md b/README.mdindex e7a1a91..a0f66c5 100644--- a/README.md+++ b/README.md@@ -19,6 +19,8 @@ CodexBar 是一个轻量级 macOS 菜单栏应用,用来查看当前本机 Cod- 不按 Option/Alt 点击菜单栏图标时,只展示额度内容- 按住 Option/Alt 点击菜单栏图标时,才展示设置区;设置区为单行布局,左侧「开机自动启动」开关,右侧「退出」按钮- 未登录或认证失效时,弹窗顶部展示橙色提示,旧额度数据置灰保留展示+- 更新时间行右侧展示当前 App 版本,双击即可通过 Sparkle 检查更新+- 集成 Sparkle 自动更新,启动后会定期在后台静默检查新版本## 运行要求@@ -138,6 +140,29 @@ Scripts/create-dmg.sh CodexBar.app CodexBar-v1.0.0.dmg如果把应用移动到 `/Applications` 后再使用开机自启,建议打开应用后重新开启一次「开机启动」,让 macOS 记录最终的应用路径。+## 自动更新++CodexBar 内置 [Sparkle](https://sparkle-project.org) 自动更新。应用会按 Info.plist 中 `SUScheduledCheckInterval`(默认 1 小时)在后台静默检查,更新源为 `SUFeedURL` 指向的 appcast。弹窗更新时间行右侧也会显示当前版本,双击即可手动检查。++发布新版本时,打包 DMG 后用脚本更新 appcast:++```bash+Scripts/update-appcast.sh CodexBar-v1.2.0.dmg+```++脚本会用 Sparkle 的 `sign_update` 对 DMG 签名,从 Xcode build settings 读取版本号,生成条目并写入 `Updates/appcast.xml`(自动去重同版本旧条目,并用 `xmllint` 校验)。省略参数时会自动取项目根目录下唯一的 `.dmg`。常用环境变量:++- `DOWNLOAD_BASE_URL`:DMG 下载地址前缀+- `RELEASE_NOTES_BASE_URL` / `INCLUDE_RELEASE_NOTES`:发行说明链接前缀,置 `0` 可省略+- `MINIMUM_SYSTEM_VERSION`:最低系统版本(默认 15.0)+- `SIGN_UPDATE`:`sign_update` 工具路径(默认从 PATH 或 DerivedData 查找)++随后把 DMG 上传到下载站点,并发布更新后的 `appcast.xml`,客户端即可收到更新。+## 隐私CodexBar 只会和本机 Codex app-server 进程通信,不会把账号信息或额度数据发送给任何第三方服务。++## 友情链接++[感谢 Linux DO 社区的大力支持](https://linux.do)diff --git a/Scripts/create-dmg.sh b/Scripts/create-dmg.shindex 57c35c0..e73f922 100755--- a/Scripts/create-dmg.sh+++ b/Scripts/create-dmg.sh@@ -191,3 +191,4 @@ hdiutil convert \mv -f "${TEMP_OUTPUT_PATH}" "${OUTPUT_PATH}"echo "==> Created ${OUTPUT_PATH}"+echo "==> Update appcast with: Scripts/update-appcast.sh \"${OUTPUT_PATH}\""diff --git a/Scripts/update-appcast.sh b/Scripts/update-appcast.shnew file mode 100755index 0000000..560d957--- /dev/null+++ b/Scripts/update-appcast.sh@@ -0,0 +1,239 @@+#!/usr/bin/env bash+set -euo pipefail++SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"+PROJECT_DIR="$(cd "${SCRIPT_DIR}/.." && pwd)"++DMG_PATH="${1:-}"+APPCAST_PATH="${APPCAST_PATH:-${PROJECT_DIR}/Updates/appcast.xml}"+DOWNLOAD_BASE_URL="${DOWNLOAD_BASE_URL:-https://codexbar.zabrian.app/download}"+RELEASE_NOTES_BASE_URL="${RELEASE_NOTES_BASE_URL:-https://codexbar.zabrian.app/notes}"+MINIMUM_SYSTEM_VERSION="${MINIMUM_SYSTEM_VERSION:-15.0}"+INCLUDE_RELEASE_NOTES="${INCLUDE_RELEASE_NOTES:-1}"+SIGN_UPDATE="${SIGN_UPDATE:-}"+XCODE_PROJECT="${XCODE_PROJECT:-}"+XCODE_SCHEME="${XCODE_SCHEME:-CodexBar}"++usage() {+ cat >&2 <<USAGE+usage: Scripts/update-appcast.sh [CodexBar-vX.Y.Z.dmg]++Environment:+ APPCAST_PATH Path to appcast.xml. Defaults to Updates/appcast.xml.+ DOWNLOAD_BASE_URL Base URL for DMG downloads.+ Defaults to https://codexbar.zabrian.app/download.+ RELEASE_NOTES_BASE_URL Base URL for release notes.+ Defaults to https://codexbar.zabrian.app/notes.+ INCLUDE_RELEASE_NOTES Set to 0 to omit sparkle:releaseNotesLink.+ MINIMUM_SYSTEM_VERSION Defaults to 15.0.+ SIGN_UPDATE Optional path to Sparkle's sign_update tool.+ XCODE_PROJECT Optional .xcodeproj path.+ XCODE_SCHEME Defaults to CodexBar.+USAGE+}++require_command() {+ if ! command -v "$1" >/dev/null 2>&1; then+ echo "error: missing command: $1" >&2+ exit 1+ fi+}++xml_escape() {+ sed \+ -e 's/&/\&/g' \+ -e 's/</\</g' \+ -e 's/>/\>/g' \+ -e 's/"/\"/g'+}++read_build_setting() {+ local name="$1"+ printf '%s\n' "${BUILD_SETTINGS}" \+ | awk -F= -v key="${name}" '+ $1 ~ key {+ value = $2+ gsub(/^[[:space:]]+|[[:space:]]+$/, "", value)+ print value+ exit+ }+ '+}++if [[ "${DMG_PATH}" == "-h" || "${DMG_PATH}" == "--help" ]]; then+ usage+ exit 0+fi++if [[ -z "${DMG_PATH}" ]]; then+ dmgs=()+ while IFS= read -r dmg; do+ dmgs+=("${dmg}")+ done < <(find "${PROJECT_DIR}" -maxdepth 1 -type f -name "*.dmg" | sort)++ if [[ "${#dmgs[@]}" -eq 0 ]]; then+ echo "error: no DMG found in project root" >&2+ usage+ exit 1+ fi++ if [[ "${#dmgs[@]}" -gt 1 ]]; then+ echo "error: multiple DMGs found; specify one explicitly:" >&2+ printf ' %s\n' "${dmgs[@]}" >&2+ exit 1+ fi++ DMG_PATH="${dmgs[0]}"+elif [[ "${DMG_PATH}" != /* ]]; then+ DMG_PATH="${PROJECT_DIR}/${DMG_PATH}"+fi++if [[ ! -f "${DMG_PATH}" || "${DMG_PATH}" != *.dmg ]]; then+ echo "error: invalid DMG path: ${DMG_PATH}" >&2+ exit 1+fi++if [[ "${APPCAST_PATH}" != /* ]]; then+ APPCAST_PATH="${PROJECT_DIR}/${APPCAST_PATH}"+fi++if [[ ! -f "${APPCAST_PATH}" ]]; then+ echo "error: appcast not found: ${APPCAST_PATH}" >&2+ exit 1+fi++if [[ -z "${XCODE_PROJECT}" ]]; then+ projects=()+ while IFS= read -r project; do+ projects+=("${project}")+ done < <(find "${PROJECT_DIR}" -maxdepth 1 -type d -name "*.xcodeproj" | sort)++ if [[ "${#projects[@]}" -eq 0 ]]; then+ echo "error: no .xcodeproj found in project root" >&2+ exit 1+ fi++ if [[ "${#projects[@]}" -gt 1 ]]; then+ echo "error: multiple .xcodeproj files found; set XCODE_PROJECT" >&2+ printf ' %s\n' "${projects[@]}" >&2+ exit 1+ fi++ XCODE_PROJECT="${projects[0]}"+elif [[ "${XCODE_PROJECT}" != /* ]]; then+ XCODE_PROJECT="${PROJECT_DIR}/${XCODE_PROJECT}"+fi++require_command xcodebuild+require_command perl+require_command stat++BUILD_SETTINGS="$(+ xcodebuild \+ -project "${XCODE_PROJECT}" \+ -scheme "${XCODE_SCHEME}" \+ -configuration Release \+ -showBuildSettings 2>/dev/null+)"++SHORT_VERSION="$(read_build_setting MARKETING_VERSION)"+BUILD_VERSION="$(read_build_setting CURRENT_PROJECT_VERSION)"+PRODUCT_NAME="$(read_build_setting PRODUCT_NAME)"++if [[ -z "${SHORT_VERSION}" || -z "${BUILD_VERSION}" ]]; then+ echo "error: unable to read MARKETING_VERSION or CURRENT_PROJECT_VERSION" >&2+ exit 1+fi++if [[ -z "${PRODUCT_NAME}" || "${PRODUCT_NAME}" == '$(TARGET_NAME)' ]]; then+ PRODUCT_NAME="$(basename "${DMG_PATH}")"+ PRODUCT_NAME="${PRODUCT_NAME%%-v*}"+ PRODUCT_NAME="${PRODUCT_NAME%.dmg}"+fi++if [[ -z "${SIGN_UPDATE}" ]]; then+ if command -v sign_update >/dev/null 2>&1; then+ SIGN_UPDATE="$(command -v sign_update)"+ else+ SIGN_UPDATE="$(+ find "${HOME}/Library/Developer/Xcode/DerivedData" \+ -path "*Sparkle*/bin/sign_update" \+ -type f \+ 2>/dev/null \+ | sort \+ | tail -n 1+ )"+ fi+fi++if [[ -z "${SIGN_UPDATE}" || ! -x "${SIGN_UPDATE}" ]]; then+ echo "error: Sparkle sign_update not found; set SIGN_UPDATE=/path/to/sign_update" >&2+ exit 1+fi++echo "==> Signing update archive"+SIGN_OUTPUT="$("${SIGN_UPDATE}" "${DMG_PATH}")"+ED_SIGNATURE="$(+ printf '%s\n' "${SIGN_OUTPUT}" \+ | sed -n 's/.*sparkle:edSignature="\([^"]*\)".*/\1/p' \+ | head -n 1+)"+ARCHIVE_LENGTH="$(+ printf '%s\n' "${SIGN_OUTPUT}" \+ | sed -n 's/.*length="\([^"]*\)".*/\1/p' \+ | head -n 1+)"++if [[ -z "${ED_SIGNATURE}" ]]; then+ echo "error: unable to parse sparkle:edSignature from sign_update output" >&2+ printf '%s\n' "${SIGN_OUTPUT}" >&2+ exit 1+fi++if [[ -z "${ARCHIVE_LENGTH}" ]]; then+ ARCHIVE_LENGTH="$(stat -f%z "${DMG_PATH}")"+fi++DOWNLOAD_URL="${DOWNLOAD_BASE_URL%/}/$(basename "${DMG_PATH}")"+PUB_DATE="$(LC_ALL=C TZ=Asia/Shanghai date '+%a, %d %b %Y %H:%M:%S %z')"+TITLE="$(printf '%s %s' "${PRODUCT_NAME}" "${SHORT_VERSION}" | xml_escape)"+DOWNLOAD_URL_ESCAPED="$(printf '%s' "${DOWNLOAD_URL}" | xml_escape)"+ED_SIGNATURE_ESCAPED="$(printf '%s' "${ED_SIGNATURE}" | xml_escape)"+MIN_SYSTEM_ESCAPED="$(printf '%s' "${MINIMUM_SYSTEM_VERSION}" | xml_escape)"++RELEASE_NOTES_XML=""+if [[ "${INCLUDE_RELEASE_NOTES}" != "0" ]]; then+ RELEASE_NOTES_URL="${RELEASE_NOTES_BASE_URL%/}/${SHORT_VERSION}.html"+ RELEASE_NOTES_URL_ESCAPED="$(printf '%s' "${RELEASE_NOTES_URL}" | xml_escape)"+ RELEASE_NOTES_XML="<sparkle:releaseNotesLink>${RELEASE_NOTES_URL_ESCAPED}</sparkle:releaseNotesLink>+"+fi++APPCAST_ITEM=" <item>+ <title>${TITLE}</title>+ <sparkle:version>${BUILD_VERSION}</sparkle:version>+ <sparkle:shortVersionString>${SHORT_VERSION}</sparkle:shortVersionString>+ <sparkle:minimumSystemVersion>${MIN_SYSTEM_ESCAPED}</sparkle:minimumSystemVersion>+ ${RELEASE_NOTES_XML} <pubDate>${PUB_DATE}</pubDate>+ <enclosure url=\"${DOWNLOAD_URL_ESCAPED}\" sparkle:edSignature=\"${ED_SIGNATURE_ESCAPED}\" length=\"${ARCHIVE_LENGTH}\" type=\"application/octet-stream\"/>+ </item>"++echo "==> Updating appcast"+APPCAST_ITEM="${APPCAST_ITEM}" APPCAST_VERSION="${BUILD_VERSION}" perl -0pi -e '+ my $item = $ENV{"APPCAST_ITEM"};+ my $version = $ENV{"APPCAST_VERSION"};++ s/\n\s*<item>\s*.*?<sparkle:version>\Q$version\E<\/sparkle:version>.*?<\/item>//sg;++ if (!s/(<language>.*?<\/language>)/$1\n$item/s) {+ die "Unable to find <language>...</language> insertion point\n";+ }+' "${APPCAST_PATH}"++if command -v xmllint >/dev/null 2>&1; then+ xmllint --noout "${APPCAST_PATH}"+fi++echo "==> Added ${PRODUCT_NAME} ${SHORT_VERSION} (${BUILD_VERSION})"+echo " ${APPCAST_PATH}"+echo " ${DOWNLOAD_URL}"diff --git a/Updates/appcast.xml b/Updates/appcast.xmlnew file mode 100644index 0000000..f1dce61--- /dev/null+++ b/Updates/appcast.xml@@ -0,0 +1,20 @@+<?xml version="1.0" encoding="utf-8"?>+<rss version="2.0"+ xmlns:sparkle="http://www.andymatuschak.org/xml-namespaces/sparkle"+ xmlns:dc="http://purl.org/dc/elements/1.1/">+ <channel>+ <title>CodexBar Updates</title>+ <link>https://codexbar.zabrian.app/appcast.xml</link>+ <description>CodexBar appcast feed</description>+ <language>zh-CN</language>+ <item>+ <title>CodexBar.app 1.2.0</title>+ <sparkle:version>1</sparkle:version>+ <sparkle:shortVersionString>1.2.0</sparkle:shortVersionString>+ <sparkle:minimumSystemVersion>15.0</sparkle:minimumSystemVersion>+ <sparkle:releaseNotesLink>https://codexbar.zabrian.app/notes/1.2.0.html</sparkle:releaseNotesLink>+ <pubDate>Thu, 11 Jun 2026 21:19:36 +0800</pubDate>+ <enclosure url="https://codexbar.zabrian.app/download/CodexBar-v1.2.0.dmg" sparkle:edSignature="uwe29fAr5NHr+Id4H0cEMqVDmFxWZb/R+GE0yxvbqKDet+NvY6tlWphl9GxbEW8FwVow5B9BF0nsg1PSJ7NIDQ==" length="1323252" type="application/octet-stream"/>+ </item>+ </channel>+</rss>