Always call handler in thumbnail and quicklook generation (#4)
This commit is contained in:
parent
5507416556
commit
c0f47191be
2 changed files with 13 additions and 7 deletions
|
@ -15,16 +15,18 @@ class PreviewViewController: NSViewController, QLPreviewingController {
|
||||||
fc.coordinate(with: [intent], queue: .main) { (err) in
|
fc.coordinate(with: [intent], queue: .main) { (err) in
|
||||||
if err == nil {
|
if err == nil {
|
||||||
do {
|
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 {
|
guard let archive = Archive(data: try Data(contentsOf: intent.url), accessMode: Archive.AccessMode.read) else {
|
||||||
return
|
throw standardError
|
||||||
}
|
}
|
||||||
|
|
||||||
guard let entry = archive[ThumbnailPath] else {
|
guard let entry = archive[ThumbnailPath] else {
|
||||||
return
|
throw standardError
|
||||||
}
|
}
|
||||||
|
|
||||||
guard let thumbnailData = readData(archive: archive, entry: entry) else {
|
guard let thumbnailData = readData(archive: archive, entry: entry) else {
|
||||||
return
|
throw standardError
|
||||||
}
|
}
|
||||||
|
|
||||||
self.imageView?.image = NSImage(data: thumbnailData)
|
self.imageView?.image = NSImage(data: thumbnailData)
|
||||||
|
@ -32,9 +34,11 @@ class PreviewViewController: NSViewController, QLPreviewingController {
|
||||||
handler(nil)
|
handler(nil)
|
||||||
} catch {
|
} catch {
|
||||||
NSLog("Could not load file \(intent.url.lastPathComponent) to preview it")
|
NSLog("Could not load file \(intent.url.lastPathComponent) to preview it")
|
||||||
|
handler(err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
NSLog("Could not find file \(intent.url.lastPathComponent) to preview it")
|
NSLog("Could not find file \(intent.url.lastPathComponent) to preview it")
|
||||||
|
handler(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,17 +4,19 @@ import Cocoa
|
||||||
|
|
||||||
class ThumbnailProvider: QLThumbnailProvider {
|
class ThumbnailProvider: QLThumbnailProvider {
|
||||||
override func provideThumbnail(for request: QLFileThumbnailRequest, _ handler: @escaping (QLThumbnailReply?, Error?) -> Void) {
|
override func provideThumbnail(for request: QLFileThumbnailRequest, _ handler: @escaping (QLThumbnailReply?, Error?) -> Void) {
|
||||||
|
let standardError = NSError(domain: "procreate-viewer", code: 1, userInfo: nil)
|
||||||
|
|
||||||
do {
|
do {
|
||||||
guard let archive = Archive(data: try Data(contentsOf: request.fileURL), accessMode: Archive.AccessMode.read) else {
|
guard let archive = Archive(data: try Data(contentsOf: request.fileURL), accessMode: Archive.AccessMode.read) else {
|
||||||
return
|
throw standardError
|
||||||
}
|
}
|
||||||
|
|
||||||
guard let entry = archive[ThumbnailPath] else {
|
guard let entry = archive[ThumbnailPath] else {
|
||||||
return
|
throw standardError
|
||||||
}
|
}
|
||||||
|
|
||||||
guard let thumbnailData = readData(archive: archive, entry: entry) else {
|
guard let thumbnailData = readData(archive: archive, entry: entry) else {
|
||||||
return
|
throw standardError
|
||||||
}
|
}
|
||||||
|
|
||||||
let image = NSImage(data: thumbnailData)
|
let image = NSImage(data: thumbnailData)
|
||||||
|
@ -51,7 +53,7 @@ class ThumbnailProvider: QLThumbnailProvider {
|
||||||
handler(reply, nil)
|
handler(reply, nil)
|
||||||
} catch {
|
} catch {
|
||||||
NSLog("Could not access file \(request.fileURL.lastPathComponent) to preview it")
|
NSLog("Could not access file \(request.fileURL.lastPathComponent) to preview it")
|
||||||
handler(nil, nil)
|
handler(nil, standardError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue