Add setting for saving recents (fixes #14)

This commit is contained in:
Arkadiusz Fal 2021-12-01 12:22:19 +01:00
parent e61d1dfe2e
commit 06f7391ad9
5 changed files with 19 additions and 2 deletions

View File

@ -3,7 +3,7 @@ import Foundation
final class RecentsModel: ObservableObject {
@Default(.recentlyOpened) var items
@Default(.saveRecents) var saveRecents
func clear() {
items = []
}
@ -13,6 +13,14 @@ final class RecentsModel: ObservableObject {
}
func add(_ item: RecentItem) {
if !saveRecents {
clear()
if item.type != .channel {
return
}
}
if let index = items.firstIndex(where: { $0.id == item.id }) {
items.remove(at: index)
}

View File

@ -40,6 +40,7 @@ extension Defaults.Keys {
static let lastPlayed = Key<PlayerQueueItem?>("lastPlayed")
static let saveHistory = Key<Bool>("saveHistory", default: true)
static let saveRecents = Key<Bool>("saveRecents", default: true)
static let trendingCategory = Key<TrendingCategory>("trendingCategory", default: .default)
static let trendingCountry = Key<Country>("trendingCountry", default: .us)

View File

@ -141,6 +141,10 @@ struct ContentView: View {
player.loadHistoryDetails()
}
if !Defaults[.saveRecents] {
recents.clear()
}
var section = Defaults[.visibleSections].min()?.tabSelection
#if os(macOS)

View File

@ -24,6 +24,8 @@ struct SearchView: View {
@EnvironmentObject<RecentsModel> private var recents
@EnvironmentObject<SearchModel> private var state
@Default(.saveRecents) private var saveRecents
private var videos = [Video]()
var items: [ContentItem] {
@ -229,7 +231,7 @@ struct SearchView: View {
}
private var showRecentQueries: Bool {
navigationStyle == .tab && state.queryText.isEmpty
navigationStyle == .tab && saveRecents && state.queryText.isEmpty
}
private var filtersActive: Bool {

View File

@ -4,6 +4,7 @@ import SwiftUI
struct BrowsingSettings: View {
@Default(.channelOnThumbnail) private var channelOnThumbnail
@Default(.timeOnThumbnail) private var timeOnThumbnail
@Default(.saveRecents) private var saveRecents
@Default(.saveHistory) private var saveHistory
@Default(.visibleSections) private var visibleSections
@ -12,6 +13,7 @@ struct BrowsingSettings: View {
Section(header: SettingsHeader(text: "Browsing")) {
Toggle("Show channel name on thumbnail", isOn: $channelOnThumbnail)
Toggle("Show video length on thumbnail", isOn: $timeOnThumbnail)
Toggle("Save recent queries and channels", isOn: $saveRecents)
Toggle("Save history of played videos", isOn: $saveHistory)
}
Section(header: SettingsHeader(text: "Sections")) {