oficina / docs Public

Clone
git clone https://amadan.net/oficina/docs

Plain git — no account needed to clone.

Download

Download this file

1import DocsKit
2import Foundation
3import RastrilloApple
4import SwiftUI
5// This entry point is exclusively the review target. The production target
6// compiles Sources/DocsApp and has no fixture/environment authentication path.
7@main struct DocsReviewPhone: App {
8 private struct Configuration: Decodable { let origin: String; let credential: NativeSession }
9 private var client: NativeHTTP? {
10 let input = URL.documentsDirectory.appendingPathComponent("review.json")
11 guard let data = try? Data(contentsOf: input),
12 let config = try? JSONDecoder().decode(Configuration.self, from: data),
13 let origin = try? NativeHTTP.origin(config.origin), origin.scheme == "http", ["localhost", "127.0.0.1", "::1", "[::1]"].contains(origin.host ?? "") else { return nil }
14 return NativeHTTP(origin: origin, credential: config.credential)
15 }
16 var body: some Scene {
17 WindowGroup {
18 if let client {
19 DocsWorkspace(client: client, signOut: {})
20 .overlay(alignment: .bottom) {
21 if ProcessInfo.processInfo.environment["DOCS_REVIEW_COMMAND_PROBE"] == "1" {
22 ReviewCommandProbe()
23 }
24 }
25 }
26 else { Text("Review fixture unavailable").accessibilityIdentifier("fixture.missing") }
27 }
28 }
29}
30
31// Fixed-command review probe only. It inspects and dispatches the editor's real
32// registered Command-K action through the first-responder chain, without HID.
33import UIKit
34private struct ReviewCommandProbe: View {
35 @State private var status = "Waiting for native editor focus"
36 var body: some View {
37 Text(status).font(.caption).accessibilityIdentifier("review.command.probe")
38 .task {
39 for _ in 0..<200 {
40 guard !Task.isCancelled else { return }
41 let scenes = UIApplication.shared.connectedScenes.compactMap { $0 as? UIWindowScene }
42 let windows: [UIWindow] = scenes.flatMap { $0.windows }
43 var focused: UITextView?
44 for window in windows {
45 if let editor = focusedEditor(in: window) { focused = editor; break }
46 }
47 if let editor = focused {
48 let registered: [UIKeyCommand] = editor.keyCommands ?? []
49 var found: UIKeyCommand?
50 for candidate in registered {
51 if candidate.input == "k" && candidate.modifierFlags == UIKeyModifierFlags.command { found = candidate; break }
52 }
53 guard let command = found, let selector = command.action, command.wantsPriorityOverSystemBehavior else {
54 status = "Missing native Command-K registration"; return
55 }
56 status = UIApplication.shared.sendAction(selector, to: nil, from: command, for: nil)
57 ? "Native Command-K dispatched" : "Native Command-K dispatch failed"
58 return
59 }
60 try? await Task.sleep(for: .milliseconds(100))
61 }
62 status = "Native editor never became first responder"
63 }
64 }
65 private func focusedEditor(in view: UIView) -> UITextView? {
66 if let editor = view as? UITextView, editor.accessibilityIdentifier == "docs.editor", editor.isFirstResponder { return editor }
67 return view.subviews.lazy.compactMap { focusedEditor(in: $0) }.first
68 }
69}
70