import AppKit import LChatCore import SwiftUI // 🤖 Settings → Advanced → "Performance": the Mac face of the shared perf // instrumentation (LChatCore Perf.swift) — the same consent toggle as the // iOS sheet, plus Reveal-in-Finder for the assembled report (the Mac idiom; // iOS shares a file instead). struct PerfSettingsSection: View { @AppStorage(Perf.consentKey) private var perfDiagnostics = Perf.defaultEnabled @State private var summary: String? var body: some View { Section { Toggle("Record performance diagnostics", isOn: $perfDiagnostics) .onChange(of: perfDiagnostics) { _, next in Perf.setRecording(next) } if perfDiagnostics { HStack { Text(summary.map { "Recorded so far: \($0)." } ?? "Nothing recorded yet.") .font(.footnote) .foregroundStyle(.secondary) Spacer() Button("Show Report in Finder") { revealReport() } } } Text("A private log of how long things take — starting the app, opening chats, moments it freezes. It never includes what's in your messages, and it never leaves this Mac unless you share the report yourself.") .font(.footnote) .foregroundStyle(.secondary) } header: { Text("Performance") } .task(id: perfDiagnostics) { guard perfDiagnostics else { return } let events = await Task.detached { Perf.recordedEvents() }.value summary = PerfEvent.summary(events) } } private func revealReport() { Task { let url = await Task.detached { Perf.assembleExport() }.value guard let url else { return } NSWorkspace.shared.activateFileViewerSelecting([url]) } } }