2021-09-25 08:18:22 +00:00
|
|
|
import Defaults
|
|
|
|
import Foundation
|
|
|
|
import SwiftUI
|
|
|
|
struct SettingsView: View {
|
2022-07-03 22:13:06 +00:00
|
|
|
static let matrixURL = URL(string: "https://tinyurl.com/matrix-yattee")!
|
|
|
|
static let discordURL = URL(string: "https://yattee.stream/discord")!
|
|
|
|
|
2021-09-29 14:29:17 +00:00
|
|
|
#if os(macOS)
|
|
|
|
private enum Tabs: Hashable {
|
2022-12-19 12:35:37 +00:00
|
|
|
case browsing, player, controls, quality, history, sponsorBlock, locations, advanced, help
|
2021-09-29 14:29:17 +00:00
|
|
|
}
|
2022-01-06 15:02:53 +00:00
|
|
|
|
2022-12-17 18:35:07 +00:00
|
|
|
@State private var selection: Tabs = .browsing
|
2021-09-29 14:29:17 +00:00
|
|
|
#endif
|
2021-09-25 08:18:22 +00:00
|
|
|
|
2021-12-05 17:09:25 +00:00
|
|
|
@Environment(\.colorScheme) private var colorScheme
|
|
|
|
|
2021-09-29 14:29:17 +00:00
|
|
|
#if os(iOS)
|
2021-11-28 14:37:55 +00:00
|
|
|
@Environment(\.presentationMode) private var presentationMode
|
2021-09-29 14:29:17 +00:00
|
|
|
#endif
|
2021-09-25 08:18:22 +00:00
|
|
|
|
2022-11-24 20:36:05 +00:00
|
|
|
@ObservedObject private var accounts = AccountsModel.shared
|
|
|
|
@ObservedObject private var model = SettingsModel.shared
|
2021-11-28 14:37:55 +00:00
|
|
|
|
|
|
|
@Default(.instances) private var instances
|
|
|
|
|
2021-09-25 08:18:22 +00:00
|
|
|
var body: some View {
|
2022-07-01 21:28:32 +00:00
|
|
|
settings
|
|
|
|
.alert(isPresented: $model.presentingAlert) { model.alert }
|
2022-12-21 20:16:53 +00:00
|
|
|
#if os(iOS)
|
|
|
|
.backport
|
2023-02-06 20:51:57 +00:00
|
|
|
.scrollDismissesKeyboardInteractively()
|
2022-12-21 20:16:53 +00:00
|
|
|
#endif
|
2022-07-01 21:28:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var settings: some View {
|
2021-09-25 08:18:22 +00:00
|
|
|
#if os(macOS)
|
2022-01-06 15:02:53 +00:00
|
|
|
TabView(selection: $selection) {
|
2022-11-11 20:28:40 +00:00
|
|
|
Form {
|
|
|
|
BrowsingSettings()
|
|
|
|
}
|
|
|
|
.tabItem {
|
|
|
|
Label("Browsing", systemImage: "list.and.film")
|
2021-11-04 23:25:51 +00:00
|
|
|
}
|
2022-12-18 18:39:03 +00:00
|
|
|
.tag(Tabs.browsing)
|
2021-11-04 23:25:51 +00:00
|
|
|
|
2021-12-26 21:14:46 +00:00
|
|
|
Form {
|
2022-01-06 15:02:53 +00:00
|
|
|
PlayerSettings()
|
2021-12-26 21:14:46 +00:00
|
|
|
}
|
|
|
|
.tabItem {
|
2022-01-06 15:02:53 +00:00
|
|
|
Label("Player", systemImage: "play.rectangle")
|
2021-12-26 21:14:46 +00:00
|
|
|
}
|
2022-12-18 18:39:03 +00:00
|
|
|
.tag(Tabs.player)
|
2021-12-26 21:14:46 +00:00
|
|
|
|
2022-12-19 12:35:37 +00:00
|
|
|
Form {
|
|
|
|
PlayerControlsSettings()
|
|
|
|
}
|
|
|
|
.tabItem {
|
|
|
|
Label("Controls", systemImage: "hand.tap")
|
|
|
|
}
|
|
|
|
.tag(Tabs.controls)
|
|
|
|
|
2022-08-14 17:06:22 +00:00
|
|
|
Form {
|
|
|
|
QualitySettings()
|
|
|
|
}
|
|
|
|
.tabItem {
|
|
|
|
Label("Quality", systemImage: "4k.tv")
|
|
|
|
}
|
2022-12-18 18:39:03 +00:00
|
|
|
.tag(Tabs.quality)
|
2022-08-14 17:06:22 +00:00
|
|
|
|
2021-10-23 12:12:53 +00:00
|
|
|
Form {
|
2022-01-06 15:02:53 +00:00
|
|
|
HistorySettings()
|
2021-10-23 12:12:53 +00:00
|
|
|
}
|
|
|
|
.tabItem {
|
2022-01-06 15:02:53 +00:00
|
|
|
Label("History", systemImage: "clock.arrow.circlepath")
|
2021-10-23 12:12:53 +00:00
|
|
|
}
|
2022-12-18 18:39:03 +00:00
|
|
|
.tag(Tabs.history)
|
2021-10-23 12:12:53 +00:00
|
|
|
|
2022-11-11 19:34:20 +00:00
|
|
|
if !accounts.isEmpty {
|
|
|
|
Form {
|
|
|
|
SponsorBlockSettings()
|
|
|
|
}
|
|
|
|
.tabItem {
|
|
|
|
Label("SponsorBlock", systemImage: "dollarsign.circle")
|
|
|
|
}
|
2022-12-18 18:39:03 +00:00
|
|
|
.tag(Tabs.sponsorBlock)
|
2021-09-25 08:18:22 +00:00
|
|
|
}
|
2022-11-13 11:14:05 +00:00
|
|
|
Form {
|
|
|
|
LocationsSettings()
|
|
|
|
}
|
|
|
|
.tabItem {
|
|
|
|
Label("Locations", systemImage: "globe")
|
|
|
|
}
|
2022-12-18 18:39:03 +00:00
|
|
|
.tag(Tabs.locations)
|
2021-12-07 23:09:49 +00:00
|
|
|
|
2022-07-01 21:28:32 +00:00
|
|
|
Group {
|
|
|
|
AdvancedSettings()
|
|
|
|
}
|
|
|
|
.tabItem {
|
|
|
|
Label("Advanced", systemImage: "wrench.and.screwdriver")
|
|
|
|
}
|
2022-12-18 18:39:03 +00:00
|
|
|
.tag(Tabs.advanced)
|
2022-07-01 21:28:32 +00:00
|
|
|
|
2022-01-06 15:02:53 +00:00
|
|
|
Form {
|
|
|
|
Help()
|
|
|
|
}
|
|
|
|
.tabItem {
|
|
|
|
Label("Help", systemImage: "questionmark.circle")
|
|
|
|
}
|
2022-12-18 18:39:03 +00:00
|
|
|
.tag(Tabs.help)
|
2021-09-25 08:18:22 +00:00
|
|
|
}
|
|
|
|
.padding(20)
|
2022-12-19 12:35:37 +00:00
|
|
|
.frame(width: 650, height: windowHeight)
|
2021-09-25 08:18:22 +00:00
|
|
|
#else
|
2022-08-14 17:06:22 +00:00
|
|
|
NavigationView {
|
|
|
|
settingsList
|
2022-11-12 01:39:44 +00:00
|
|
|
.navigationTitle("Settings")
|
2022-06-26 13:17:18 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
2021-11-28 14:37:55 +00:00
|
|
|
|
2023-09-10 18:08:42 +00:00
|
|
|
struct SettingsLabel: LabelStyle {
|
|
|
|
func makeBody(configuration: Configuration) -> some View {
|
|
|
|
#if os(tvOS)
|
|
|
|
Label {
|
|
|
|
configuration.title.padding(.leading, 10)
|
|
|
|
} icon: {
|
|
|
|
configuration.icon
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
Label(configuration)
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-26 13:17:18 +00:00
|
|
|
#if !os(macOS)
|
|
|
|
var settingsList: some View {
|
|
|
|
List {
|
|
|
|
#if os(tvOS)
|
2022-11-11 19:34:20 +00:00
|
|
|
if !accounts.isEmpty {
|
2022-12-11 22:15:56 +00:00
|
|
|
Section(header: Text("Current Location")) {
|
|
|
|
NavigationLink(destination: AccountsView()) {
|
|
|
|
if let account = accounts.current {
|
|
|
|
Text(account.isPublic ? account.description : "\(account.description) — \(account.instance.shortDescription)")
|
|
|
|
} else {
|
|
|
|
Text("Not Selected")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-11-11 19:34:20 +00:00
|
|
|
Divider()
|
|
|
|
}
|
2022-06-26 13:17:18 +00:00
|
|
|
#endif
|
2022-01-06 15:02:53 +00:00
|
|
|
|
2022-06-26 13:17:18 +00:00
|
|
|
Section {
|
2022-11-11 20:28:40 +00:00
|
|
|
NavigationLink {
|
|
|
|
BrowsingSettings()
|
|
|
|
} label: {
|
2023-09-10 18:08:42 +00:00
|
|
|
Label("Browsing", systemImage: "list.and.film").labelStyle(SettingsLabel())
|
2022-06-26 13:17:18 +00:00
|
|
|
}
|
2022-01-06 15:02:53 +00:00
|
|
|
|
2022-06-26 13:17:18 +00:00
|
|
|
NavigationLink {
|
|
|
|
PlayerSettings()
|
|
|
|
} label: {
|
2023-09-10 18:08:42 +00:00
|
|
|
Label("Player", systemImage: "play.rectangle").labelStyle(SettingsLabel())
|
2022-01-06 15:02:53 +00:00
|
|
|
}
|
|
|
|
|
2022-12-19 12:35:37 +00:00
|
|
|
NavigationLink {
|
|
|
|
PlayerControlsSettings()
|
|
|
|
} label: {
|
2023-09-10 18:08:42 +00:00
|
|
|
Label("Controls", systemImage: "hand.tap").labelStyle(SettingsLabel())
|
2022-12-19 12:35:37 +00:00
|
|
|
}
|
|
|
|
|
2022-08-14 17:06:22 +00:00
|
|
|
NavigationLink {
|
|
|
|
QualitySettings()
|
|
|
|
} label: {
|
2023-09-10 18:08:42 +00:00
|
|
|
Label("Quality", systemImage: "4k.tv").labelStyle(SettingsLabel())
|
2022-08-14 17:06:22 +00:00
|
|
|
}
|
|
|
|
|
2022-06-26 13:17:18 +00:00
|
|
|
NavigationLink {
|
|
|
|
HistorySettings()
|
|
|
|
} label: {
|
2023-09-10 18:08:42 +00:00
|
|
|
Label("History", systemImage: "clock.arrow.circlepath").labelStyle(SettingsLabel())
|
2022-06-26 13:17:18 +00:00
|
|
|
}
|
|
|
|
|
2022-11-11 19:34:20 +00:00
|
|
|
if !accounts.isEmpty {
|
|
|
|
NavigationLink {
|
|
|
|
SponsorBlockSettings()
|
|
|
|
} label: {
|
2023-09-10 18:08:42 +00:00
|
|
|
Label("SponsorBlock", systemImage: "dollarsign.circle").labelStyle(SettingsLabel())
|
2022-11-11 19:34:20 +00:00
|
|
|
}
|
2022-01-06 15:02:53 +00:00
|
|
|
}
|
2022-07-01 21:28:32 +00:00
|
|
|
|
2022-11-13 11:14:05 +00:00
|
|
|
NavigationLink {
|
|
|
|
LocationsSettings()
|
|
|
|
} label: {
|
2023-09-10 18:08:42 +00:00
|
|
|
Label("Locations", systemImage: "globe").labelStyle(SettingsLabel())
|
2022-11-13 11:14:05 +00:00
|
|
|
}
|
|
|
|
|
2022-07-01 21:28:32 +00:00
|
|
|
NavigationLink {
|
|
|
|
AdvancedSettings()
|
|
|
|
} label: {
|
2023-09-10 18:08:42 +00:00
|
|
|
Label("Advanced", systemImage: "wrench.and.screwdriver").labelStyle(SettingsLabel())
|
2022-07-01 21:28:32 +00:00
|
|
|
}
|
2021-09-25 08:18:22 +00:00
|
|
|
}
|
2023-09-09 16:20:44 +00:00
|
|
|
#if os(tvOS)
|
|
|
|
.padding(.horizontal, 20)
|
|
|
|
#endif
|
2022-06-26 13:17:18 +00:00
|
|
|
|
2022-07-03 22:39:05 +00:00
|
|
|
Section(footer: helpFooter) {
|
2022-06-26 13:17:18 +00:00
|
|
|
NavigationLink {
|
|
|
|
Help()
|
|
|
|
} label: {
|
2023-09-10 18:08:42 +00:00
|
|
|
Label("Help", systemImage: "questionmark.circle").labelStyle(SettingsLabel())
|
2021-09-25 08:18:22 +00:00
|
|
|
}
|
2021-09-26 22:03:33 +00:00
|
|
|
}
|
2023-09-09 16:20:44 +00:00
|
|
|
#if os(tvOS)
|
|
|
|
.padding(.horizontal, 20)
|
|
|
|
#endif
|
2022-07-03 22:13:06 +00:00
|
|
|
|
|
|
|
#if !os(tvOS)
|
|
|
|
Section(header: Text("Contact"), footer: versionString) {
|
|
|
|
Link(destination: Self.discordURL) {
|
|
|
|
HStack {
|
|
|
|
Image("Discord")
|
|
|
|
.resizable()
|
|
|
|
.renderingMode(.template)
|
|
|
|
.frame(maxWidth: 30, maxHeight: 30)
|
2023-09-10 18:07:24 +00:00
|
|
|
.padding(.trailing, 6)
|
2022-07-03 22:13:06 +00:00
|
|
|
Text("Discord Server")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Link(destination: Self.matrixURL) {
|
|
|
|
HStack {
|
|
|
|
Image("Matrix")
|
|
|
|
.resizable()
|
|
|
|
.renderingMode(.template)
|
|
|
|
.frame(maxWidth: 30, maxHeight: 30)
|
2023-09-10 18:07:24 +00:00
|
|
|
.padding(.trailing, 6)
|
2022-07-03 22:13:06 +00:00
|
|
|
Text("Matrix Chat")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2021-09-25 08:18:22 +00:00
|
|
|
}
|
2022-06-26 13:17:18 +00:00
|
|
|
.toolbar {
|
|
|
|
ToolbarItem(placement: .navigationBarLeading) {
|
|
|
|
#if !os(tvOS)
|
|
|
|
Button("Done") {
|
|
|
|
presentationMode.wrappedValue.dismiss()
|
|
|
|
}
|
|
|
|
.keyboardShortcut(.cancelAction)
|
|
|
|
#endif
|
|
|
|
}
|
2021-11-28 14:37:55 +00:00
|
|
|
}
|
2022-06-26 13:17:18 +00:00
|
|
|
.frame(maxWidth: 1000)
|
|
|
|
#if os(iOS)
|
|
|
|
.listStyle(.insetGrouped)
|
2021-09-28 18:06:05 +00:00
|
|
|
#endif
|
2022-06-26 13:17:18 +00:00
|
|
|
}
|
|
|
|
#endif
|
2021-11-28 14:37:55 +00:00
|
|
|
|
2022-01-06 15:02:53 +00:00
|
|
|
#if os(macOS)
|
|
|
|
private var windowHeight: Double {
|
|
|
|
switch selection {
|
|
|
|
case .browsing:
|
2023-07-22 17:02:59 +00:00
|
|
|
return 800
|
2022-01-06 15:02:53 +00:00
|
|
|
case .player:
|
2023-10-14 22:37:02 +00:00
|
|
|
return 500
|
2022-12-19 12:35:37 +00:00
|
|
|
case .controls:
|
2023-04-22 17:22:13 +00:00
|
|
|
return 920
|
2022-08-14 17:06:22 +00:00
|
|
|
case .quality:
|
2022-08-25 23:36:46 +00:00
|
|
|
return 420
|
2022-01-06 15:02:53 +00:00
|
|
|
case .history:
|
2022-09-27 15:46:14 +00:00
|
|
|
return 500
|
2022-01-06 15:02:53 +00:00
|
|
|
case .sponsorBlock:
|
2022-11-11 18:55:18 +00:00
|
|
|
return 700
|
2022-11-13 11:14:05 +00:00
|
|
|
case .locations:
|
|
|
|
return 600
|
2022-07-01 21:28:32 +00:00
|
|
|
case .advanced:
|
2022-12-14 16:21:48 +00:00
|
|
|
return 380
|
2022-01-06 15:02:53 +00:00
|
|
|
case .help:
|
2022-11-18 23:38:32 +00:00
|
|
|
return 650
|
2022-01-06 15:02:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2022-07-03 22:39:05 +00:00
|
|
|
var helpFooter: some View {
|
|
|
|
#if os(tvOS)
|
|
|
|
versionString
|
|
|
|
#else
|
|
|
|
EmptyView()
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2022-01-06 15:02:53 +00:00
|
|
|
private var versionString: some View {
|
|
|
|
Text("Yattee \(YatteeApp.version) (build \(YatteeApp.build))")
|
|
|
|
#if os(tvOS)
|
|
|
|
.foregroundColor(.secondary)
|
|
|
|
#endif
|
|
|
|
}
|
2021-09-25 08:18:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct SettingsView_Previews: PreviewProvider {
|
|
|
|
static var previews: some View {
|
|
|
|
SettingsView()
|
2021-09-29 11:45:00 +00:00
|
|
|
.injectFixtureEnvironmentObjects()
|
2021-09-25 08:18:22 +00:00
|
|
|
#if os(macOS)
|
|
|
|
.frame(width: 600, height: 300)
|
2022-11-11 15:19:14 +00:00
|
|
|
#else
|
|
|
|
.navigationViewStyle(.stack)
|
2021-09-25 08:18:22 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|