76 lines
2.4 KiB
Swift
76 lines
2.4 KiB
Swift
import SwiftUI
|
|
import ZxDocumentRuntime
|
|
|
|
/// Minimal demo app to verify zhixi-document-runtime integration.
|
|
@main
|
|
struct MaterialReaderDemo: App {
|
|
var body: some Scene {
|
|
WindowGroup {
|
|
ContentView()
|
|
}
|
|
}
|
|
}
|
|
|
|
struct ContentView: View {
|
|
@State private var filePath = ""
|
|
@State private var result = ""
|
|
@State private var events: [ReadingEvent] = []
|
|
|
|
var body: some View {
|
|
NavigationStack {
|
|
List {
|
|
Section("File Type Detection") {
|
|
TextField("File path", text: $filePath)
|
|
.font(.system(size: 14, design: .monospaced))
|
|
Button("Detect Type") {
|
|
detect()
|
|
}
|
|
if !result.isEmpty {
|
|
Text(result)
|
|
.font(.system(size: 14))
|
|
.foregroundColor(.secondary)
|
|
}
|
|
}
|
|
|
|
Section("Reading Events") {
|
|
if events.isEmpty {
|
|
Text("No events yet")
|
|
.foregroundColor(.secondary)
|
|
} else {
|
|
ForEach(0..<events.count, id: \.self) { i in
|
|
Text("Event \(i): \(String(describing: events[i]))")
|
|
.font(.system(size: 12, design: .monospaced))
|
|
}
|
|
}
|
|
Button("Simulate Reading Session") {
|
|
simulateReading()
|
|
}
|
|
}
|
|
}
|
|
.navigationTitle("MaterialReader Demo")
|
|
}
|
|
}
|
|
|
|
func detect() {
|
|
guard !filePath.isEmpty else {
|
|
result = "Enter a file path"
|
|
return
|
|
}
|
|
do {
|
|
let type = try detectMaterialType(filePath: filePath)
|
|
result = "Detected: \(type)"
|
|
} catch {
|
|
result = "Error: \(error)"
|
|
}
|
|
}
|
|
|
|
func simulateReading() {
|
|
let now = Int64(Date().timeIntervalSince1970 * 1000)
|
|
events = [
|
|
ReadingEvent.materialOpened(materialId: "demo-1", timestampMs: now),
|
|
ReadingEvent.heartbeat(materialId: "demo-1", activeSeconds: 15, position: nil, timestampMs: now + 15000),
|
|
ReadingEvent.materialClosed(materialId: "demo-1", timestampMs: now + 30000, activeSeconds: 30),
|
|
]
|
|
}
|
|
}
|