mirror of
https://github.com/yattee/yattee.git
synced 2024-12-23 05:53:41 +00:00
Add setting for saving recents (fixes #14)
This commit is contained in:
parent
e61d1dfe2e
commit
06f7391ad9
@ -3,7 +3,7 @@ import Foundation
|
|||||||
|
|
||||||
final class RecentsModel: ObservableObject {
|
final class RecentsModel: ObservableObject {
|
||||||
@Default(.recentlyOpened) var items
|
@Default(.recentlyOpened) var items
|
||||||
|
@Default(.saveRecents) var saveRecents
|
||||||
func clear() {
|
func clear() {
|
||||||
items = []
|
items = []
|
||||||
}
|
}
|
||||||
@ -13,6 +13,14 @@ final class RecentsModel: ObservableObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func add(_ item: RecentItem) {
|
func add(_ item: RecentItem) {
|
||||||
|
if !saveRecents {
|
||||||
|
clear()
|
||||||
|
|
||||||
|
if item.type != .channel {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if let index = items.firstIndex(where: { $0.id == item.id }) {
|
if let index = items.firstIndex(where: { $0.id == item.id }) {
|
||||||
items.remove(at: index)
|
items.remove(at: index)
|
||||||
}
|
}
|
||||||
|
@ -40,6 +40,7 @@ extension Defaults.Keys {
|
|||||||
static let lastPlayed = Key<PlayerQueueItem?>("lastPlayed")
|
static let lastPlayed = Key<PlayerQueueItem?>("lastPlayed")
|
||||||
|
|
||||||
static let saveHistory = Key<Bool>("saveHistory", default: true)
|
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 trendingCategory = Key<TrendingCategory>("trendingCategory", default: .default)
|
||||||
static let trendingCountry = Key<Country>("trendingCountry", default: .us)
|
static let trendingCountry = Key<Country>("trendingCountry", default: .us)
|
||||||
|
@ -141,6 +141,10 @@ struct ContentView: View {
|
|||||||
player.loadHistoryDetails()
|
player.loadHistoryDetails()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !Defaults[.saveRecents] {
|
||||||
|
recents.clear()
|
||||||
|
}
|
||||||
|
|
||||||
var section = Defaults[.visibleSections].min()?.tabSelection
|
var section = Defaults[.visibleSections].min()?.tabSelection
|
||||||
|
|
||||||
#if os(macOS)
|
#if os(macOS)
|
||||||
|
@ -24,6 +24,8 @@ struct SearchView: View {
|
|||||||
@EnvironmentObject<RecentsModel> private var recents
|
@EnvironmentObject<RecentsModel> private var recents
|
||||||
@EnvironmentObject<SearchModel> private var state
|
@EnvironmentObject<SearchModel> private var state
|
||||||
|
|
||||||
|
@Default(.saveRecents) private var saveRecents
|
||||||
|
|
||||||
private var videos = [Video]()
|
private var videos = [Video]()
|
||||||
|
|
||||||
var items: [ContentItem] {
|
var items: [ContentItem] {
|
||||||
@ -229,7 +231,7 @@ struct SearchView: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private var showRecentQueries: Bool {
|
private var showRecentQueries: Bool {
|
||||||
navigationStyle == .tab && state.queryText.isEmpty
|
navigationStyle == .tab && saveRecents && state.queryText.isEmpty
|
||||||
}
|
}
|
||||||
|
|
||||||
private var filtersActive: Bool {
|
private var filtersActive: Bool {
|
||||||
|
@ -4,6 +4,7 @@ import SwiftUI
|
|||||||
struct BrowsingSettings: View {
|
struct BrowsingSettings: View {
|
||||||
@Default(.channelOnThumbnail) private var channelOnThumbnail
|
@Default(.channelOnThumbnail) private var channelOnThumbnail
|
||||||
@Default(.timeOnThumbnail) private var timeOnThumbnail
|
@Default(.timeOnThumbnail) private var timeOnThumbnail
|
||||||
|
@Default(.saveRecents) private var saveRecents
|
||||||
@Default(.saveHistory) private var saveHistory
|
@Default(.saveHistory) private var saveHistory
|
||||||
@Default(.visibleSections) private var visibleSections
|
@Default(.visibleSections) private var visibleSections
|
||||||
|
|
||||||
@ -12,6 +13,7 @@ struct BrowsingSettings: View {
|
|||||||
Section(header: SettingsHeader(text: "Browsing")) {
|
Section(header: SettingsHeader(text: "Browsing")) {
|
||||||
Toggle("Show channel name on thumbnail", isOn: $channelOnThumbnail)
|
Toggle("Show channel name on thumbnail", isOn: $channelOnThumbnail)
|
||||||
Toggle("Show video length on thumbnail", isOn: $timeOnThumbnail)
|
Toggle("Show video length on thumbnail", isOn: $timeOnThumbnail)
|
||||||
|
Toggle("Save recent queries and channels", isOn: $saveRecents)
|
||||||
Toggle("Save history of played videos", isOn: $saveHistory)
|
Toggle("Save history of played videos", isOn: $saveHistory)
|
||||||
}
|
}
|
||||||
Section(header: SettingsHeader(text: "Sections")) {
|
Section(header: SettingsHeader(text: "Sections")) {
|
||||||
|
Loading…
Reference in New Issue
Block a user