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
3 changes: 3 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ let package = Package(
.product(name: "Logging", package: "swift-log"),
.product(name: "SweetCookieKit", package: "SweetCookieKit"),
],
resources: [
.process("Resources"),
],
swiftSettings: [
.enableUpcomingFeature("StrictConcurrency"),
]),
Expand Down
9 changes: 5 additions & 4 deletions Sources/CodexBar/About.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import AppKit
import CodexBarCore

@MainActor
func showAbout() {
Expand All @@ -21,16 +22,16 @@ func showAbout() {
])
}

let credits = NSMutableAttributedString(string: "Peter Steinberger — MIT License\n")
let credits = NSMutableAttributedString(string: L10n.tr("about.credits", default: "Peter Steinberger — MIT License\n"))
credits.append(makeLink("GitHub", urlString: "https://github.com/steipete/CodexBar"))
credits.append(separator)
credits.append(makeLink("Website", urlString: "https://codexbar.app"))
credits.append(makeLink(L10n.tr("common.website", default: "Website"), urlString: "https://codexbar.app"))
credits.append(separator)
credits.append(makeLink("Twitter", urlString: "https://twitter.com/steipete"))
credits.append(separator)
credits.append(makeLink("Email", urlString: "mailto:peter@steipete.me"))
credits.append(makeLink(L10n.tr("common.email", default: "Email"), urlString: "mailto:peter@steipete.me"))
if let buildTimestamp, let formatted = formattedBuildTimestamp(buildTimestamp) {
var builtLine = "Built \(formatted)"
var builtLine = L10n.tr("about.built", default: "Built %@", formatted)
if let gitCommit, !gitCommit.isEmpty, gitCommit != "unknown" {
builtLine += " (\(gitCommit)"
#if DEBUG
Expand Down
4 changes: 2 additions & 2 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("chart.costHistory.empty", default: "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.tr("chart.costHistory.total30Days", default: "Total (30d): %@", UsageFormatter.usdString(total)))
.font(.caption)
.foregroundStyle(.secondary)
}
Expand Down
7 changes: 5 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("chart.creditsHistory.empty", default: "No credits history data."))
.font(.footnote)
.foregroundStyle(.secondary)
} else {
Expand Down Expand Up @@ -98,7 +98,10 @@ struct CreditsHistoryChartMenuView: View {
}

if let total = model.totalCreditsUsed {
Text("Total (30d): \(total.formatted(.number.precision(.fractionLength(0...2)))) credits")
Text(L10n.tr(
"chart.creditsHistory.total30Days",
default: "Total (30d): %@ credits",
total.formatted(.number.precision(.fractionLength(0...2)))))
.font(.caption)
.foregroundStyle(.secondary)
}
Expand Down
7 changes: 4 additions & 3 deletions Sources/CodexBar/CursorLoginRunner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ final class CursorLoginRunner: NSObject {
backing: .buffered,
defer: false)
window.isReleasedWhenClosed = false
window.title = "Cursor Login"
window.title = L10n.tr("login.cursor.windowTitle", default: "Cursor Login")
window.contentView = webView
window.center()
window.delegate = self
Expand Down Expand Up @@ -110,9 +110,10 @@ final class CursorLoginRunner: NSObject {
}

guard !cursorCookies.isEmpty else {
self.phaseCallback?(.failed("No session cookies found"))
let message = L10n.tr("login.cursor.noSessionCookies", default: "No session cookies found")
self.phaseCallback?(.failed(message))
self.logger.warning("Cursor login failed: no session cookies found")
self.complete(with: Result(outcome: .failed("No session cookies found"), email: nil))
self.complete(with: Result(outcome: .failed(message), email: nil))
return
}

Expand Down
3 changes: 2 additions & 1 deletion Sources/CodexBar/Date+RelativeDescription.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import CodexBarCore
import Foundation

enum RelativeTimeFormatters {
Expand All @@ -14,7 +15,7 @@ extension Date {
func relativeDescription(now: Date = .now) -> String {
let seconds = abs(now.timeIntervalSince(self))
if seconds < 15 {
return "just now"
return L10n.tr("relative.justNow", default: "just now")
}
return RelativeTimeFormatters.full.localizedString(for: self, relativeTo: now)
}
Expand Down
122 changes: 54 additions & 68 deletions Sources/CodexBar/KeychainPromptCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,94 +22,80 @@ 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: " ")
let title = L10n.tr("keychain.title", default: "Keychain Access Required")
let message = L10n.tr(
"keychain.browserCookie.message",
default: "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"
switch context.kind {
let title = L10n.tr("keychain.title", default: "Keychain Access Required")
let message: String = 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: " "))
L10n.tr(
"keychain.claudeOAuth.message",
default: "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: " "))
L10n.tr(
"keychain.codexCookie.message",
default: "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: " "))
L10n.tr(
"keychain.claudeCookie.message",
default: "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: " "))
L10n.tr(
"keychain.cursorCookie.message",
default: "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: " "))
L10n.tr(
"keychain.opencodeCookie.message",
default: "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: " "))
L10n.tr(
"keychain.factoryCookie.message",
default: "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: " "))
L10n.tr(
"keychain.zaiToken.message",
default: "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: " "))
L10n.tr(
"keychain.syntheticToken.message",
default: "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: " "))
L10n.tr(
"keychain.copilotToken.message",
default: "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: " "))
L10n.tr(
"keychain.kimiToken.message",
default: "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: " "))
L10n.tr(
"keychain.kimik2Token.message",
default: "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: " "))
L10n.tr(
"keychain.minimaxCookie.message",
default: "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: " "))
L10n.tr(
"keychain.minimaxToken.message",
default: "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: " "))
L10n.tr(
"keychain.augmentCookie.message",
default: "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: " "))
L10n.tr(
"keychain.ampCookie.message",
default: "CodexBar will ask macOS Keychain for your Amp cookie header so it can fetch usage. Click OK to continue.")
}
return (title, message)
}

private static func presentAlert(title: String, message: String) {
Expand All @@ -134,7 +120,7 @@ enum KeychainPromptCoordinator {
let alert = NSAlert()
alert.messageText = title
alert.informativeText = message
alert.addButton(withTitle: "OK")
alert.addButton(withTitle: L10n.tr("common.ok", default: "OK"))
_ = alert.runModal()
}
}
Loading