diff --git a/Sources/PlayerRecorder.swift b/Sources/PlayerRecorder.swift index 5539856..0363bf8 100644 --- a/Sources/PlayerRecorder.swift +++ b/Sources/PlayerRecorder.swift @@ -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