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
4 changes: 4 additions & 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 All @@ -33,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
5 changes: 3 additions & 2 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,7 +22,7 @@ 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"))
Expand All @@ -30,7 +31,7 @@ func showAbout() {
credits.append(separator)
credits.append(makeLink("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
92 changes: 24 additions & 68 deletions Sources/CodexBar/KeychainPromptCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,94 +22,50 @@ 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 +90,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()
}
}
34 changes: 17 additions & 17 deletions Sources/CodexBar/MenuDescriptor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ struct MenuDescriptor {
sections.append(accountSection)
}
} else {
sections.append(Section(entries: [.text("No usage configured.", .secondary)]))
sections.append(Section(entries: [ .text(L10n.tr("menu.noUsageConfigured", default: "No usage configured."), .secondary)]))
}
}

Expand Down Expand Up @@ -174,7 +174,7 @@ struct MenuDescriptor {
if meta.supportsOpus, let opus = snap.tertiary {
Self.appendRateWindow(
entries: &entries,
title: meta.opusLabel ?? "Sonnet",
title: meta.opusLabel ?? L10n.tr("provider.label.sonnet", default: "Sonnet"),
window: opus,
resetStyle: resetStyle,
showUsed: settings.usageBarsShowUsed)
Expand All @@ -184,11 +184,11 @@ struct MenuDescriptor {
if cost.currencyCode == "Quota" {
let used = String(format: "%.0f", cost.used)
let limit = String(format: "%.0f", cost.limit)
entries.append(.text("Quota: \(used) / \(limit)", .primary))
entries.append(.text(L10n.tr("menu.quota", default: "Quota: %@ / %@", used, limit), .primary))
}
}
} else {
entries.append(.text("No usage yet", .secondary))
entries.append(.text(L10n.tr("menu.noUsageYet", default: "No usage yet"), .secondary))
}

let usageContext = ProviderMenuUsageContext(
Expand Down Expand Up @@ -236,27 +236,27 @@ struct MenuDescriptor {
let redactedEmail = PersonalInfoRedactor.redactEmail(emailText, isEnabled: hidePersonalInfo)

if let emailText, !emailText.isEmpty {
entries.append(.text("Account: \(redactedEmail)", .secondary))
entries.append(.text(L10n.tr("menu.account", default: "Account: %@", redactedEmail), .secondary))
}
if provider == .kilo {
let kiloLogin = self.kiloLoginParts(loginMethod: loginMethodText)
if let pass = kiloLogin.pass {
entries.append(.text("Plan: \(AccountFormatter.plan(pass))", .secondary))
entries.append(.text(L10n.tr("menu.plan", default: "Plan: %@", AccountFormatter.plan(pass)), .secondary))
}
for detail in kiloLogin.details {
entries.append(.text("Activity: \(detail)", .secondary))
entries.append(.text(L10n.tr("menu.activity", default: "Activity: %@", detail), .secondary))
}
} else if let loginMethodText, !loginMethodText.isEmpty {
entries.append(.text("Plan: \(AccountFormatter.plan(loginMethodText))", .secondary))
entries.append(.text(L10n.tr("menu.plan", default: "Plan: %@", AccountFormatter.plan(loginMethodText)), .secondary))
}

if metadata.usesAccountFallback {
if emailText?.isEmpty ?? true, let fallbackEmail = fallback.email, !fallbackEmail.isEmpty {
let redacted = PersonalInfoRedactor.redactEmail(fallbackEmail, isEnabled: hidePersonalInfo)
entries.append(.text("Account: \(redacted)", .secondary))
entries.append(.text(L10n.tr("menu.account", default: "Account: %@", redacted), .secondary))
}
if loginMethodText?.isEmpty ?? true, let fallbackPlan = fallback.plan, !fallbackPlan.isEmpty {
entries.append(.text("Plan: \(AccountFormatter.plan(fallbackPlan))", .secondary))
entries.append(.text(L10n.tr("menu.plan", default: "Plan: %@", AccountFormatter.plan(fallbackPlan)), .secondary))
}
}

Expand Down Expand Up @@ -327,7 +327,7 @@ struct MenuDescriptor {
} else {
let loginAction = self.switchAccountTarget(for: provider, store: store)
let hasAccount = self.hasAccount(for: provider, store: store, account: account)
let accountLabel = hasAccount ? "Switch Account..." : "Add Account..."
let accountLabel = hasAccount ? L10n.tr("menu.switchAccount", default: "Switch Account...") : L10n.tr("menu.addAccount", default: "Add Account...")
entries.append(.action(accountLabel, loginAction))
}
}
Expand All @@ -343,10 +343,10 @@ struct MenuDescriptor {
}

if metadata?.dashboardURL != nil {
entries.append(.action("Usage Dashboard", .dashboard))
entries.append(.action(L10n.tr("menu.dashboard", default: "Usage Dashboard"), .dashboard))
}
if metadata?.statusPageURL != nil || metadata?.statusLinkURL != nil {
entries.append(.action("Status Page", .statusPage))
entries.append(.action(L10n.tr("menu.statusPage", default: "Status Page"), .statusPage))
}

if let statusLine = self.statusLine(for: provider, store: store) {
Expand All @@ -359,12 +359,12 @@ struct MenuDescriptor {
private static func metaSection(updateReady: Bool) -> Section {
var entries: [Entry] = []
if updateReady {
entries.append(.action("Update ready, restart now?", .installUpdate))
entries.append(.action(L10n.tr("menu.updateReady", default: "Update ready, restart now?"), .installUpdate))
}
entries.append(contentsOf: [
.action("Settings...", .settings),
.action("About CodexBar", .about),
.action("Quit", .quit),
.action(L10n.tr("menu.settings", default: "Settings..."), .settings),
.action(L10n.tr("menu.about", default: "About CodexBar"), .about),
.action(L10n.tr("menu.quit", default: "Quit"), .quit),
])
return Section(entries: entries)
}
Expand Down
15 changes: 8 additions & 7 deletions Sources/CodexBar/PreferencesAboutPane.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import AppKit
import CodexBarCore
import SwiftUI

@MainActor
Expand Down Expand Up @@ -51,14 +52,14 @@ struct AboutPane: View {
VStack(spacing: 2) {
Text("CodexBar")
.font(.title3).bold()
Text("Version \(self.versionString)")
Text(L10n.tr("preferences.about.version", default: "Version %@", self.versionString))
.foregroundStyle(.secondary)
if let buildTimestamp {
Text("Built \(buildTimestamp)")
Text(L10n.tr("preferences.about.built", default: "Built %@", buildTimestamp))
.font(.footnote)
.foregroundStyle(.secondary)
}
Text("May your tokens never run out—keep agent limits in view.")
Text(L10n.tr("preferences.about.tagline", default: "May your tokens never run out—keep agent limits in view."))
.font(.footnote)
.foregroundStyle(.secondary)
}
Expand All @@ -80,12 +81,12 @@ struct AboutPane: View {

if self.updater.isAvailable {
VStack(spacing: 10) {
Toggle("Check for updates automatically", isOn: self.$autoUpdateEnabled)
Toggle(L10n.tr("preferences.about.autoUpdates", default: "Check for updates automatically"), isOn: self.$autoUpdateEnabled)
.toggleStyle(.checkbox)
.frame(maxWidth: .infinity, alignment: .center)
VStack(spacing: 6) {
HStack(spacing: 12) {
Text("Update Channel")
Text(L10n.tr("preferences.about.updateChannel", default: "Update Channel"))
Spacer()
Picker("", selection: self.updateChannelBinding) {
ForEach(UpdateChannel.allCases) { channel in
Expand All @@ -102,10 +103,10 @@ struct AboutPane: View {
.multilineTextAlignment(.center)
.frame(maxWidth: 280)
}
Button("Check for Updates…") { self.updater.checkForUpdates(nil) }
Button(L10n.tr("preferences.about.checkForUpdates", default: "Check for Updates…")) { self.updater.checkForUpdates(nil) }
}
} else {
Text(self.updater.unavailableReason ?? "Updates unavailable in this build.")
Text(self.updater.unavailableReason ?? L10n.tr("preferences.about.updatesUnavailable", default: "Updates unavailable in this build."))
.foregroundStyle(.secondary)
}

Expand Down
Loading