Merge record-ui: recording controls for the macOS + iOS builder apps
This commit is contained in:
@@ -55,6 +55,9 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
private var startMenuItem: NSMenuItem?
|
||||
private var stopMenuItem: NSMenuItem?
|
||||
|
||||
/// Record toggle item, retained so `validateMenuItem(_:)` can flip its title + enabled state.
|
||||
private var recordMenuItem: NSMenuItem?
|
||||
|
||||
/// Default file name offered by the Save panel.
|
||||
private static let defaultRigFileName: String = "ShoeGazeRig"
|
||||
|
||||
@@ -178,6 +181,25 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
startMenuItem = addItem(to: boardMenu, title: "Start", action: #selector(startAction(_:)), key: "r")
|
||||
stopMenuItem = addItem(to: boardMenu, title: "Stop", action: #selector(stopAction(_:)), key: ".")
|
||||
|
||||
// Record menu — choose an output folder, then toggle recording.
|
||||
let recordMenuItem: NSMenuItem = NSMenuItem()
|
||||
mainMenu.addItem(recordMenuItem)
|
||||
let recordMenu: NSMenu = NSMenu(title: "Record")
|
||||
recordMenuItem.submenu = recordMenu
|
||||
addItem(
|
||||
to: recordMenu,
|
||||
title: "Choose Recording Folder…",
|
||||
action: #selector(chooseRecordingFolderAction(_:)),
|
||||
key: ""
|
||||
)
|
||||
recordMenu.addItem(NSMenuItem.separator())
|
||||
self.recordMenuItem = addItem(
|
||||
to: recordMenu,
|
||||
title: "Start Recording",
|
||||
action: #selector(toggleRecordingAction(_:)),
|
||||
key: "R" // ⇧⌘R
|
||||
)
|
||||
|
||||
NSApplication.shared.mainMenu = mainMenu
|
||||
}
|
||||
|
||||
@@ -249,9 +271,41 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
engine.stop()
|
||||
}
|
||||
|
||||
@objc private func chooseRecordingFolderAction(_ sender: Any?) {
|
||||
let panel: NSOpenPanel = NSOpenPanel()
|
||||
panel.canChooseDirectories = true
|
||||
panel.canChooseFiles = false
|
||||
panel.allowsMultipleSelection = false
|
||||
panel.canCreateDirectories = true
|
||||
panel.prompt = "Choose"
|
||||
panel.message = "Select a folder for recording output"
|
||||
let session: ShoeGaze = shoeGaze
|
||||
panel.begin { response in
|
||||
if response == .OK, let url: URL = panel.url {
|
||||
session.recordingFolder = url
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@objc private func toggleRecordingAction(_ sender: Any?) {
|
||||
if shoeGaze.isRecording {
|
||||
shoeGaze.stopRecording()
|
||||
} else {
|
||||
do { try shoeGaze.startRecording() }
|
||||
catch { print("[ShoeGazeBuilder] startRecording() failed: \(error)") }
|
||||
}
|
||||
// Reflect the new state on the item immediately, not only on the next menu-open validation.
|
||||
recordMenuItem?.title = shoeGaze.isRecording ? "Stop Recording" : "Start Recording"
|
||||
}
|
||||
|
||||
func validateMenuItem(_ menuItem: NSMenuItem) -> Bool {
|
||||
if menuItem == startMenuItem { return !engine.isRunning }
|
||||
if menuItem == stopMenuItem { return engine.isRunning }
|
||||
if menuItem == recordMenuItem {
|
||||
menuItem.title = shoeGaze.isRecording ? "Stop Recording" : "Start Recording"
|
||||
// Can always stop; can only start once a folder has been chosen.
|
||||
return shoeGaze.isRecording || shoeGaze.recordingFolder != nil
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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