fix: show save dialog even on error if file has content; better default filename

This commit is contained in:
yumoqing 2026-06-28 21:46:41 +08:00
parent 221075ce8a
commit 49948049c0

View File

@ -73,9 +73,17 @@ final class PlayerRecorder: NSObject {
await MainActor.run {
RecorderState.isFinalizing = false
self?.stopDurationTimer()
self?.onError?(error.localizedDescription)
try? FileManager.default.removeItem(at: tempURL)
self?.checkPendingTerminate()
//
let attrs = try? FileManager.default.attributesOfItem(atPath: tempURL.path)
let fileSize = (attrs?[.size] as? Int64) ?? 0
if fileSize > 0 {
NSLog("[Recorder] File exists with size %lld, offering save dialog", fileSize)
self?.showSaveDialog(tempURL: tempURL)
} else {
self?.onError?(error.localizedDescription)
try? FileManager.default.removeItem(at: tempURL)
self?.checkPendingTerminate()
}
}
}
}
@ -122,7 +130,9 @@ final class PlayerRecorder: NSObject {
private func showSaveDialog(tempURL: URL) {
let panel = NSSavePanel()
panel.allowedContentTypes = [.mpeg4Movie]
panel.nameFieldStringValue = tempURL.lastPathComponent
// temp_
let defaultName = tempURL.lastPathComponent.replacingOccurrences(of: "temp_", with: "")
panel.nameFieldStringValue = defaultName
panel.directoryURL = saveDirectory
panel.begin { [weak self] response in