Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,9 @@
- Keep provider data siloed: when rendering usage or account info for a provider (Claude vs Codex), never display identity/plan fields sourced from a different provider.***
- Claude CLI status line is custom + user-configurable; never rely on it for usage parsing.
- Cookie imports: default Chrome-only when possible to avoid other browser prompts; override via browser list when needed.
- Signing identities: verify with `security find-identity -v -p codesigning` (prefer running with elevated permissions if sandboxed). A CA certificate alone (e.g., `Developer ID Certification Authority`) is not a signing identity.
- Preferred local signing: use available `Apple Development` identity (for this machine: `Apple Development: shawnrain@foxmail.com (ZQG28N5AK8)`) unless a valid `Developer ID Application` identity is installed.
- `Scripts/package_app.sh` uses `--timestamp` when signing with identity; if timestamp service is unavailable, build release with `CODEXBAR_SIGNING=adhoc ./Scripts/package_app.sh release` and then re-sign the app without timestamp:
`codesign --force --deep --options runtime --sign 'Apple Development: shawnrain@foxmail.com (ZQG28N5AK8)' /Users/shawnrain/CodexBar/CodexBar.app`
- Install to system Applications with:
`ditto /Users/shawnrain/CodexBar/CodexBar.app /Applications/CodexBar.app`
1 change: 1 addition & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ let sweetCookieKitDependency: Package.Dependency =

