Fixed chapters not loading (#216)

* hey

* mediainfoview fixed chapters not loading

* added back that

* ts annoying 🥀
This commit is contained in:
ibro 2025-07-06 15:53:07 +02:00 committed by GitHub
parent 508dcd4a42
commit 5d0c3fd977
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -209,7 +209,7 @@ struct MediaInfoView: View {
currentFetchTask?.cancel() currentFetchTask?.cancel()
activeFetchID = nil activeFetchID = nil
UserDefaults.standard.set(false, forKey: "isMediaInfoActive") UserDefaults.standard.set(false, forKey: "isMediaInfoActive")
UIScrollView.appearance().bounces = true UIScrollView.appearance().bounces = true
} }
.task { .task {
await setupInitialData() await setupInitialData()
@ -239,7 +239,7 @@ struct MediaInfoView: View {
private var navigationOverlay: some View { private var navigationOverlay: some View {
VStack { VStack {
HStack { HStack {
Button(action: { Button(action: {
dismiss() dismiss()
}) { }) {
Image(systemName: "chevron.left") Image(systemName: "chevron.left")
@ -729,7 +729,7 @@ struct MediaInfoView: View {
LazyVStack(spacing: 15) { LazyVStack(spacing: 15) {
ForEach(chapters.indices.filter { selectedChapterRange.contains($0) }, id: \..self) { i in ForEach(chapters.indices.filter { selectedChapterRange.contains($0) }, id: \..self) { i in
let chapter = chapters[i] let chapter = chapters[i]
let _ = refreshTrigger let _ = refreshTrigger
if let href = chapter["href"] as? String, if let href = chapter["href"] as? String,
let number = chapter["number"] as? Int, let number = chapter["number"] as? Int,
let title = chapter["title"] as? String { let title = chapter["title"] as? String {
@ -751,7 +751,7 @@ struct MediaInfoView: View {
ChapterCell( ChapterCell(
chapterNumber: String(number), chapterNumber: String(number),
chapterTitle: title, chapterTitle: title,
isCurrentChapter: false, isCurrentChapter: false,
progress: UserDefaults.standard.double(forKey: "readingProgress_\(href)"), progress: UserDefaults.standard.double(forKey: "readingProgress_\(href)"),
href: href href: href
) )
@ -868,7 +868,7 @@ struct MediaInfoView: View {
.sheet(isPresented: $isMatchingPresented) { .sheet(isPresented: $isMatchingPresented) {
AnilistMatchPopupView(seriesTitle: title) { id, matched in AnilistMatchPopupView(seriesTitle: title) { id, matched in
handleAniListMatch(selectedID: id) handleAniListMatch(selectedID: id)
matchedTitle = matched matchedTitle = matched
fetchMetadataIDIfNeeded() fetchMetadataIDIfNeeded()
} }
} }
@ -876,7 +876,7 @@ struct MediaInfoView: View {
TMDBMatchPopupView(seriesTitle: title) { id, type, matched in TMDBMatchPopupView(seriesTitle: title) { id, type, matched in
tmdbID = id tmdbID = id
tmdbType = type tmdbType = type
matchedTitle = matched matchedTitle = matched
fetchMetadataIDIfNeeded() fetchMetadataIDIfNeeded()
} }
} }
@ -973,8 +973,6 @@ struct MediaInfoView: View {
await withTaskGroup(of: Void.self) { group in await withTaskGroup(of: Void.self) { group in
var chaptersLoaded = false var chaptersLoaded = false
var detailsLoaded = false var detailsLoaded = false
let timeout: TimeInterval = 8.0
let start = Date()
group.addTask { group.addTask {
let fetchedChapters = try? await JSController.shared.extractChapters(moduleId: module.id.uuidString, href: href) let fetchedChapters = try? await JSController.shared.extractChapters(moduleId: module.id.uuidString, href: href)
@ -997,9 +995,6 @@ struct MediaInfoView: View {
if !(self.synopsis.isEmpty && self.aliases.isEmpty && self.airdate.isEmpty) { if !(self.synopsis.isEmpty && self.aliases.isEmpty && self.airdate.isEmpty) {
detailsLoaded = true detailsLoaded = true
continuation.resume() continuation.resume()
} else if Date().timeIntervalSince(start) > timeout {
detailsLoaded = true
continuation.resume()
} else { } else {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
checkDetails() checkDetails()
@ -1010,13 +1005,6 @@ struct MediaInfoView: View {
checkDetails() checkDetails()
} }
} }
group.addTask {
try? await Task.sleep(nanoseconds: UInt64(timeout * 1_000_000_000))
await MainActor.run {
chaptersLoaded = true
detailsLoaded = true
}
}
while true { while true {
let loaded = await MainActor.run { chaptersLoaded && detailsLoaded } let loaded = await MainActor.run { chaptersLoaded && detailsLoaded }
if loaded { break } if loaded { break }