perf: load comics async #40
@@ -249,27 +249,27 @@ final class ViewController: UIViewController, UIGestureRecognizerDelegate {
|
||||
preferredStyle: .alert
|
||||
)
|
||||
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
|
||||
do {
|
||||
var directories: [URL] = []
|
||||
var directories: [URL] = []
|
||||
|
||||
guard let contents = try? fileManager.contentsOfDirectory(
|
||||
at: documentsURL,
|
||||
includingPropertiesForKeys: [.isDirectoryKey],
|
||||
options: [.skipsHiddenFiles]
|
||||
)
|
||||
else {
|
||||
alert.message = String(format: "Failed to read contents of directory: \(documentsURL)")
|
||||
pendingAlert = alert
|
||||
return
|
||||
}
|
||||
guard let contents = try? fileManager.contentsOfDirectory(
|
||||
at: documentsURL,
|
||||
includingPropertiesForKeys: [.isDirectoryKey],
|
||||
options: [.skipsHiddenFiles]
|
||||
)
|
||||
else {
|
||||
alert.message = String(format: "Failed to read contents of directory: \(documentsURL)")
|
||||
pendingAlert = alert
|
||||
return
|
||||
}
|
||||
|
||||
directories = contents.filter { url in
|
||||
var isDirectory: ObjCBool = false
|
||||
return fileManager.fileExists(atPath: url.path, isDirectory: &isDirectory)
|
||||
&& isDirectory.boolValue
|
||||
}.sorted { $0.path < $1.path }
|
||||
directories = contents.filter { url in
|
||||
var isDirectory: ObjCBool = false
|
||||
return fileManager.fileExists(atPath: url.path, isDirectory: &isDirectory)
|
||||
&& isDirectory.boolValue
|
||||
}.sorted { $0.path < $1.path }
|
||||
|
||||
for dir in directories {
|
||||
for dir in directories {
|
||||
queue.async { [self] in
|
||||
if !fileManager.fileExists(atPath: dir.appendingPathComponent(metadataFilename).path) {
|
||||
getMetadataFromFilename(path: dir)
|
||||
if pendingAlert != nil {
|
||||
@@ -298,7 +298,15 @@ final class ViewController: UIViewController, UIGestureRecognizerDelegate {
|
||||
loadLocalState()
|
||||
let volCovP = ProgressIndices(v: state[currentPath.lastPathComponent]!.progress.v, c: 0, i: 0)
|
||||
let archivePath = getArchiveURL(volCovP.v)
|
||||
let archive = try Archive(url: archivePath, accessMode: .read)
|
||||
let archive: Archive!
|
||||
do {
|
||||
let a = try Archive(url: archivePath, accessMode: .read)
|
||||
archive = a
|
||||
} catch {
|
||||
alert.message = String(format: "Could not open Archive: \(archivePath)")
|
||||
pendingAlert = alert
|
||||
return
|
||||
}
|
||||
let filename = metadata.volumes[volCovP.v].chapters[volCovP.c].images[volCovP.i].filename!
|
||||
guard let targetEntry = archive[filename] else {
|
||||
alert.message = String(format: "Archive entry does not exist: \(filename)")
|
||||
@@ -327,11 +335,10 @@ final class ViewController: UIViewController, UIGestureRecognizerDelegate {
|
||||
path: dir
|
||||
)
|
||||
)
|
||||
DispatchQueue.main.async {
|
||||
self.comicCollectionView.reloadData()
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
pendingAlert = alert
|
||||
alert.message = String(format: "Generic failure.")
|
||||
print("Failed to read directories")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user