mirror of
https://github.com/yattee/yattee.git
synced 2024-12-22 21:43:41 +00:00
Fix restoring queue
This commit is contained in:
parent
534f356471
commit
a04827cc56
@ -33,7 +33,7 @@ final class PlayerModel: ObservableObject {
|
|||||||
@Published var streamSelection: Stream? { didSet { rebuildTVMenu() } }
|
@Published var streamSelection: Stream? { didSet { rebuildTVMenu() } }
|
||||||
|
|
||||||
@Published var queue = [PlayerQueueItem]() { didSet { Defaults[.queue] = queue } }
|
@Published var queue = [PlayerQueueItem]() { didSet { Defaults[.queue] = queue } }
|
||||||
@Published var currentItem: PlayerQueueItem! { didSet { updateWindowTitle() } }
|
@Published var currentItem: PlayerQueueItem! { didSet { handleCurrentItemChange() } }
|
||||||
@Published var historyVideos = [Video]()
|
@Published var historyVideos = [Video]()
|
||||||
|
|
||||||
@Published var preservedTime: CMTime?
|
@Published var preservedTime: CMTime?
|
||||||
@ -804,10 +804,12 @@ final class PlayerModel: ObservableObject {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
func updateWindowTitle() {
|
func handleCurrentItemChange() {
|
||||||
#if os(macOS)
|
#if os(macOS)
|
||||||
Windows.player.window?.title = windowTitle
|
Windows.player.window?.title = windowTitle
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Defaults[.lastPlayed] = currentItem
|
||||||
}
|
}
|
||||||
|
|
||||||
#if os(macOS)
|
#if os(macOS)
|
||||||
|
@ -201,4 +201,21 @@ extension PlayerModel {
|
|||||||
func removeQueueItems() {
|
func removeQueueItems() {
|
||||||
queue.removeAll()
|
queue.removeAll()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func restoreQueue() {
|
||||||
|
guard !accounts.current.isNil else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
queue = ([Defaults[.lastPlayed]] + Defaults[.queue]).compactMap { $0 }
|
||||||
|
Defaults[.lastPlayed] = nil
|
||||||
|
|
||||||
|
queue.forEach { item in
|
||||||
|
accounts.api.loadDetails(item) { newItem in
|
||||||
|
if let index = self.queue.firstIndex(where: { $0.id == item.id }) {
|
||||||
|
self.queue[index] = newItem
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -64,6 +64,7 @@ extension Defaults.Keys {
|
|||||||
static let recentlyOpened = Key<[RecentItem]>("recentlyOpened", default: [])
|
static let recentlyOpened = Key<[RecentItem]>("recentlyOpened", default: [])
|
||||||
|
|
||||||
static let queue = Key<[PlayerQueueItem]>("queue", default: [])
|
static let queue = Key<[PlayerQueueItem]>("queue", default: [])
|
||||||
|
static let lastPlayed = Key<PlayerQueueItem?>("lastPlayed")
|
||||||
|
|
||||||
static let saveHistory = Key<Bool>("saveHistory", default: true)
|
static let saveHistory = Key<Bool>("saveHistory", default: true)
|
||||||
static let showWatchingProgress = Key<Bool>("showWatchingProgress", default: true)
|
static let showWatchingProgress = Key<Bool>("showWatchingProgress", default: true)
|
||||||
|
@ -30,7 +30,7 @@ private struct CurrentPlaylistID: EnvironmentKey {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private struct LoadMoreContentHandler: EnvironmentKey {
|
private struct LoadMoreContentHandler: EnvironmentKey {
|
||||||
static let defaultValue: LoadMoreContentHandlerType = { }
|
static let defaultValue: LoadMoreContentHandlerType = {}
|
||||||
}
|
}
|
||||||
|
|
||||||
typealias LoadMoreContentHandlerType = () -> Void
|
typealias LoadMoreContentHandlerType = () -> Void
|
||||||
|
@ -139,6 +139,10 @@ struct ContentView: View {
|
|||||||
player.accounts = accounts
|
player.accounts = accounts
|
||||||
player.comments = comments
|
player.comments = comments
|
||||||
|
|
||||||
|
if !accounts.current.isNil {
|
||||||
|
player.restoreQueue()
|
||||||
|
}
|
||||||
|
|
||||||
if !Defaults[.saveRecents] {
|
if !Defaults[.saveRecents] {
|
||||||
recents.clear()
|
recents.clear()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user