Do not run the optimize pass if writing was cancelled
This commit is contained in:
3 files changed
+15
-5
No files matched your search
+11
-1
@@ -15,6 +15,7 @@ final class Document: NSDocument {
|
|||||||
private var unsupportedMp4Brand: Bool
|
private var unsupportedMp4Brand: Bool
|
||||||
|
|
||||||
override init() {
|
override init() {
|
||||||
|
self.cancelled = false
|
||||||
self.options = [:]
|
self.options = [:]
|
||||||
self.optimize = false
|
self.optimize = false
|
||||||
self.unsupportedMp4Brand = false
|
self.unsupportedMp4Brand = false
|
||||||
@@ -22,6 +23,7 @@ final class Document: NSDocument {
|
|||||||
}
|
}
|
||||||
|
|
||||||
init(mp4: MP42File) {
|
init(mp4: MP42File) {
|
||||||
|
self.cancelled = false
|
||||||
self.options = [:]
|
self.options = [:]
|
||||||
self.optimize = false
|
self.optimize = false
|
||||||
self.unsupportedMp4Brand = false
|
self.unsupportedMp4Brand = false
|
||||||
@@ -75,6 +77,7 @@ final class Document: NSDocument {
|
|||||||
|
|
||||||
private var optimize: Bool
|
private var optimize: Bool
|
||||||
private var options: [String : Any]
|
private var options: [String : Any]
|
||||||
|
private var cancelled: Bool
|
||||||
|
|
||||||
private func saveOptions(for saveOperation: NSDocument.SaveOperationType) -> [String : Any] {
|
private func saveOptions(for saveOperation: NSDocument.SaveOperationType) -> [String : Any] {
|
||||||
var options = [String : Any]()
|
var options = [String : Any]()
|
||||||
@@ -132,6 +135,11 @@ final class Document: NSDocument {
|
|||||||
super.save(to: url, ofType: typeName, for: saveOperation, completionHandler: modifiedCompletionhandler)
|
super.save(to: url, ofType: typeName, for: saveOperation, completionHandler: modifiedCompletionhandler)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func cancelSave() {
|
||||||
|
cancelled = true
|
||||||
|
mp4.cancel()
|
||||||
|
}
|
||||||
|
|
||||||
private var sleepAssertion: IOPMAssertionID = IOPMAssertionID(0)
|
private var sleepAssertion: IOPMAssertionID = IOPMAssertionID(0)
|
||||||
private var sleepAssertionSuccess: IOReturn = kIOReturnInvalid
|
private var sleepAssertionSuccess: IOReturn = kIOReturnInvalid
|
||||||
|
|
||||||
@@ -177,13 +185,15 @@ final class Document: NSDocument {
|
|||||||
fatalError("Unsupported save operation")
|
fatalError("Unsupported save operation")
|
||||||
}
|
}
|
||||||
|
|
||||||
if optimize {
|
if optimize && cancelled == false {
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
let docController = self.windowControllers.first as? DocumentWindowController
|
let docController = self.windowControllers.first as? DocumentWindowController
|
||||||
docController?.setProgress(title: NSLocalizedString("Optimizing…", comment: "Document Optimize sheet."))
|
docController?.setProgress(title: NSLocalizedString("Optimizing…", comment: "Document Optimize sheet."))
|
||||||
}
|
}
|
||||||
mp4.optimize()
|
mp4.optimize()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cancelled = false
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: Save panel
|
// MARK: Save panel
|
||||||
|
|||||||
@@ -280,8 +280,8 @@ final class DocumentWindowController: NSWindowController, TracksViewControllerDe
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func cancel() {
|
func cancelSave() {
|
||||||
mp4.cancel()
|
doc.cancelSave()
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: Actions
|
// MARK: Actions
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
import Cocoa
|
import Cocoa
|
||||||
|
|
||||||
protocol ProgressViewControllerDelegate : AnyObject {
|
protocol ProgressViewControllerDelegate : AnyObject {
|
||||||
func cancel()
|
func cancelSave()
|
||||||
}
|
}
|
||||||
|
|
||||||
final class ProgressViewController: NSViewController {
|
final class ProgressViewController: NSViewController {
|
||||||
@@ -53,7 +53,7 @@ final class ProgressViewController: NSViewController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@IBAction func cancel(_ sender: Any) {
|
@IBAction func cancel(_ sender: Any) {
|
||||||
delegate?.cancel()
|
delegate?.cancelSave()
|
||||||
cancelButton.isEnabled = false
|
cancelButton.isEnabled = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user