Add "Startup section" setting

Fix #103
This commit is contained in:
Arkadiusz Fal 2023-05-25 17:01:53 +02:00
parent ae144ea82f
commit 59f48c739a
4 changed files with 56 additions and 34 deletions

View File

@ -185,6 +185,7 @@ extension Defaults.Keys {
static let trendingCountry = Key<Country>("trendingCountry", default: .us)
static let visibleSections = Key<Set<VisibleSection>>("visibleSections", default: [.subscriptions, .trending, .playlists])
static let startupSection = Key<StartupSection>("startupSection", default: .home)
#if os(iOS)
static let honorSystemOrientationLock = Key<Bool>("honorSystemOrientationLock", default: true)
@ -340,6 +341,31 @@ enum VisibleSection: String, CaseIterable, Comparable, Defaults.Serializable {
}
}
enum StartupSection: String, CaseIterable, Defaults.Serializable {
case home, subscriptions, popular, trending, playlists, search
var label: String {
rawValue.capitalized.localized()
}
var tabSelection: TabSelection {
switch self {
case .home:
return .home
case .subscriptions:
return .subscriptions
case .popular:
return .popular
case .trending:
return .trending
case .playlists:
return .playlists
case .search:
return .search
}
}
}
enum WatchedVideoStyle: String, Defaults.Serializable {
case nothing, badge, decreasedOpacity, both

View File

@ -17,6 +17,7 @@ struct BrowsingSettings: View {
@Default(.timeOnThumbnail) private var timeOnThumbnail
@Default(.showOpenActionsToolbarItem) private var showOpenActionsToolbarItem
@Default(.visibleSections) private var visibleSections
@Default(.startupSection) private var startupSection
@Default(.playerButtonSingleTapGesture) private var playerButtonSingleTapGesture
@Default(.playerButtonDoubleTapGesture) private var playerButtonDoubleTapGesture
@Default(.playerButtonShowsControlButtonsWhenMinimized) private var playerButtonShowsControlButtonsWhenMinimized
@ -50,7 +51,7 @@ struct BrowsingSettings: View {
#endif
}
#if os(tvOS)
.frame(maxWidth: 1000)
.frame(maxWidth: 1200)
#else
.frame(minWidth: 0, maxWidth: .infinity, alignment: .leading)
#endif
@ -60,25 +61,28 @@ struct BrowsingSettings: View {
private var sections: some View {
Group {
homeSettings
if !accounts.isEmpty {
startupSectionPicker
visibleSectionsSettings
}
let interface = interfaceSettings
#if os(tvOS)
if !accounts.isEmpty {
interface
}
#else
playerBarSettings
interface
playerBarSettings
#endif
if !accounts.isEmpty {
thumbnailsSettings
visibleSectionsSettings
}
}
}
@ViewBuilder private var homeSettings: some View {
if !accounts.isEmpty {
Section(header: SettingsHeader(text: "Home".localized())) {
Section {
#if os(macOS)
Button {
presentingHomeSettingsSheet = true
@ -204,37 +208,28 @@ struct BrowsingSettings: View {
private var visibleSectionsSettings: some View {
Section(header: SettingsHeader(text: "Sections".localized())) {
#if os(macOS)
let list = ForEach(VisibleSection.allCases, id: \.self) { section in
MultiselectRow(
title: section.title,
selected: visibleSections.contains(section)
) { value in
toggleSection(section, value: value)
}
ForEach(VisibleSection.allCases, id: \.self) { section in
MultiselectRow(
title: section.title,
selected: visibleSections.contains(section)
) { value in
toggleSection(section, value: value)
}
}
}
}
Group {
if #available(macOS 12.0, *) {
list
.listStyle(.inset(alternatesRowBackgrounds: true))
} else {
list
.listStyle(.inset)
}
Spacer()
}
#else
ForEach(VisibleSection.allCases, id: \.self) { section in
MultiselectRow(
title: section.title,
selected: visibleSections.contains(section)
) { value in
toggleSection(section, value: value)
}
}
private var startupSectionPicker: some View {
Group {
#if os(tvOS)
SettingsHeader(text: "Startup section".localized())
#endif
Picker("Startup section", selection: $startupSection) {
ForEach(StartupSection.allCases, id: \.rawValue) { section in
Text(section.label).tag(section)
}
}
.modifier(SettingsPickerModifier())
}
}

View File

@ -243,7 +243,7 @@ struct SettingsView: View {
private var windowHeight: Double {
switch selection {
case .browsing:
return 880
return 720
case .player:
return 480
case .controls:

View File

@ -152,7 +152,8 @@ struct YatteeApp: App {
recents.clear()
}
var section = Defaults[.showHome] ? TabSelection.home : Defaults[.visibleSections].min()?.tabSelection
let startupSection = Defaults[.startupSection]
var section: TabSelection? = startupSection.tabSelection
#if os(macOS)
if section == .playlists {