mirror of
https://github.com/yattee/yattee.git
synced 2025-08-09 04:04:07 +00:00
Persistence for queue, history and last played
This commit is contained in:
@@ -29,6 +29,10 @@ extension Defaults.Keys {
|
||||
|
||||
static let recentlyOpened = Key<[RecentItem]>("recentlyOpened", default: [])
|
||||
|
||||
static let queue = Key<[PlayerQueueItem]>("queue", default: [])
|
||||
static let history = Key<[PlayerQueueItem]>("history", default: [])
|
||||
static let lastPlayed = Key<PlayerQueueItem?>("lastPlayed")
|
||||
|
||||
static let trendingCategory = Key<TrendingCategory>("trendingCategory", default: .default)
|
||||
static let trendingCountry = Key<Country>("trendingCountry", default: .us)
|
||||
}
|
||||
|
@@ -111,6 +111,10 @@ struct ContentView: View {
|
||||
playlists.accounts = accounts
|
||||
search.accounts = accounts
|
||||
subscriptions.accounts = accounts
|
||||
|
||||
if !accounts.current.isNil {
|
||||
player.loadHistoryDetails()
|
||||
}
|
||||
}
|
||||
|
||||
func openWelcomeScreenIfAccountEmpty() {
|
||||
@@ -135,6 +139,7 @@ struct ContentView: View {
|
||||
|
||||
accounts.api.video(id).load().onSuccess { response in
|
||||
if let video: Video = response.typedContent() {
|
||||
self.player.autoPlayItems = true
|
||||
self.player.playNow(video, at: parser.time)
|
||||
self.player.presentPlayer()
|
||||
}
|
||||
|
@@ -24,7 +24,7 @@ struct PlaybackBar: View {
|
||||
if !player.lastSkipped.isNil {
|
||||
restoreLastSkippedSegmentButton
|
||||
}
|
||||
if player.currentVideo!.live {
|
||||
if player.live {
|
||||
Image(systemName: "dot.radiowaves.left.and.right")
|
||||
} else if player.isLoadingAvailableStreams || player.isLoadingStream {
|
||||
Image(systemName: "bolt.horizontal.fill")
|
||||
@@ -78,7 +78,7 @@ struct PlaybackBar: View {
|
||||
return "LIVE"
|
||||
}
|
||||
|
||||
guard player.time != nil, player.time!.isValid else {
|
||||
guard player.time != nil, player.time!.isValid, !player.currentVideo.isNil else {
|
||||
return "loading..."
|
||||
}
|
||||
|
||||
|
@@ -4,11 +4,11 @@ import SDWebImageSwiftUI
|
||||
import SwiftUI
|
||||
|
||||
struct VideoBanner: View {
|
||||
let video: Video
|
||||
let video: Video?
|
||||
var playbackTime: CMTime?
|
||||
var videoDuration: TimeInterval?
|
||||
|
||||
init(video: Video, playbackTime: CMTime? = nil, videoDuration: TimeInterval? = nil) {
|
||||
init(video: Video? = nil, playbackTime: CMTime? = nil, videoDuration: TimeInterval? = nil) {
|
||||
self.video = video
|
||||
self.playbackTime = playbackTime
|
||||
self.videoDuration = videoDuration
|
||||
@@ -24,14 +24,14 @@ struct VideoBanner: View {
|
||||
#endif
|
||||
}
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
Text(video.title)
|
||||
Text(video?.title ?? "Unknown title")
|
||||
.truncationMode(.middle)
|
||||
.lineLimit(2)
|
||||
.font(.headline)
|
||||
.frame(alignment: .leading)
|
||||
|
||||
HStack {
|
||||
Text(video.author)
|
||||
Text(video?.author ?? "Unknown author")
|
||||
.lineLimit(1)
|
||||
|
||||
Spacer()
|
||||
@@ -40,7 +40,7 @@ struct VideoBanner: View {
|
||||
progressView
|
||||
#endif
|
||||
|
||||
if let time = (videoDuration ?? video.length).formattedAsPlaybackTime() {
|
||||
if let time = (videoDuration ?? video?.length ?? 0).formattedAsPlaybackTime() {
|
||||
Text(time)
|
||||
.fontWeight(.light)
|
||||
}
|
||||
@@ -71,7 +71,7 @@ struct VideoBanner: View {
|
||||
}
|
||||
|
||||
private var smallThumbnail: some View {
|
||||
WebImage(url: video.thumbnailURL(quality: .medium))
|
||||
WebImage(url: video?.thumbnailURL(quality: .medium))
|
||||
.resizable()
|
||||
.placeholder {
|
||||
ProgressView()
|
||||
@@ -109,7 +109,7 @@ struct VideoBanner: View {
|
||||
}
|
||||
|
||||
private var progressViewTotal: Double {
|
||||
videoDuration ?? video.length
|
||||
videoDuration ?? video?.length ?? 1
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -31,12 +31,12 @@ struct PlayerControlsView<Content: View>: View {
|
||||
}) {
|
||||
HStack {
|
||||
VStack(alignment: .leading, spacing: 3) {
|
||||
Text(model.currentItem?.video.title ?? "Not playing")
|
||||
Text(model.currentItem?.video?.title ?? "Not playing")
|
||||
.font(.system(size: 14).bold())
|
||||
.foregroundColor(model.currentItem.isNil ? .secondary : .accentColor)
|
||||
.lineLimit(1)
|
||||
|
||||
Text(model.currentItem?.video.author ?? "Yattee v0.1")
|
||||
Text(model.currentItem?.video?.author ?? "Yattee v0.1")
|
||||
.fontWeight(model.currentItem.isNil ? .light : .bold)
|
||||
.font(.system(size: 10))
|
||||
.foregroundColor(.secondary)
|
||||
|
Reference in New Issue
Block a user