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:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user