codeburn/mac/Sources/CodeBurnMenubar/Views/SectionCaption.swift
Resham Joshi 495a254338 feat(mac): native Swift menubar app + one-command install
Introduces mac/ with a native SwiftUI menubar app that replaces the
previous SwiftBar plugin entirely. Install via `npx codeburn menubar`,
which downloads the .app from GitHub Releases, strips Gatekeeper
quarantine, and drops it into ~/Applications.

Highlights

- mac/ SwiftUI app: agent tabs, Today/7/30/Month/All period switcher,
  Trend/Forecast/Pulse/Stats/Plan insights, activity + model
  breakdowns, optimize findings, CSV/JSON export, Star-on-GitHub
  banner, live 60s refresh, instant currency switching with offline FX
  cache.
- Security: CodeburnCLI argv-based spawn (no shell interpretation),
  SafeFile symlink guards + O_NOFOLLOW writes, FX rate clamping to
  [0.0001, 1_000_000], keychain filtered to account == "default",
  removed byte-window credential log, in-flight refresh guard, POSIX
  flock on config.json writes, TerminalLauncher validates argv before
  AppleScript interpolation.
- Performance: shared static NumberFormatter (thousands of allocations
  per popover redraw eliminated), concurrent pipe drain with 20 MB cap
  + 60s timeout in DataClient, Observation-tracked reactive UI, 5-min
  payload cache keyed on (period, provider).
- CLI: new `codeburn menubar` subcommand that downloads + installs +
  launches the .app (no clone, no build). New `status --format
  menubar-json` payload builder. `export` rewritten to produce a
  folder of one-table-per-file CSVs with a `.codeburn-export` marker
  so arbitrary -o paths cannot be silently deleted.
- Removed: src/menubar.ts (SwiftBar plugin generator),
  install-menubar / uninstall-menubar subcommands, `status --format
  menubar` directive output, tests/menubar.test.ts,
  tests/security/menubar-injection.test.ts.
- Release: .github/workflows/release-menubar.yml builds universal
  binary, assembles .app, ad-hoc signs, zips, uploads on mac-v* tag
  push. Runs on the free macos-latest runner.

Tests

- 230 TypeScript tests pass
- 10 Swift CapacityEstimator tests pass
- TypeScript typecheck clean
- Swift release build clean
2026-04-17 16:55:56 -07:00

85 lines
2.6 KiB
Swift

import SwiftUI
struct SectionCaption: View {
let text: String
var body: some View {
HStack(spacing: 5) {
Circle()
.fill(Theme.brandAccent.opacity(0.7))
.frame(width: 3, height: 3)
Text(text)
.font(.system(size: 11.5, weight: .medium))
.foregroundStyle(.secondary)
.tracking(-0.1)
}
}
}
/// Collapsible section shell with a clickable caption, optional inline trailing
/// view (e.g. column headers), and a chevron.
struct CollapsibleSection<Trailing: View, Content: View>: View {
let caption: String
@Binding var isExpanded: Bool
let trailing: Trailing
let content: Content
init(
caption: String,
isExpanded: Binding<Bool>,
@ViewBuilder trailing: () -> Trailing,
@ViewBuilder content: () -> Content
) {
self.caption = caption
self._isExpanded = isExpanded
self.trailing = trailing()
self.content = content()
}
var body: some View {
VStack(alignment: .leading, spacing: 7) {
Button {
withAnimation(.easeInOut(duration: 0.18)) {
isExpanded.toggle()
}
} label: {
HStack(spacing: 8) {
HStack(spacing: 5) {
Circle()
.fill(Theme.brandAccent.opacity(0.7))
.frame(width: 3, height: 3)
Text(caption)
.font(.system(size: 11.5, weight: .medium))
.tracking(-0.1)
}
Spacer()
trailing
Image(systemName: "chevron.right")
.font(.system(size: 9, weight: .semibold))
.rotationEffect(.degrees(isExpanded ? 90 : 0))
.opacity(0.55)
}
.foregroundStyle(.secondary)
.contentShape(Rectangle())
}
.buttonStyle(.plain)
if isExpanded {
content
.transition(.opacity)
}
}
.padding(.horizontal, 14)
.padding(.vertical, 11)
}
}
extension CollapsibleSection where Trailing == EmptyView {
init(
caption: String,
isExpanded: Binding<Bool>,
@ViewBuilder content: () -> Content
) {
self.init(caption: caption, isExpanded: isExpanded, trailing: { EmptyView() }, content: content)
}
}