Compare commits

..

3 Commits

Author SHA1 Message Date
2e5348cc97 feat: fix detail 2026-02-27 13:50:32 +08:00
bcfee96fa9 Merge branch 'main' into feature_tvOS 2026-02-27 11:35:24 +08:00
1da412e637 fix: 修复详情页空白和海报图片错误
- DetailViewModel 添加 @MainActor 确保状态更新在主线程
- DetailView 消除空白初始状态,ProgressView 作为默认兜底
- 取消时保留加载状态避免页面闪回空白
- 使用 .task(id:) 确保切换条目时任务重新触发
- 海报优先从 JSON-LD image 字段获取,HTML fallback 改用正确选择器

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-27 11:33:22 +08:00
9 changed files with 88 additions and 21 deletions

View File

@@ -21,7 +21,11 @@
"Bash(killall xcodebuild:*)", "Bash(killall xcodebuild:*)",
"Bash(cp:*)", "Bash(cp:*)",
"Bash(pkill:*)", "Bash(pkill:*)",
"Bash(git:*)" "Bash(git:*)",
"Bash(xcrun simctl:*)",
"Bash(xcrun devicectl:*)",
"Bash(networksetup:*)",
"Bash(system_profiler SPNetworkDataType:*)"
] ]
} }
} }

View File

