diff --git a/Model/Player/PlayerModel.swift b/Model/Player/PlayerModel.swift index 374cef1c..557ca41d 100644 --- a/Model/Player/PlayerModel.swift +++ b/Model/Player/PlayerModel.swift @@ -150,6 +150,8 @@ final class PlayerModel: ObservableObject { } }} + @Default(.saveLastPlayed) var saveLastPlayed + @Default(.lastPlayed) var lastPlayed @Default(.qualityProfiles) var qualityProfiles @Default(.forceAVPlayerForLiveStreams) var forceAVPlayerForLiveStreams @Default(.pauseOnHidingPlayer) private var pauseOnHidingPlayer @@ -643,7 +645,9 @@ final class PlayerModel: ObservableObject { DispatchQueue.main.async(qos: .background) { [weak self] in guard let self = self else { return } - Defaults[.lastPlayed] = self.currentItem + if self.saveLastPlayed { + self.lastPlayed = self.currentItem + } if self.playbackMode == .related, let video = self.currentVideo, diff --git a/Model/Player/PlayerQueue.swift b/Model/Player/PlayerQueue.swift index 4dd29825..66099f00 100644 --- a/Model/Player/PlayerQueue.swift +++ b/Model/Player/PlayerQueue.swift @@ -239,11 +239,11 @@ extension PlayerModel { func restoreQueue() { var restoredQueue = [PlayerQueueItem?]() - if let lastPlayed = Defaults[.lastPlayed], + if let lastPlayed = lastPlayed, !Defaults[.queue].contains(where: { $0.videoID == lastPlayed.videoID }) { restoredQueue.append(lastPlayed) - Defaults[.lastPlayed] = nil + self.lastPlayed = nil } restoredQueue.append(contentsOf: Defaults[.queue]) diff --git a/Shared/Defaults.swift b/Shared/Defaults.swift index eea86c1a..bb5b8e4a 100644 --- a/Shared/Defaults.swift +++ b/Shared/Defaults.swift @@ -154,6 +154,7 @@ extension Defaults.Keys { static let recentlyOpened = Key<[RecentItem]>("recentlyOpened", default: []) static let queue = Key<[PlayerQueueItem]>("queue", default: []) + static let saveLastPlayed = Key("saveLastPlayed", default: false) static let lastPlayed = Key("lastPlayed") static let playbackMode = Key("playbackMode", default: .queue) diff --git a/Shared/Settings/HistorySettings.swift b/Shared/Settings/HistorySettings.swift index 059ed1d3..f69e19de 100644 --- a/Shared/Settings/HistorySettings.swift +++ b/Shared/Settings/HistorySettings.swift @@ -9,6 +9,7 @@ struct HistorySettings: View { @EnvironmentObject private var player @Default(.saveRecents) private var saveRecents + @Default(.saveLastPlayed) private var saveLastPlayed @Default(.saveHistory) private var saveHistory @Default(.showWatchingProgress) private var showWatchingProgress @Default(.watchedThreshold) private var watchedThreshold @@ -57,6 +58,7 @@ struct HistorySettings: View { Toggle("Save history of played videos", isOn: $saveHistory) Toggle("Show progress of watching on thumbnails", isOn: $showWatchingProgress) .disabled(!saveHistory) + Toggle("Keep last played video in the queue after restart", isOn: $saveLastPlayed) } Section(header: SettingsHeader(text: "Watched")) {