fix crash because currentPage and currentChapter were yet to be set
This commit is contained in:
@@ -251,11 +251,11 @@ class ViewController: UIViewController, UIGestureRecognizerDelegate {
|
||||
try String(
|
||||
contentsOfFile: currentPath.appendingPathComponent("state.json").path
|
||||
).utf8)
|
||||
let l = try JSONDecoder().decode(LocalState.self, from: json)
|
||||
currentPage = l.page
|
||||
currentChapter = l.chapter
|
||||
mode = l.turnMode
|
||||
readerView.backgroundColor = convertStringToColor(str: l.backgroundColor)
|
||||
let local = try JSONDecoder().decode(LocalState.self, from: json)
|
||||
currentPage = local.page
|
||||
currentChapter = local.chapter
|
||||
mode = local.turnMode
|
||||
readerView.backgroundColor = convertStringToColor(str: local.backgroundColor)
|
||||
} catch {
|
||||
print("failed to load local state")
|
||||
}
|
||||
@@ -693,8 +693,8 @@ class ViewController: UIViewController, UIGestureRecognizerDelegate {
|
||||
info.text = """
|
||||
\(metadata.title)
|
||||
\(metadata.chapters[currentChapter - 1].title)
|
||||
Volume \(Int(metadata.chapters[currentChapter - 1].volume)) of \(Int(metadata.chapters.last!.volume))
|
||||
Chapter \(currentChapter!) of \(Int(metadata.chapters.last!.chapter))
|
||||
Volume \(Int(metadata.chapters[currentChapter - 1].volume)) of \(Int(metadata.last_volume))
|
||||
Chapter \(currentChapter!) of \(Int(metadata.last_chapter))
|
||||
Page \(currentPage!) of \(metadata.chapters[currentChapter - 1].pages)
|
||||
Image size: \(Int(imageView.image!.size.width))x\(Int(imageView.image!.size.height))
|
||||
"""
|
||||
@@ -814,7 +814,6 @@ class ViewController: UIViewController, UIGestureRecognizerDelegate {
|
||||
let ps: [String] = try fileManager.contentsOfDirectory(atPath: dir.path).sorted()
|
||||
let current = dir.appendingPathComponent(ps[0])
|
||||
imageView.image = UIImage(contentsOfFile: current.path)
|
||||
updateInfo()
|
||||
|
||||
let path_meta = current.lastPathComponent.components(separatedBy: "_")
|
||||
assert(path_meta[0] == "chapter")
|
||||
@@ -829,6 +828,7 @@ class ViewController: UIViewController, UIGestureRecognizerDelegate {
|
||||
assert(path_meta[2] == "image")
|
||||
currentPage = Int(path_meta[3].components(separatedBy: ".")[0])! + 1
|
||||
}
|
||||
updateInfo()
|
||||
} catch {
|
||||
print("failed to set images")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user