let package = Package(
name: "CodexBar",
defaultLocalization: "en",
platforms: [
.macOS(.v14),
],
Expand Down
1 change: 1 addition & 0 deletions Scripts/compile_and_run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ resolve_signing_mode() {

local candidate=""
for candidate in \
"Apple Development: shawnrain@foxmail.com (ZQG28N5AK8)" \
"Developer ID Application: Peter Steinberger (Y5PE65HELJ)" \
"CodexBar Development"
do
Expand Down
29 changes: 29 additions & 0 deletions Scripts/package_with_my_sign.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env bash
set -euo pipefail

ROOT=$(cd "$(dirname "$0")/.." && pwd)
cd "$ROOT"

CONF=${1:-release}

# Allow explicit override:
# APP_IDENTITY="Apple Development: Name (TEAMID)" ./Scripts/package_with_my_sign.sh
if [[ -z "${APP_IDENTITY:-}" ]]; then
APP_IDENTITY=$(security find-identity -v -p codesigning \
| awk -F'"' '/Apple Development:/{print $2; exit}')
fi

if [[ -z "${APP_IDENTITY:-}" ]]; then
echo "ERROR: No Apple Development signing identity found." >&2
echo "Run: security find-identity -v -p codesigning" >&2
exit 1
fi

echo "Using signing identity: ${APP_IDENTITY}"
APP_IDENTITY="${APP_IDENTITY}" ./Scripts/package_app.sh "${CONF}"

echo ""
echo "Packaged app: ${ROOT}/CodexBar.app"
echo "Recommended verification:"
echo " spctl -a -t exec -vv ${ROOT}/CodexBar.app"
echo " codesign --verify --deep --strict --verbose ${ROOT}/CodexBar.app"
12 changes: 6 additions & 6 deletions Sources/CodexBar/CostHistoryChartMenuView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ struct CostHistoryChartMenuView: View {
let model = Self.makeModel(provider: self.provider, daily: self.daily)
VStack(alignment: .leading, spacing: 10) {
if model.points.isEmpty {
Text("No cost history data.")
Text(L10n.tr("No cost history data."))
.font(.footnote)
.foregroundStyle(.secondary)
} else {
Expand Down Expand Up @@ -107,7 +107,7 @@ struct CostHistoryChartMenuView: View {
}

if let total = self.totalCostUSD {
Text("Total (30d): \(UsageFormatter.usdString(total))")
Text(L10n.format("Total (30d): %@", UsageFormatter.usdString(total)))
.font(.caption)
.foregroundStyle(.secondary)
}
Expand Down Expand Up @@ -291,17 +291,17 @@ struct CostHistoryChartMenuView: View {
let point = model.pointsByDateKey[key],
let date = Self.dateFromDayKey(key)
else {
return ("Hover a bar for details", nil)
return (L10n.tr("Hover a bar for details"), nil)
}

let dayLabel = date.formatted(.dateTime.month(.abbreviated).day())
let cost = UsageFormatter.usdString(point.costUSD)
if let tokens = point.totalTokens {
let primary = "\(dayLabel): \(cost) · \(UsageFormatter.tokenCountString(tokens)) tokens"
let primary = L10n.format("%@: %@ · %@ tokens", dayLabel, cost, UsageFormatter.tokenCountString(tokens))
let secondary = self.topModelsText(key: key, model: model)
return (primary, secondary)
}
let primary = "\(dayLabel): \(cost)"
let primary = L10n.format("%@: %@", dayLabel, cost)
let secondary = self.topModelsText(key: key, model: model)
return (primary, secondary)
}
Expand All @@ -321,6 +321,6 @@ struct CostHistoryChartMenuView: View {
.prefix(3)
.map { "\($0.name) \(UsageFormatter.usdString($0.costUSD))" }
guard !parts.isEmpty else { return nil }
return "Top: \(parts.joined(separator: " · "))"
return L10n.format("Top: %@", parts.joined(separator: " · "))
}
}
6 changes: 4 additions & 2 deletions Sources/CodexBar/CreditsHistoryChartMenuView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ struct CreditsHistoryChartMenuView: View {
let model = Self.makeModel(from: self.breakdown)
VStack(alignment: .leading, spacing: 10) {
if model.points.isEmpty {
Text("No credits history data.")
Text(L10n.tr("No credits history data."))
.font(.footnote)
.foregroundStyle(.secondary)
} else {
Expand Down Expand Up @@ -98,7 +98,9 @@ struct CreditsHistoryChartMenuView: View {
}

if let total = model.totalCreditsUsed {
Text("Total (30d): \(total.formatted(.number.precision(.fractionLength(0...2)))) credits")
Text(L10n.format(
"Total (30d): %@ credits",
total.formatted(.number.precision(.fractionLength(0...2)))))
.font(.caption)
.foregroundStyle(.secondary)
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/CodexBar/Date+RelativeDescription.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ extension Date {
func relativeDescription(now: Date = .now) -> String {
let seconds = abs(now.timeIntervalSince(self))
if seconds < 15 {
return "just now"
return L10n.tr("just now")
}
return RelativeTimeFormatters.full.localizedString(for: self, relativeTo: now)
}
Expand Down
153 changes: 85 additions & 68 deletions Sources/CodexBar/KeychainPromptCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,93 +22,110 @@ enum KeychainPromptCoordinator {
}

private static func presentBrowserCookiePrompt(_ context: BrowserCookieKeychainPromptContext) {
let title = "Keychain Access Required"
let message = [
"CodexBar will ask macOS Keychain for “\(context.label)” so it can decrypt browser cookies",
"and authenticate your account. Click OK to continue.",
].joined(separator: " ")
self.log.info("Browser cookie keychain prompt requested", metadata: ["label": context.label])
let title = L10n.tr("Keychain Access Required")
let message = L10n.format(
"CodexBar will ask macOS Keychain for \"%@\" so it can decrypt browser cookies " +
"and authenticate your account. Click OK to continue.",
context.label)
self.log.info(
"Browser cookie keychain prompt requested",
metadata: ["label": context.label])
self.presentAlert(title: title, message: message)
}

private static func keychainCopy(for context: KeychainPromptContext) -> (title: String, message: String) {
let title = "Keychain Access Required"
let title = L10n.tr("Keychain Access Required")
switch context.kind {
case .claudeOAuth:
return (title, [
"CodexBar will ask macOS Keychain for the Claude Code OAuth token",
"so it can fetch your Claude usage. Click OK to continue.",
].joined(separator: " "))
return (
title,
L10n.tr(
"CodexBar will ask macOS Keychain for the Claude Code OAuth token so it can " +
"fetch your Claude usage. Click OK to continue."))
case .codexCookie:
return (title, [
"CodexBar will ask macOS Keychain for your OpenAI cookie header",
"so it can fetch Codex dashboard extras. Click OK to continue.",
].joined(separator: " "))
return (
title,
L10n.tr(
"CodexBar will ask macOS Keychain for your OpenAI cookie header so it can " +
"fetch Codex dashboard extras. Click OK to continue."))
case .claudeCookie:
return (title, [
"CodexBar will ask macOS Keychain for your Claude cookie header",
"so it can fetch Claude web usage. Click OK to continue.",
].joined(separator: " "))
return (
title,
L10n.tr(
"CodexBar will ask macOS Keychain for your Claude cookie header so it can " +
"fetch Claude web usage. Click OK to continue."))
case .cursorCookie:
return (title, [
"CodexBar will ask macOS Keychain for your Cursor cookie header",
"so it can fetch usage. Click OK to continue.",
].joined(separator: " "))
return (
title,
L10n.tr(
"CodexBar will ask macOS Keychain for your Cursor cookie header so it can " +
"fetch usage. Click OK to continue."))
case .opencodeCookie:
return (title, [
"CodexBar will ask macOS Keychain for your OpenCode cookie header",
"so it can fetch usage. Click OK to continue.",
].joined(separator: " "))
return (
title,
L10n.tr(
"CodexBar will ask macOS Keychain for your OpenCode cookie header so it can " +
"fetch usage. Click OK to continue."))
case .factoryCookie:
return (title, [
"CodexBar will ask macOS Keychain for your Factory cookie header",
"so it can fetch usage. Click OK to continue.",
].joined(separator: " "))
return (
title,
L10n.tr(
"CodexBar will ask macOS Keychain for your Factory cookie header so it can " +
"fetch usage. Click OK to continue."))
case .zaiToken:
return (title, [
"CodexBar will ask macOS Keychain for your z.ai API token",
"so it can fetch usage. Click OK to continue.",
].joined(separator: " "))
return (
title,
L10n.tr(
"CodexBar will ask macOS Keychain for your z.ai API token so it can fetch " +
"usage. Click OK to continue."))
case .syntheticToken:
return (title, [
"CodexBar will ask macOS Keychain for your Synthetic API key",
"so it can fetch usage. Click OK to continue.",
].joined(separator: " "))
return (
title,
L10n.tr(
"CodexBar will ask macOS Keychain for your Synthetic API key so it can fetch " +
"usage. Click OK to continue."))
case .copilotToken:
return (title, [
"CodexBar will ask macOS Keychain for your GitHub Copilot token",
"so it can fetch usage. Click OK to continue.",
].joined(separator: " "))
return (
title,
L10n.tr(
"CodexBar will ask macOS Keychain for your GitHub Copilot token so it can " +
"fetch usage. Click OK to continue."))
case .kimiToken:
return (title, [
"CodexBar will ask macOS Keychain for your Kimi auth token",
"so it can fetch usage. Click OK to continue.",
].joined(separator: " "))
return (
title,
L10n.tr(
"CodexBar will ask macOS Keychain for your Kimi auth token so it can fetch " +
"usage. Click OK to continue."))
case .kimiK2Token:
return (title, [
"CodexBar will ask macOS Keychain for your Kimi K2 API key",
"so it can fetch usage. Click OK to continue.",
].joined(separator: " "))
return (
title,
L10n.tr(
"CodexBar will ask macOS Keychain for your Kimi K2 API key so it can fetch " +
"usage. Click OK to continue."))
case .minimaxCookie:
return (title, [
"CodexBar will ask macOS Keychain for your MiniMax cookie header",
"so it can fetch usage. Click OK to continue.",
].joined(separator: " "))
return (
title,
L10n.tr(
"CodexBar will ask macOS Keychain for your MiniMax cookie header so it can " +
"fetch usage. Click OK to continue."))
case .minimaxToken:
return (title, [
"CodexBar will ask macOS Keychain for your MiniMax API token",
"so it can fetch usage. Click OK to continue.",
].joined(separator: " "))
return (
title,
L10n.tr(
"CodexBar will ask macOS Keychain for your MiniMax API token so it can fetch " +
"usage. Click OK to continue."))
case .augmentCookie:
return (title, [
"CodexBar will ask macOS Keychain for your Augment cookie header",
"so it can fetch usage. Click OK to continue.",
].joined(separator: " "))
return (
title,
L10n.tr(
"CodexBar will ask macOS Keychain for your Augment cookie header so it can " +
"fetch usage. Click OK to continue."))
case .ampCookie:
return (title, [
"CodexBar will ask macOS Keychain for your Amp cookie header",
"so it can fetch usage. Click OK to continue.",
].joined(separator: " "))
return (
title,
L10n.tr(
"CodexBar will ask macOS Keychain for your Amp cookie header so it can fetch " +
"usage. Click OK to continue."))
}
}

Expand All @@ -134,7 +151,7 @@ enum KeychainPromptCoordinator {
let alert = NSAlert()
alert.messageText = title
alert.informativeText = message
alert.addButton(withTitle: "OK")
alert.addButton(withTitle: L10n.tr("OK"))
_ = alert.runModal()
}
}
26 changes: 26 additions & 0 deletions Sources/CodexBar/Localization.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import Foundation

enum L10n {
static func tr(_ key: String) -> String {
NSLocalizedString(key, bundle: .module, comment: "")
}

static func format(_ key: String, _ arguments: CVarArg...) -> String {
let format = Self.tr(key)
return String(format: format, locale: .current, arguments: arguments)
}

static func localizedDynamicValue(_ raw: String) -> String {
let trimmed = raw.trimmingCharacters(in: .whitespacesAndNewlines)
guard !trimmed.isEmpty else { return trimmed }

let normalized = trimmed.lowercased()
let localizedNormalized = Self.tr(normalized)
if localizedNormalized != normalized {
return localizedNormalized
}

let localizedExact = Self.tr(trimmed)
return localizedExact == trimmed ? trimmed : localizedExact
}
}
12 changes: 6 additions & 6 deletions Sources/CodexBar/MenuBarDisplayMode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ enum MenuBarDisplayMode: String, CaseIterable, Identifiable {

var label: String {
switch self {
case .percent: "Percent"
case .pace: "Pace"
case .both: "Both"
case .percent: L10n.tr("Percent")
case .pace: L10n.tr("Pace")
case .both: L10n.tr("Both")
}
}

var description: String {
switch self {
case .percent: "Show remaining/used percentage (e.g. 45%)"
case .pace: "Show pace indicator (e.g. +5%)"
case .both: "Show both percentage and pace (e.g. 45% · +5%)"
case .percent: L10n.tr("Show remaining/used percentage (e.g. 45%)")
case .pace: L10n.tr("Show pace indicator (e.g. +5%)")
case .both: L10n.tr("Show both percentage and pace (e.g. 45% · +5%)")
}
}
}
2 changes: 1 addition & 1 deletion Sources/CodexBar/MenuBarDisplayText.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ enum MenuBarDisplayText {
return self.paceText(provider: provider, window: paceWindow, now: now)
case .both:
guard let percent = percentText(window: percentWindow, showUsed: showUsed) else { return nil }
guard let pace = Self.paceText(provider: provider, window: paceWindow, now: now) else { return nil }
guard let pace = Self.paceText(provider: provider, window: paceWindow, now: now) else { return percent }
return "\(percent) · \(pace)"
}
}
Expand Down
Loading