1
Fork 0

Always call handler in thumbnail and quicklook generation (#4)

This commit is contained in:
Joshua Goins 2021-06-14 12:17:58 -04:00 committed by redstrate
parent 5507416556
commit c0f47191be
2 changed files with 13 additions and 7 deletions

View file

@ -15,16 +15,18 @@ class PreviewViewController: NSViewController, QLPreviewingController {
fc.coordinate(with: [intent], queue: .main) { (err) in
if err == nil {
do {
let standardError = NSError(domain: "procreate-viewer", code: 1, userInfo: nil)
guard let archive = Archive(data: try Data(contentsOf: intent.url), accessMode: Archive.AccessMode.read) else {
return
throw standardError
}
guard let entry = archive[ThumbnailPath] else {
return
throw standardError
}
guard let thumbnailData = readData(archive: archive, entry: entry) else {
return
throw standardError
}
self.imageView?.image = NSImage(data: thumbnailData)
@ -32,9 +34,11 @@ class PreviewViewController: NSViewController, QLPreviewingController {
handler(nil)
} catch {
NSLog("Could not load file \(intent.url.lastPathComponent) to preview it")
handler(err)
}
} else {
NSLog("Could not find file \(intent.url.lastPathComponent) to preview it")
handler(err)
}
}
}

View file

@ -4,17 +4,19 @@ import Cocoa
class ThumbnailProvider: QLThumbnailProvider {
override func provideThumbnail(for request: QLFileThumbnailRequest, _ handler: @escaping (QLThumbnailReply?, Error?) -> Void) {
let standardError = NSError(domain: "procreate-viewer", code: 1, userInfo: nil)
do {
guard let archive = Archive(data: try Data(contentsOf: request.fileURL), accessMode: Archive.AccessMode.read) else {
return
throw standardError
}
guard let entry = archive[ThumbnailPath] else {
return
throw standardError
}
guard let thumbnailData = readData(archive: archive, entry: entry) else {
return
throw standardError
}
let image = NSImage(data: thumbnailData)
@ -51,7 +53,7 @@ class ThumbnailProvider: QLThumbnailProvider {
handler(reply, nil)
} catch {
NSLog("Could not access file \(request.fileURL.lastPathComponent) to preview it")
handler(nil, nil)
handler(nil, standardError)
}
}
}