#if COTTON_DEV // DevCorner.swift — DEVELOPER TOOL, compiled into Cotton Dev only. // // Every screen's corner says which build this is and which store schema it // writes, so a screenshot in a report needs no question about the build. With // Settings › Developer › Show timings on, it also says the surface on screen, // its time to first rows and the reads it made; a tap opens the list. import CottonKit import SwiftUI struct DevCorner: View { /// A leaf reader (`Scaffold/CottonCoreKey.swift`): no core, no schema line. @Environment(\.cottonCore) private var core @State private var schema: Int? @State private var expanded = false private let timings = DevTimings.shared private let build = BuildFacts.fromBundle() private struct Facts: Decodable { let schemaVersion: Int } var body: some View { VStack(alignment: .trailing, spacing: 2) { if timings.showing { // The reads are not observed; a second's tick redraws them. TimelineView(.periodic(from: .now, by: 1)) { _ in VStack(alignment: .trailing, spacing: 2) { timingLines } } } Text(stamp) } .font(.system(size: 9, weight: .medium, design: .monospaced)) .foregroundStyle(.white) .padding(.horizontal, 5) .padding(.vertical, 2) .background(.black.opacity(0.55), in: RoundedRectangle(cornerRadius: 4)) .padding(4) .onTapGesture { if timings.showing { expanded.toggle() } } // It sits over the page's foot: a tap meant for what is under it (the // tray's undo) passes through unless it has timings to open (walker, // 16 Oct 2026: undo under the corner did nothing). .allowsHitTesting(timings.showing) .accessibilityIdentifier("dev-corner") .task { guard let core else { return } schema = (try? await core.call("build.facts", as: Facts.self))?.schemaVersion } } private var stamp: String { // The developer's corner, opened on purpose in a dev build, keeps the // schema the person-facing build line no longer writes. BuildLine.own(version: build.version, build: build.build, commit: build.commit) + " · schema \(schema.map(String.init) ?? "?")" } @ViewBuilder private var timingLines: some View { let reads = timings.reads() let first = timings.firstRowMillis.map { String(format: "%.0f ms", $0) } ?? ShellLines.line("developer", "corner.no_rows") Text(ShellLines.line("developer", "corner.timings", [ "surface": timings.surface ?? ShellLines.line("developer", "corner.no_surface"), "first": first, "reads": String(reads.count), ])) if expanded { ForEach(Array(reads.suffix(20).enumerated()), id: \.offset) { _, call in Text(String(format: "%@ %.0f ms", call.method, call.millis)) } } } } #endif