Phase 6: Live-TV, plus Live Activity für Downloads
Live-TV - An keinem echten Server geprüft: die DVR- und EPG-Endpunkte sind der am schlechtesten dokumentierte Teil der Plex-API. Die Modelle sind deshalb durchgehend nachsichtig — fehlende Felder ergeben leere Listen, nicht Fehler, und die Senderkennung wird als Zahl, Zeichenkette oder uuid akzeptiert. - Ohne eingerichteten Empfänger erklärt die App das, statt einen Fehler zu zeigen. Das ist der häufigste Fall. - Senderliste mit laufender Sendung, Fortschrittsbalken und „danach". Der Programmführer wird getrennt geholt: fällt er aus, bleibt das Umschalten möglich. - Die Anbieterkennung wird aus /media/providers gelesen statt fest verdrahtet — sie wechselt je nach Server. Live Activity - Eigene Widget-Erweiterung; iOS zeichnet den Sperrbildschirm in einem getrennten Prozess, während die App meist gar nicht läuft. - Der Presenter drosselt auf 1,5 Sekunden. ActivityKit verwirft zu häufige Aktualisierungen kommentarlos, und der Fortschritt kommt mehrmals je Sekunde — ungebremst bliebe die Anzeige stehen. - @preconcurrency import: Activity und ActivityContent tragen keine Sendable-Zusage. Zwei Stolpersteine unterwegs: canImport(ActivityKit) ist auf macOS wahr, die Typen darin aber nicht verfügbar — es muss os(iOS) sein. Und eine von Hand geschriebene Info.plist ohne CFBundleIdentifier führt zu einer Erweiterung ganz ohne Kennung; der Fehler lautet dann „not prefixed with the parent app's bundle identifier" und zeigt auf die falsche Stelle. 126 Tests. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
import ActivityKit
|
||||
import SwiftUI
|
||||
import WidgetKit
|
||||
import FlixyDesign
|
||||
import FlixyDownloads
|
||||
|
||||
/// Der Download-Fortschritt im Sperrbildschirm und in der Dynamic Island.
|
||||
struct DownloadLiveActivity: Widget {
|
||||
var body: some WidgetConfiguration {
|
||||
ActivityConfiguration(for: DownloadActivityAttributes.self) { context in
|
||||
lockScreen(context.state)
|
||||
// Die Erweiterung liest die Akzentfarbe nicht: sie läuft in
|
||||
// einem eigenen Prozess ohne Zugriff auf die Voreinstellungen
|
||||
// der App. Ein Gruppen-Container wäre der Weg dafür — für
|
||||
// eine Fortschrittsanzeige ist das mehr Aufwand als Nutzen.
|
||||
.tint(.white)
|
||||
} dynamicIsland: { context in
|
||||
DynamicIsland {
|
||||
DynamicIslandExpandedRegion(.leading) {
|
||||
Image(systemName: "arrow.down.circle.fill")
|
||||
.foregroundStyle(.white)
|
||||
}
|
||||
DynamicIslandExpandedRegion(.center) {
|
||||
Text(context.state.title)
|
||||
.font(.caption)
|
||||
.lineLimit(1)
|
||||
}
|
||||
DynamicIslandExpandedRegion(.bottom) {
|
||||
progressBar(context.state)
|
||||
}
|
||||
} compactLeading: {
|
||||
Image(systemName: "arrow.down")
|
||||
} compactTrailing: {
|
||||
if let progress = context.state.progress {
|
||||
Text(progress.formatted(.percent.precision(.fractionLength(0))))
|
||||
.font(.caption2)
|
||||
.monospacedDigit()
|
||||
}
|
||||
} minimal: {
|
||||
Image(systemName: "arrow.down")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func lockScreen(_ state: DownloadActivityAttributes.ContentState) -> some View {
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
HStack {
|
||||
Label(state.title, systemImage: "arrow.down.circle")
|
||||
.font(.headline)
|
||||
.lineLimit(1)
|
||||
Spacer()
|
||||
if state.remainingCount > 0 {
|
||||
Text("+\(state.remainingCount)")
|
||||
.font(.caption)
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
}
|
||||
|
||||
progressBar(state)
|
||||
|
||||
HStack {
|
||||
Text(state.receivedBytes.formatted(.byteCount(style: .file)))
|
||||
Spacer()
|
||||
if state.totalBytes > 0 {
|
||||
Text(state.totalBytes.formatted(.byteCount(style: .file)))
|
||||
}
|
||||
}
|
||||
.font(.caption2)
|
||||
.monospacedDigit()
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
.padding()
|
||||
.activityBackgroundTint(Color(red: 0.05, green: 0.05, blue: 0.06))
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
private func progressBar(_ state: DownloadActivityAttributes.ContentState) -> some View {
|
||||
// Ohne bekannte Gesamtgröße ein unbestimmter Balken: einer bei null
|
||||
// Prozent, der sich nie bewegt, sieht im Sperrbildschirm aus wie ein
|
||||
// hängender Download.
|
||||
if let progress = state.progress {
|
||||
ProgressView(value: progress)
|
||||
} else {
|
||||
ProgressView()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import SwiftUI
|
||||
import WidgetKit
|
||||
|
||||
@main
|
||||
struct DownloadWidgetBundle: WidgetBundle {
|
||||
var body: some Widget {
|
||||
DownloadLiveActivity()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>$(DEVELOPMENT_LANGUAGE)</string>
|
||||
<key>CFBundleDisplayName</key>
|
||||
<string>Flixy Downloads</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>$(EXECUTABLE_NAME)</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>$(PRODUCT_NAME)</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>XPC!</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.0</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1</string>
|
||||
<key>NSExtension</key>
|
||||
<dict>
|
||||
<key>NSExtensionPointIdentifier</key>
|
||||
<string>com.apple.widgetkit-extension</string>
|
||||
</dict>
|
||||
</dict>
|
||||
</plist>
|
||||
Reference in New Issue
Block a user