Add recording UI to the builder apps (macOS menu + iOS controls)
Wires the existing ShoeGaze recording engine into the builder: - macOS: a Record menu (Choose Recording Folder…; Start/Stop Recording, ⇧⌘R) in the app shell's AppDelegate. validateMenuItem gates Start on a chosen folder and flips the title; the title is also set directly in the toggle action so it never goes stale. - iOS: an in-view recording row in ShoeGazeBuilderView — folder picker (.fileImporter with security-scoped access) + Record/Stop button, gated on a chosen folder. - Both: a red REC indicator in the transport header bound to isRecording. Reuses startRecording/stopRecording/recordingFolder/isRecording (already covered by RecordingTests); no core or RT changes. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -49,6 +49,8 @@ public struct ShoeGazeBuilderView: View {
|
||||
private static let backgroundBlue: Double = 0.06
|
||||
private static let testLoopTag: Int = -1
|
||||
private static let defaultRigFileName: String = "ShoeGazeRig"
|
||||
private static let recordDotSize: CGFloat = 9
|
||||
private static let folderLabelOpacity: Double = 0.55
|
||||
|
||||
// MARK: - Properties
|
||||
|
||||
@@ -65,6 +67,8 @@ public struct ShoeGazeBuilderView: View {
|
||||
@State private var showImporter: Bool = false
|
||||
@State private var showExporter: Bool = false
|
||||
@State private var exportDocument: RigFileDocument = RigFileDocument(data: Data())
|
||||
/// iOS recording-folder picker presentation flag. (macOS uses the Record menu.)
|
||||
@State private var showRecordingFolderImporter: Bool = false
|
||||
#endif
|
||||
|
||||
// MARK: - Init
|
||||
@@ -83,6 +87,9 @@ public struct ShoeGazeBuilderView: View {
|
||||
VStack(alignment: .leading, spacing: ShoeGazeBuilderView.sectionSpacing) {
|
||||
transportRow
|
||||
ioRow
|
||||
#if !os(macOS)
|
||||
recordingRow
|
||||
#endif
|
||||
Divider().overlay(Color.white.opacity(ShoeGazeBuilderView.dividerOpacity))
|
||||
HStack(alignment: .top, spacing: ShoeGazeBuilderView.columnSpacing) {
|
||||
paletteSidebar
|
||||
@@ -105,6 +112,9 @@ public struct ShoeGazeBuilderView: View {
|
||||
.fileImporter(isPresented: $showImporter, allowedContentTypes: [.json]) { result in
|
||||
handleImport(result)
|
||||
}
|
||||
.fileImporter(isPresented: $showRecordingFolderImporter, allowedContentTypes: [.folder]) { result in
|
||||
handleRecordingFolderImport(result)
|
||||
}
|
||||
.fileExporter(
|
||||
isPresented: $showExporter,
|
||||
document: exportDocument,
|
||||
@@ -127,6 +137,18 @@ public struct ShoeGazeBuilderView: View {
|
||||
Text("ShoeGaze Builder")
|
||||
.font(.title2).bold()
|
||||
.foregroundStyle(Color.white)
|
||||
if shoeGaze.isRecording {
|
||||
// Recording indicator (both platforms; recording is driven from the macOS Record
|
||||
// menu or the iOS controls below).
|
||||
HStack(spacing: 4) {
|
||||
Circle()
|
||||
.fill(Color.red)
|
||||
.frame(width: ShoeGazeBuilderView.recordDotSize, height: ShoeGazeBuilderView.recordDotSize)
|
||||
Text("REC")
|
||||
.font(.caption.monospaced())
|
||||
.foregroundStyle(Color.red)
|
||||
}
|
||||
}
|
||||
Spacer()
|
||||
Button("Start") {
|
||||
do { try shoeGaze.engine.start() }
|
||||
@@ -302,6 +324,50 @@ public struct ShoeGazeBuilderView: View {
|
||||
// NSSavePanel/NSOpenPanel and calls `shoeGaze.saveRig`/`loadRig` directly). On iOS they are
|
||||
// in-view, presenting `fileExporter`/`fileImporter`.
|
||||
#if !os(macOS)
|
||||
/// iOS recording controls: choose an output folder, then start/stop recording.
|
||||
private var recordingRow: some View {
|
||||
HStack(spacing: ShoeGazeBuilderView.rowSpacing) {
|
||||
Button("Recording Folder…") { showRecordingFolderImporter = true }
|
||||
.buttonStyle(.bordered).tint(.blue)
|
||||
Text(shoeGaze.recordingFolder?.lastPathComponent ?? "No folder")
|
||||
.font(.caption)
|
||||
.foregroundStyle(Color.white.opacity(ShoeGazeBuilderView.folderLabelOpacity))
|
||||
.lineLimit(1)
|
||||
.truncationMode(.middle)
|
||||
Spacer()
|
||||
Button(shoeGaze.isRecording ? "Stop Recording" : "Record") {
|
||||
toggleRecording()
|
||||
}
|
||||
.buttonStyle(.borderedProminent)
|
||||
.tint(shoeGaze.isRecording ? .red : .accentColor)
|
||||
.disabled(shoeGaze.recordingFolder == nil && !shoeGaze.isRecording)
|
||||
}
|
||||
}
|
||||
|
||||
private func toggleRecording() {
|
||||
if shoeGaze.isRecording {
|
||||
shoeGaze.stopRecording()
|
||||
} else {
|
||||
do { try shoeGaze.startRecording() }
|
||||
catch { print("[ShoeGazeBuilderView] startRecording() failed: \(error)") }
|
||||
}
|
||||
}
|
||||
|
||||
private func handleRecordingFolderImport(_ result: Result<URL, Error>) {
|
||||
switch result {
|
||||
case .success(let url):
|
||||
// A `.fileImporter` folder URL is security-scoped on iOS; keep access open for the
|
||||
// session so the recorder can write into it.
|
||||
if url.startAccessingSecurityScopedResource() {
|
||||
shoeGaze.recordingFolder = url
|
||||
} else {
|
||||
print("[ShoeGazeBuilderView] could not access recording folder")
|
||||
}
|
||||
case .failure(let error):
|
||||
print("[ShoeGazeBuilderView] recording folder pick failed: \(error)")
|
||||
}
|
||||
}
|
||||
|
||||
private func saveAction() {
|
||||
do {
|
||||
exportDocument = RigFileDocument(data: try shoeGaze.rigData())
|
||||
|
||||
Reference in New Issue
Block a user