Skip to content

Open source CapCut alternative.

TypeScript

fix(app): finalize recordings on close [rebuild]

David Le16f50d723090
diff --git a/apps/Donkey/Sources/DonkeyUI/RecordingControlBarView.swift b/apps/Donkey/Sources/DonkeyUI/RecordingControlBarView.swift
index d8b4dff4..c4dd28b2 100644
--- a/apps/Donkey/Sources/DonkeyUI/RecordingControlBarView.swift
+++ b/apps/Donkey/Sources/DonkeyUI/RecordingControlBarView.swift
@@ -69,6 +69,17 @@ public final class RecordingControlBarModel: ObservableObject {
public init() {}
+ // Keep the controls until an active movie has finished writing.
+ func requestClose() {
+ guard !isBusy else { return }
+ if isRecording {
+ onStop?()
+ return
+ }
+
+ onClose?()
+ }
+
var selectedAudioInput: RecordingAudioInput? {
audioInputs.first { $0.id == selectedAudioInputID }
}
@@ -151,7 +162,7 @@ public struct RecordingControlBarView: View {
private var controls: some View {
HStack(spacing: 10) {
- iconButton(symbol: "xmark", help: "Close") { model.onClose?() }
+ iconButton(symbol: "xmark", help: "Close") { model.requestClose() }
.disabled(model.isBusy)
Divider().frame(height: 22)
diff --git a/apps/Donkey/Tests/DonkeyRuntimeTests/RecordingCloseTests.swift b/apps/Donkey/Tests/DonkeyRuntimeTests/RecordingCloseTests.swift
new file mode 100644
index 00000000..ea18b3c0
--- /dev/null
+++ b/apps/Donkey/Tests/DonkeyRuntimeTests/RecordingCloseTests.swift
@@ -0,0 +1,46 @@
+import Testing
+@testable import DonkeyUI
+
+@MainActor
+struct RecordingCloseTests {
+ @Test func closeFinalizesActiveCapture() {
+ let model = RecordingControlBarModel()
+ model.isRecording = true
+ var stopRequests = 0
+ var closeRequests = 0
+ model.onStop = { stopRequests += 1 }
+ model.onClose = { closeRequests += 1 }
+
+ // Closing a live capture must request its finalized file.
+ model.requestClose()
+
+ #expect(stopRequests == 1)
+ #expect(closeRequests == 0)
+ }
+
+ @Test func closeDismissesArmedCapture() {
+ let model = RecordingControlBarModel()
+ var closeRequests = 0
+ model.onClose = { closeRequests += 1 }
+
+ // An armed capture has no movie to finalize.
+ model.requestClose()
+
+ #expect(closeRequests == 1)
+ }
+
+ @Test(arguments: [true, false])
+ func closeWaitsForBusyCapture(isRecording: Bool) {
+ let model = RecordingControlBarModel()
+ model.isRecording = isRecording
+ model.isBusy = true
+ var requests = 0
+ model.onStop = { requests += 1 }
+ model.onClose = { requests += 1 }
+
+ // Start and finalization retain ownership until they finish.
+ model.requestClose()
+
+ #expect(requests == 0)
+ }
+}