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

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

ShareExtension.swift37 lines · 1.9 KiBRaw
1// EverySync Notes — Share extension.
2//
3// `NSExtension` (`com.apple.share-services`) target. Receives text / URLs /
4// images, converts to `NoteBlock`s via the XCFramework parsers
5// (`parseNoteBody` / text-block construction — never hand-built JSON), and
6// writes through the App-Group envelope IPC. It NEVER talks to the relay
7// directly; the hub picks up the new envelopes on its next cycle.
8//
9// Conversion (via XCFramework only):
10// - text / URL -> `NoteBlock.Text(markdown:)` (URLs stored as markdown links;
11// Swift does not invent block types).
12// - image -> write bytes to `BlobStore` under the XCFramework-derived
13// `fileName`, then `NoteBlock.Image(fileName:, widthFraction: 1.0)`.
14// - New note = fresh syncId (`newRelaySyncId` in the XCFramework);
15// `blocksJson` = `serializeNoteBody`; row written via
16// `upsertRaw(vaultId:table:rows:)` on the `notes` table.
17//
18// MAC-CHECK (needs xcodebuild on a Mac):
19// - Extension target links `EverysyncCore.xcframework` + shares the App Group.
20// - `NSExtensionAttributes` (`NSExtensionActivationRule`) in the extension's
21// Info.plist — plain-text + URL + image predicates.
22
23import UIKit
24import Social
25import EverysyncCore
26
27/// Share-extension view controller. Thin adapter: system share sheet in,
28/// envelope IPC out, XCFramework parsers in between.
29final class EverySyncShareExtension: SLComposeServiceViewController {
30 // TODO(Mac): read `extensionContext?.inputItems`; for each:
31 // - text/URL: build NoteBlock.Text via the XCFramework (never raw JSON).
32 // - image: persist bytes through BlobStore, build NoteBlock.Image.
33 // Then serialize via `serializeNoteBody`, wrap in a RemoteNote envelope
34 // via `NoteKind.toJson`, and `upsertRaw` into the active vault's `notes`
35 // table. Surface errors with `AppMessages`-equivalent UI (no Toast —
36 // repo-wide ban; use the host sheet's own presentation).
37}