fix: show save dialog even on error if file has content; better default filename
This commit is contained in:
parent
221075ce8a
commit
49948049c0
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user