Modern Apps git
git clone https://git.maproj.org/Modern-Apps.git
cov/c3 ▾

Modern-Apps.git / apple / Notes / NotesApp.swift

NotesApp.swift84 lines · 3.6 KiBRaw
1// EverySync Notes — Phase 3 SwiftUI shell.
2//
3// ZERO sync logic in Swift. All blocks parsing (`parseNoteBody` /
4// `serializeNoteBody` / `noteBodyText`), merge (`NoteKind`), transport
5// (`IosRelayTransport`), and crypto lives in the shared XCFramework. This
6// target renders the editor, maps PencilKit strokes to the shared ink model
7// (see `PencilKitMapping.swift`), renders blocks natively (see
8// `NoteBodyView.swift`), hosts the Share extension (see
9// `ShareExtension.swift`), and schedules background sync. Notes soft-delete:
10// tombstone rows persist locally and propagate
11// (`NoteKind.localDeletesAreAuthoritative == true`).
12
13import SwiftUI
14import BackgroundTasks
15import EverysyncCore
16
17// MARK: - KMP entry points (Phase 3 wiring — call, never re-implement)
18//
19// data: core.data.RemoteNote (uid / title / content / blocksJson /
20// position / deleted / updatedAt)
21// blocks: core.notes.parseNoteBody(blocksJson, fallbackContent)
22// core.notes.serializeNoteBody(body)
23// core.notes.noteBodyText(body) — plain-text projection for
24// search / preview / share. `ignoreUnknownKeys` keeps legacy
25// notes parsing.
26// core.notes.NoteBlock.Text(markdown, id) / .Image(fileName,
27// widthFraction, id) / .Ink(strokes, heightDp, id)
28// core.notes.InkStroke(brushFamily="pressurePen", brushSize,
29// brushColor argb int, brushEpsilon=0.1, points)
30// core.notes.InkPoint(x, y, timeMillis, pressure, tiltRadians,
31// orientationRadians)
32// kind: core.sync.adapters.NoteKind (syncId=uid, LWW updatedAt, hash
33// over canonical JSON with identity/position/timestamps stripped
34// — reorder is not an edit; `imageNames(blocksJson)` for blob
35// prefetch)
36// blobs: channel `notes-blobs:<vaultId>` for image bytes (never inline
37// in envelopes); sidecar via `../Shared/BlobStore.swift`
38// driver: core.provider.SyncDriver.drive(kind, store, remote, append, now)
39// cursors: core.platform.RelayCursorStore
40// securestore: core.platform.SecureStore (Keychain actual)
41// transport: core.network.IosRelayTransport
42// (`recordChannel("notes", vaultId)` -> `notes:<vaultId>`)
43// pqc/roles/links: same surface as Passwords; notes vaults may offer EDITOR
44// or VIEWER (unlike passwords — see `RelayRoles`).
45
46@main
47struct NotesApp: App {
48 init() {
49 // MAC-CHECK: identifier must match Info.plist
50 // `BGTaskSchedulerPermittedIdentifiers`.
51 BackgroundSync.register(handlers: [
52 "com.vayunmathur.everysync.notes.refresh": { task in
53 // TODO(Mac): call XCFramework SyncDriver cycle for each vault,
54 // then re-schedule + `task.setTaskCompleted(success:)`.
55 task.setTaskCompleted(success: true)
56 },
57 ])
58 }
59
60 var body: some Scene {
61 WindowGroup {
62 NotesRootView()
63 }
64 }
65}
66
67struct NotesRootView: View {
68 // TODO(Mac): note list driven by SyncDriver snapshots; preview text via
69 // `noteBodyText` in the XCFramework (never hand-parsed in Swift).
70 // Editor binds PKCanvasView and maps PKStroke -> InkStroke per
71 // `PencilKitMapping.swift`, then serializes via `serializeNoteBody`.
72 @State private var query = ""
73
74 var body: some View {
75 NavigationStack {
76 VStack {
77 // TODO(Mac): replace with the XCFramework-driven list.
78 Text("EverySync Notes")
79 .navigationTitle("Notes")
80 }
81 .searchable(text: $query)
82 }
83 }
84}