1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-14 06:10:32 +05:30
yattee/Shared/Settings/SettingsView.swift

268 lines
8.0 KiB
Swift
Raw Normal View History

2021-09-25 13:48:22 +05:30
import Defaults
import Foundation
import SwiftUI
struct SettingsView: View {
2022-07-04 03:43:06 +05:30
static let matrixURL = URL(string: "https://tinyurl.com/matrix-yattee")!
static let discordURL = URL(string: "https://yattee.stream/discord")!
#if os(macOS)
private enum Tabs: Hashable {
2022-11-13 16:44:05 +05:30
case browsing, player, quality, history, sponsorBlock, locations, advanced, help
}
2022-01-06 20:32:53 +05:30
2022-11-12 01:04:20 +05:30
@State private var selection: Tabs?
#endif
2021-09-25 13:48:22 +05:30
@Environment(\.colorScheme) private var colorScheme
#if os(iOS)
2021-11-28 20:07:55 +05:30
@Environment(\.presentationMode) private var presentationMode
#endif
2021-09-25 13:48:22 +05:30
@ObservedObject private var accounts = AccountsModel.shared
@ObservedObject private var model = SettingsModel.shared
2021-11-28 20:07:55 +05:30
@Default(.instances) private var instances
2021-09-25 13:48:22 +05:30
var body: some View {
settings
.alert(isPresented: $model.presentingAlert) { model.alert }
}
var settings: some View {
2021-09-25 13:48:22 +05:30
#if os(macOS)
2022-01-06 20:32:53 +05:30
TabView(selection: $selection) {
2022-11-12 01:58:40 +05:30
Form {
BrowsingSettings()
}
.tabItem {
Label("Browsing", systemImage: "list.and.film")
2021-11-05 04:55:51 +05:30
}
2022-11-12 01:58:40 +05:30
.tag(Optional(Tabs.browsing))
2021-11-05 04:55:51 +05:30
Form {
2022-01-06 20:32:53 +05:30
PlayerSettings()
}
.tabItem {
2022-01-06 20:32:53 +05:30
Label("Player", systemImage: "play.rectangle")
}
2022-11-12 01:04:20 +05:30
.tag(Optional(Tabs.player))
2022-08-14 22:36:22 +05:30
Form {
QualitySettings()
}
.tabItem {
Label("Quality", systemImage: "4k.tv")
}
2022-11-12 01:04:20 +05:30
.tag(Optional(Tabs.quality))
2022-08-14 22:36:22 +05:30
2021-10-23 17:42:53 +05:30
Form {
2022-01-06 20:32:53 +05:30
HistorySettings()
2021-10-23 17:42:53 +05:30
}
.tabItem {
2022-01-06 20:32:53 +05:30
Label("History", systemImage: "clock.arrow.circlepath")
2021-10-23 17:42:53 +05:30
}
2022-11-12 01:04:20 +05:30
.tag(Optional(Tabs.history))
2021-10-23 17:42:53 +05:30
2022-11-12 01:04:20 +05:30
if !accounts.isEmpty {
Form {
SponsorBlockSettings()
}
.tabItem {
Label("SponsorBlock", systemImage: "dollarsign.circle")
}
.tag(Optional(Tabs.sponsorBlock))
2021-09-25 13:48:22 +05:30
}
2022-11-13 16:44:05 +05:30
Form {
LocationsSettings()
}
.tabItem {
Label("Locations", systemImage: "globe")
}
.tag(Optional(Tabs.locations))
2021-12-08 04:39:49 +05:30
Group {
AdvancedSettings()
}
.tabItem {
Label("Advanced", systemImage: "wrench.and.screwdriver")
}
2022-11-12 01:04:20 +05:30
.tag(Optional(Tabs.advanced))
2022-01-06 20:32:53 +05:30
Form {
Help()
}
.tabItem {
Label("Help", systemImage: "questionmark.circle")
}
2022-11-12 01:04:20 +05:30
.tag(Optional(Tabs.help))
2021-09-25 13:48:22 +05:30
}
.padding(20)
2022-09-04 20:58:30 +05:30
.frame(width: 600, height: windowHeight)
2021-09-25 13:48:22 +05:30
#else
2022-08-14 22:36:22 +05:30
NavigationView {
settingsList
2022-11-12 07:09:44 +05:30
.navigationTitle("Settings")
}
#endif
}
2021-11-28 20:07:55 +05:30
#if !os(macOS)
var settingsList: some View {
List {
#if os(tvOS)
2022-11-12 01:04:20 +05:30
if !accounts.isEmpty {
AccountSelectionView()
Divider()
}
#endif
2022-01-06 20:32:53 +05:30
Section {
2022-11-12 01:58:40 +05:30
NavigationLink {
BrowsingSettings()
} label: {
Label("Browsing", systemImage: "list.and.film")
}
2022-01-06 20:32:53 +05:30
NavigationLink {
PlayerSettings()
} label: {
Label("Player", systemImage: "play.rectangle")
2022-01-06 20:32:53 +05:30
}
2022-08-14 22:36:22 +05:30
NavigationLink {
QualitySettings()
} label: {
Label("Quality", systemImage: "4k.tv")
}
NavigationLink {
HistorySettings()
} label: {
Label("History", systemImage: "clock.arrow.circlepath")
}
2022-11-12 01:04:20 +05:30
if !accounts.isEmpty {
NavigationLink {
SponsorBlockSettings()
} label: {
Label("SponsorBlock", systemImage: "dollarsign.circle")
}
2022-01-06 20:32:53 +05:30
}
2022-11-13 16:44:05 +05:30
NavigationLink {
LocationsSettings()
} label: {
Label("Locations", systemImage: "globe")
}
NavigationLink {
AdvancedSettings()
} label: {
Label("Advanced", systemImage: "wrench.and.screwdriver")
}
2021-09-25 13:48:22 +05:30
}
2022-07-04 04:09:05 +05:30
Section(footer: helpFooter) {
NavigationLink {
Help()
} label: {
Label("Help", systemImage: "questionmark.circle")
2021-09-25 13:48:22 +05:30
}
2021-09-27 03:33:33 +05:30
}
2022-07-04 03:43:06 +05:30
#if !os(tvOS)
Section(header: Text("Contact"), footer: versionString) {
Link(destination: Self.discordURL) {
HStack {
Image("Discord")
.resizable()
.renderingMode(.template)
.frame(maxWidth: 30, maxHeight: 30)
Text("Discord Server")
}
}
Link(destination: Self.matrixURL) {
HStack {
Image("Matrix")
.resizable()
.renderingMode(.template)
.frame(maxWidth: 30, maxHeight: 30)
Text("Matrix Chat")
}
}
}
#endif
2021-09-25 13:48:22 +05:30
}
.toolbar {
ToolbarItem(placement: .navigationBarLeading) {
#if !os(tvOS)
Button("Done") {
presentationMode.wrappedValue.dismiss()
}
.keyboardShortcut(.cancelAction)
#endif
}
2021-11-28 20:07:55 +05:30
}
.frame(maxWidth: 1000)
#if os(iOS)
.listStyle(.insetGrouped)
#endif
}
#endif
2021-11-28 20:07:55 +05:30
2022-01-06 20:32:53 +05:30
#if os(macOS)
private var windowHeight: Double {
switch selection {
2022-11-12 01:04:20 +05:30
case nil:
2022-11-12 07:09:44 +05:30
return accounts.isEmpty ? 680 : 580
2022-01-06 20:32:53 +05:30
case .browsing:
2022-11-12 07:09:44 +05:30
return 580
2022-01-06 20:32:53 +05:30
case .player:
return 900
2022-08-14 22:36:22 +05:30
case .quality:
return 420
2022-01-06 20:32:53 +05:30
case .history:
2022-09-27 21:16:14 +05:30
return 500
2022-01-06 20:32:53 +05:30
case .sponsorBlock:
2022-11-12 00:25:18 +05:30
return 700
2022-11-13 16:44:05 +05:30
case .locations:
return 600
case .advanced:
2022-11-13 16:44:05 +05:30
return 250
2022-01-06 20:32:53 +05:30
case .help:
return 650
2022-01-06 20:32:53 +05:30
}
}
#endif
2022-07-04 04:09:05 +05:30
var helpFooter: some View {
#if os(tvOS)
versionString
#else
EmptyView()
#endif
}
2022-01-06 20:32:53 +05:30
private var versionString: some View {
Text("Yattee \(YatteeApp.version) (build \(YatteeApp.build))")
#if os(tvOS)
.foregroundColor(.secondary)
#endif
}
2021-09-25 13:48:22 +05:30
}
struct SettingsView_Previews: PreviewProvider {
static var previews: some View {
SettingsView()
2021-09-29 17:15:00 +05:30
.injectFixtureEnvironmentObjects()
2021-09-25 13:48:22 +05:30
#if os(macOS)
.frame(width: 600, height: 300)
2022-11-11 20:49:14 +05:30
#else
.navigationViewStyle(.stack)
2021-09-25 13:48:22 +05:30
#endif
}
}