diff --git a/Classes/Document.swift b/Classes/Document.swift index 75fcc4b..c465899 100644 --- a/Classes/Document.swift +++ b/Classes/Document.swift @@ -11,16 +11,19 @@ import IOKit.pwr_mgt @objc(SBDocument) class Document: NSDocument { var mp4: MP42File + var unsupportedMp4Brand: Bool override init() { self.options = [:] self.optimize = false + self.unsupportedMp4Brand = false self.mp4 = MP42File() } @objc init(mp4: MP42File) throws { self.options = [:] self.optimize = false + self.unsupportedMp4Brand = false self.mp4 = mp4 super.init() @@ -35,6 +38,12 @@ import IOKit.pwr_mgt let documentWindowController = DocumentWindowController() addWindowController(documentWindowController) documentWindowController.showWindow(self) + + if let url = fileURL, unsupportedMp4Brand { + // We can't edit this file, so ask the user if it wants to import it + documentWindowController.showImportSheet(fileURLs: [url]) + fileURL = nil + } } // MARK: Read @@ -44,7 +53,12 @@ import IOKit.pwr_mgt override open var isEntireFileLoaded: Bool { get { return false } } override func read(from url: URL, ofType typeName: String) throws { - mp4 = try MP42File(url: url) + do { + mp4 = try MP42File(url: url) + } + catch { + unsupportedMp4Brand = true + } } override func revert(toContentsOf url: URL, ofType typeName: String) throws { diff --git a/Classes/DocumentWindowController.swift b/Classes/DocumentWindowController.swift index 678d656..ed59c23 100644 --- a/Classes/DocumentWindowController.swift +++ b/Classes/DocumentWindowController.swift @@ -537,7 +537,6 @@ class DocumentWindowController: NSWindowController, TracksViewControllerDelegate } } - @objc func showImportSheet(fileURLs: [URL]) { do { let controller = try FileImportController(fileURLs: fileURLs, delegate: self) diff --git a/Classes/SBAppDelegate.m b/Classes/SBAppDelegate.m index c9b24df..970b999 100644 --- a/Classes/SBAppDelegate.m +++ b/Classes/SBAppDelegate.m @@ -284,10 +284,7 @@ - (nullable __kindof NSDocument *)documentForURL:(NSURL *)url { - NSArray<__kindof NSDocument *> *documents = nil; - @synchronized(self) { - documents = [self.documents copy]; - } + NSArray<__kindof NSDocument *> *documents = [self.documents copy]; for (NSDocument *doc in documents) { if ([doc.fileURL isEqualTo:url.filePathURL]) {