feat: adopt a two-pane start screen

This commit is contained in:
2026-10-18 22:50:24 +02:00
parent 4b9436c04a
commit a6fa54fc42
5 changed files with 218 additions and 90 deletions
+22
View File
@@ -1,6 +1,12 @@
import Foundation
struct PlaybackProgress {
struct RecentMedia: Equatable, Identifiable {
let url: URL
let title: String
var id: URL { url }
}
private let defaults: UserDefaults
init(defaults: UserDefaults = .standard) {
@@ -28,6 +34,22 @@ struct PlaybackProgress {
defaults.set(position, forKey: key)
}
var recentMedia: [RecentMedia] {
(defaults.array(forKey: "recentMedia") as? [[String: String]] ?? []).compactMap {
guard let text = $0["url"], let url = URL(string: text), let title = $0["title"] else { return nil }
return RecentMedia(url: url, title: title)
}
}
func recordRecent(_ url: URL, title: String) {
let url = url.isFileURL ? url.standardizedFileURL.resolvingSymlinksInPath() : url
var entries = recentMedia
entries.removeAll { $0.url == url }
entries.insert(RecentMedia(url: url, title: title), at: 0)
defaults.set(entries.prefix(6).map { ["url": $0.url.absoluteString, "title": $0.title] },
forKey: "recentMedia")
}
private func key(for url: URL) -> String {
// YouTube callers supply the canonical webpage URL, never an expiring media URL.
return "playbackPosition:" + (url.isFileURL ? url.standardizedFileURL.resolvingSymlinksInPath().absoluteString : url.absoluteString)