@@ -93,10 +93,6 @@ enum HTMLParser {
let h1 = try doc.select("h1").first() let h1 = try doc.select("h1").first()
let fullTitle = try h1?.text().trimmingCharacters(in: .whitespacesAndNewlines) ?? "未知标题" let fullTitle = try h1?.text().trimmingCharacters(in: .whitespacesAndNewlines) ?? "未知标题"
//
let imgSrc = try doc.select("img.w-full.h-full.object-cover").first()?.attr("src") ?? ""
let posterURL = URL(string: imgSrc)
// === JSON-LD === // === JSON-LD ===
var year = 0 var year = 0
var rating: Double? var rating: Double?
@@ -105,12 +101,17 @@ enum HTMLParser {
var genres: [String] = [] var genres: [String] = []
var description = "" var description = ""
var region = "" var region = ""
var posterURL: URL?
if let jsonLDScript = try doc.select("script[type=application/ld+json]").first() { if let jsonLDScript = try doc.select("script[type=application/ld+json]").first() {
let jsonText = try jsonLDScript.data() let jsonText = try jsonLDScript.data()
if let data = jsonText.data(using: .utf8), if let data = jsonText.data(using: .utf8),
let json = try? JSONSerialization.jsonObject(with: data) as? [String: Any] { let json = try? JSONSerialization.jsonObject(with: data) as? [String: Any] {
if let imageStr = json["image"] as? String {
posterURL = URL(string: imageStr)
}
if let published = json["datePublished"] as? String { if let published = json["datePublished"] as? String {
year = Int(published) ?? 0 year = Int(published) ?? 0
} }
@@ -140,6 +141,12 @@ enum HTMLParser {
// === HTML === // === HTML ===
// fallback: .flex-shrink-0
if posterURL == nil {
let imgSrc = try doc.select(".flex-shrink-0 img.object-cover").first()?.attr("src") ?? ""
posterURL = URL(string: imgSrc)
}
// fallback // fallback
if rating == nil { if rating == nil {
let ratingText = try doc.select(".rating-display").text() let ratingText = try doc.select(".rating-display").text()

View File

@@ -1,6 +1,6 @@
import Foundation import Foundation
@Observable @Observable @MainActor
final class DetailViewModel { final class DetailViewModel {
var detail: ContentDetail? var detail: ContentDetail?
var selectedSourceIndex = 0 var selectedSourceIndex = 0
@@ -27,23 +27,22 @@ final class DetailViewModel {
func loadDetail(path: String) async { func loadDetail(path: String) async {
isLoading = true isLoading = true
error = nil error = nil
defer { isLoading = false }
do { do {
let html = try await APIClient.shared.fetchDetailPage(path: path) let html = try await APIClient.shared.fetchDetailPage(path: path)
let parsedDetail = try HTMLParser.parseContentDetail(html: html) let parsedDetail = try HTMLParser.parseContentDetail(html: html)
await MainActor.run { self.detail = parsedDetail
self.detail = parsedDetail self.selectedSourceIndex = 0
self.selectedSourceIndex = 0 self.selectedEpisodeIndex = 0
self.selectedEpisodeIndex = 0
}
} catch is CancellationError { } catch is CancellationError {
// loading
return return
} catch let error as URLError where error.code == .cancelled { } catch let error as URLError where error.code == .cancelled {
return return
} catch { } catch {
await MainActor.run { self.error = error.localizedDescription } self.error = error.localizedDescription
} }
isLoading = false
} }
func selectSource(_ index: Int) { func selectSource(_ index: Int) {

View File

@@ -14,9 +14,14 @@ struct CookieInputView: View {
} }
Section("Cookie") { Section("Cookie") {
#if os(tvOS)
TextField("粘贴 Cookie...", text: $cookieText)
.font(.system(.body, design: .monospaced))
#else
TextEditor(text: $cookieText) TextEditor(text: $cookieText)
.font(.system(.body, design: .monospaced)) .font(.system(.body, design: .monospaced))
.frame(minHeight: 120) .frame(minHeight: 120)
#endif
} }
Section { Section {

View File

@@ -16,22 +16,22 @@ struct DetailView: View {
var body: some View { var body: some View {
Group { Group {
if viewModel.isLoading { if let detail = viewModel.detail {
ProgressView()
.frame(maxWidth: .infinity, maxHeight: .infinity)
} else if let error = viewModel.error {
errorView(error)
} else if let detail = viewModel.detail {
ScrollView { ScrollView {
detailContent(detail) detailContent(detail)
} }
} else if let error = viewModel.error {
errorView(error)
} else {
ProgressView()
.frame(maxWidth: .infinity, maxHeight: .infinity)
} }
} }
.navigationTitle(item.title) .navigationTitle(item.title)
#if os(iOS) #if os(iOS)
.navigationBarTitleDisplayMode(.inline) .navigationBarTitleDisplayMode(.inline)
#endif #endif
.task { .task(id: item.id) {
if viewModel.detail == nil { if viewModel.detail == nil {
await viewModel.loadDetail(path: item.detailURL) await viewModel.loadDetail(path: item.detailURL)
} }

View File

@@ -93,6 +93,7 @@ struct AppNavigation: View {
} }
} }
#if !os(tvOS)
private var sidebarLayout: some View { private var sidebarLayout: some View {
NavigationSplitView { NavigationSplitView {
List(AppTab.visibleTabs, selection: $selectedTab) { tab in List(AppTab.visibleTabs, selection: $selectedTab) { tab in
@@ -106,6 +107,7 @@ struct AppNavigation: View {
} }
} }
} }
#endif
@ViewBuilder @ViewBuilder
private func tabContent(for tab: AppTab) -> some View { private func tabContent(for tab: AppTab) -> some View {

Submodule LocalPackages/SwiftSoup updated: 8b6cf29eea...e98a6d63ce

23
Package.resolved Normal file
View File

@@ -0,0 +1,23 @@
{
"pins" : [
{
"identity" : "lrucache",
"kind" : "remoteSourceControl",
"location" : "https://github.com/nicklockwood/LRUCache.git",
"state" : {
"revision" : "cb5b2bd0da83ad29c0bec762d39f41c8ad0eaf3e",
"version" : "1.2.1"
}
},
{
"identity" : "swift-atomics",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-atomics.git",
"state" : {
"revision" : "b601256eab081c0f92f059e12818ac1d4f178ff7",
"version" : "1.3.0"
}
}
],
"version" : 2
}

View File

@@ -4,6 +4,7 @@ options:
deploymentTarget: deploymentTarget:
iOS: "17.0" iOS: "17.0"
macOS: "14.0" macOS: "14.0"
tvOS: "17.0"
xcodeVersion: "16.0" xcodeVersion: "16.0"
groupSortPosition: top groupSortPosition: top
createIntermediateGroups: true createIntermediateGroups: true
@@ -32,6 +33,26 @@ targets:
INFOPLIST_KEY_CFBundleDisplayName: DDYS INFOPLIST_KEY_CFBundleDisplayName: DDYS
CODE_SIGN_ENTITLEMENTS: DDYSClient/DDYSClient.entitlements CODE_SIGN_ENTITLEMENTS: DDYSClient/DDYSClient.entitlements
DDYSClient-tvOS:
type: application
platform: tvOS
sources:
- path: DDYSClient
resources:
- path: Resources
optional: true
dependencies:
- package: SwiftSoup
settings:
base:
PRODUCT_BUNDLE_IDENTIFIER: com.fusion.ddys.client
MARKETING_VERSION: "1.0.0"
CURRENT_PROJECT_VERSION: 1
SWIFT_VERSION: "5.9"
GENERATE_INFOPLIST_FILE: YES
INFOPLIST_KEY_CFBundleDisplayName: 低端影视
INFOPLIST_KEY_UILaunchScreen_Generation: YES
schemes: schemes:
DDYSClient: DDYSClient:
build: build:
@@ -39,3 +60,9 @@ schemes:
DDYSClient: all DDYSClient: all
run: run:
config: Debug config: Debug
DDYSClient-tvOS:
build:
targets:
DDYSClient-tvOS: all
run:
config: Debug