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")!
|
|
|
|
|
2021-09-29 19:59:17 +05:30
|
|
|
#if os(macOS)
|
|
|
|
private enum Tabs: Hashable {
|
2024-02-02 04:24:16 +05:30
|
|
|
case browsing, player, controls, quality, history, sponsorBlock, locations, advanced, importExport, help
|
2021-09-29 19:59:17 +05:30
|
|
|
}
|
2022-01-06 20:32:53 +05:30
|
|
|
|
2022-12-18 00:05:07 +05:30
|
|
|
@State private var selection: Tabs = .browsing
|
2021-09-29 19:59:17 +05:30
|
|
|
#endif
|
2021-09-25 13:48:22 +05:30
|
|
|
|
2021-12-05 22:39:25 +05:30
|
|
|
@Environment(\.colorScheme) private var colorScheme
|
|
|
|
|
2021-09-29 19:59:17 +05:30
|
|
|
#if os(iOS)
|
2021-11-28 20:07:55 +05:30
|
|
|
@Environment(\.presentationMode) private var presentationMode
|
2021-09-29 19:59:17 +05:30
|
|
|
#endif
|
2021-09-25 13:48:22 +05:30
|
|
|
|
2022-11-25 02:06:05 +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
|
|
|
|
|
2024-02-02 04:24:16 +05:30
|
|
|
@State private var filesToShare = []
|
|
|
|
|
|
|
|
@ObservedObject private var navigation = NavigationModel.shared
|
|
|
|
@ObservedObject private var settingsModel = SettingsModel.shared
|
|
|
|
|
2021-09-25 13:48:22 +05:30
|
|
|
var body: some View {
|
2022-07-02 02:58:32 +05:30
|
|
|
settings
|
2024-02-02 04:24:16 +05:30
|
|
|
#if !os(tvOS)
|
|
|
|
.modifier(ImportSettingsFileImporterViewModifier(isPresented: $navigation.presentingSettingsFileImporter))
|
|
|
|
.modifier(ImportSettingsSheetViewModifier(isPresented: $settingsModel.presentingSettingsImportSheet, settingsFile: $settingsModel.settingsImportURL))
|
|
|
|
#endif
|
2022-12-22 01:46:53 +05:30
|
|
|
#if os(iOS)
|
2024-02-02 04:24:16 +05:30
|
|
|
.backport
|
|
|
|
.scrollDismissesKeyboardInteractively()
|
2022-12-22 01:46:53 +05:30
|
|
|
#endif
|
2024-02-02 04:24:16 +05:30
|
|
|
.alert(isPresented: $model.presentingAlert) { model.alert }
|
2022-07-02 02:58:32 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
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-12-19 00:09:03 +05:30
|
|
|
.tag(Tabs.browsing)
|
2021-11-05 04:55:51 +05:30
|
|
|
|
2021-12-27 02:44:46 +05:30
|
|
|
Form {
|
2022-01-06 20:32:53 +05:30
|
|
|
PlayerSettings()
|
2021-12-27 02:44:46 +05:30
|
|
|
}
|
|
|
|
.tabItem {
|
2022-01-06 20:32:53 +05:30
|
|
|
Label("Player", systemImage: "play.rectangle")
|
2021-12-27 02:44:46 +05:30
|
|
|
}
|
2022-12-19 00:09:03 +05:30
|
|
|
.tag(Tabs.player)
|
2021-12-27 02:44:46 +05:30
|
|
|
|
2022-12-19 18:05:37 +05:30
|
|
|
Form {
|
|
|
|
PlayerControlsSettings()
|
|
|
|
}
|
|
|
|
.tabItem {
|
|
|
|
Label("Controls", systemImage: "hand.tap")
|
|
|
|
}
|
|
|
|
.tag(Tabs.controls)
|
|
|
|
|
2022-08-14 22:36:22 +05:30
|
|
|
Form {
|
|
|
|
QualitySettings()
|
|
|
|
}
|
|
|
|
.tabItem {
|
|
|
|
Label("Quality", systemImage: "4k.tv")
|
|
|
|
}
|
2022-12-19 00:09:03 +05:30
|
|
|
.tag(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-12-19 00:09:03 +05:30
|
|
|
.tag(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")
|
|
|
|
}
|
2022-12-19 00:09:03 +05:30
|
|
|
.tag(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")
|
|
|
|
}
|
2022-12-19 00:09:03 +05:30
|
|
|
.tag(Tabs.locations)
|
2021-12-08 04:39:49 +05:30
|
|
|
|
2022-07-02 02:58:32 +05:30
|
|
|
Group {
|
|
|
|
AdvancedSettings()
|
|
|
|
}
|
|
|
|
.tabItem {
|
|
|
|
Label("Advanced", systemImage: "wrench.and.screwdriver")
|
|
|
|
}
|
2022-12-19 00:09:03 +05:30
|
|
|
.tag(Tabs.advanced)
|
2022-07-02 02:58:32 +05:30
|
|
|
|
2024-02-02 04:24:16 +05:30
|
|
|
Group {
|
|
|
|
ExportSettings()
|
|
|
|
}
|
|
|
|
.tabItem {
|
|
|
|
Label("Export", systemImage: "square.and.arrow.up")
|
|
|
|
}
|
|
|
|
.tag(Tabs.importExport)
|
|
|
|
|
2022-01-06 20:32:53 +05:30
|
|
|
Form {
|
|
|
|
Help()
|
|
|
|
}
|
|
|
|
.tabItem {
|
|
|
|
Label("Help", systemImage: "questionmark.circle")
|
|
|
|
}
|
2022-12-19 00:09:03 +05:30
|
|
|
.tag(Tabs.help)
|
2021-09-25 13:48:22 +05:30
|
|
|
}
|
|
|
|
.padding(20)
|
2024-02-02 04:24:16 +05:30
|
|
|
.frame(width: 700, 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")
|
2022-06-26 18:47:18 +05:30
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
2021-11-28 20:07:55 +05:30
|
|
|
|
2023-09-10 23:38:42 +05:30
|
|
|
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 18:47:18 +05:30
|
|
|
#if !os(macOS)
|
|
|
|
var settingsList: some View {
|
|
|
|
List {
|
|
|
|
#if os(tvOS)
|
2022-11-12 01:04:20 +05:30
|
|
|
if !accounts.isEmpty {
|
2022-12-12 03:45:56 +05:30
|
|
|
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-12 01:04:20 +05:30
|
|
|
Divider()
|
|
|
|
}
|
2022-06-26 18:47:18 +05:30
|
|
|
#endif
|
2022-01-06 20:32:53 +05:30
|
|
|
|
2022-06-26 18:47:18 +05:30
|
|
|
Section {
|
2022-11-12 01:58:40 +05:30
|
|
|
NavigationLink {
|
|
|
|
BrowsingSettings()
|
|
|
|
} label: {
|
2023-09-10 23:38:42 +05:30
|
|
|
Label("Browsing", systemImage: "list.and.film").labelStyle(SettingsLabel())
|
2022-06-26 18:47:18 +05:30
|
|
|
}
|
2022-01-06 20:32:53 +05:30
|
|
|
|
2022-06-26 18:47:18 +05:30
|
|
|
NavigationLink {
|
|
|
|
PlayerSettings()
|
|
|
|
} label: {
|
2023-09-10 23:38:42 +05:30
|
|
|
Label("Player", systemImage: "play.rectangle").labelStyle(SettingsLabel())
|
2022-01-06 20:32:53 +05:30
|
|
|
}
|
|
|
|
|
2022-12-19 18:05:37 +05:30
|
|
|
NavigationLink {
|
|
|
|
PlayerControlsSettings()
|
|
|
|
} label: {
|
2023-09-10 23:38:42 +05:30
|
|
|
Label("Controls", systemImage: "hand.tap").labelStyle(SettingsLabel())
|
2022-12-19 18:05:37 +05:30
|
|
|
}
|
|
|
|
|
2022-08-14 22:36:22 +05:30
|
|
|
NavigationLink {
|
|
|
|
QualitySettings()
|
|
|
|
} label: {
|
2023-09-10 23:38:42 +05:30
|
|
|
Label("Quality", systemImage: "4k.tv").labelStyle(SettingsLabel())
|
2022-08-14 22:36:22 +05:30
|
|
|
}
|
|
|
|
|
2022-06-26 18:47:18 +05:30
|
|
|
NavigationLink {
|
|
|
|
HistorySettings()
|
|
|
|
} label: {
|
2023-09-10 23:38:42 +05:30
|
|
|
Label("History", systemImage: "clock.arrow.circlepath").labelStyle(SettingsLabel())
|
2022-06-26 18:47:18 +05:30
|
|
|
}
|
|
|
|
|
2022-11-12 01:04:20 +05:30
|
|
|
if !accounts.isEmpty {
|
|
|
|
NavigationLink {
|
|
|
|
SponsorBlockSettings()
|
|
|
|
} label: {
|
2023-09-10 23:38:42 +05:30
|
|
|
Label("SponsorBlock", systemImage: "dollarsign.circle").labelStyle(SettingsLabel())
|
2022-11-12 01:04:20 +05:30
|
|
|
}
|
2022-01-06 20:32:53 +05:30
|
|
|
}
|
2022-07-02 02:58:32 +05:30
|
|
|
|
2022-11-13 16:44:05 +05:30
|
|
|
NavigationLink {
|
|
|
|
LocationsSettings()
|
|
|
|
} label: {
|
2023-09-10 23:38:42 +05:30
|
|
|
Label("Locations", systemImage: "globe").labelStyle(SettingsLabel())
|
2022-11-13 16:44:05 +05:30
|
|
|
}
|
|
|
|
|
2022-07-02 02:58:32 +05:30
|
|
|
NavigationLink {
|
|
|
|
AdvancedSettings()
|
|
|
|
} label: {
|
2023-09-10 23:38:42 +05:30
|
|
|
Label("Advanced", systemImage: "wrench.and.screwdriver").labelStyle(SettingsLabel())
|
2022-07-02 02:58:32 +05:30
|
|
|
}
|
2021-09-25 13:48:22 +05:30
|
|
|
}
|
2023-09-09 21:50:44 +05:30
|
|
|
#if os(tvOS)
|
|
|
|
.padding(.horizontal, 20)
|
|
|
|
#endif
|
2022-06-26 18:47:18 +05:30
|
|
|
|
2024-02-02 04:24:16 +05:30
|
|
|
importView
|
|
|
|
|
2022-07-04 04:09:05 +05:30
|
|
|
Section(footer: helpFooter) {
|
2022-06-26 18:47:18 +05:30
|
|
|
NavigationLink {
|
|
|
|
Help()
|
|
|
|
} label: {
|
2023-09-10 23:38:42 +05:30
|
|
|
Label("Help", systemImage: "questionmark.circle").labelStyle(SettingsLabel())
|
2021-09-25 13:48:22 +05:30
|
|
|
}
|
2021-09-27 03:33:33 +05:30
|
|
|
}
|
2023-09-09 21:50:44 +05:30
|
|
|
#if os(tvOS)
|
|
|
|
.padding(.horizontal, 20)
|
|
|
|
#endif
|
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)
|
2023-09-10 23:37:24 +05:30
|
|
|
.padding(.trailing, 6)
|
2022-07-04 03:43:06 +05:30
|
|
|
Text("Discord Server")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Link(destination: Self.matrixURL) {
|
|
|
|
HStack {
|
|
|
|
Image("Matrix")
|
|
|
|
.resizable()
|
|
|
|
.renderingMode(.template)
|
|
|
|
.frame(maxWidth: 30, maxHeight: 30)
|
2023-09-10 23:37:24 +05:30
|
|
|
.padding(.trailing, 6)
|
2022-07-04 03:43:06 +05:30
|
|
|
Text("Matrix Chat")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2021-09-25 13:48:22 +05:30
|
|
|
}
|
2022-06-26 18:47:18 +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
|
|
|
}
|
2022-06-26 18:47:18 +05:30
|
|
|
.frame(maxWidth: 1000)
|
|
|
|
#if os(iOS)
|
|
|
|
.listStyle(.insetGrouped)
|
2021-09-28 23:36:05 +05:30
|
|
|
#endif
|
2022-06-26 18:47:18 +05:30
|
|
|
}
|
|
|
|
#endif
|
2021-11-28 20:07:55 +05:30
|
|
|
|
2024-02-02 04:24:16 +05:30
|
|
|
var importView: some View {
|
|
|
|
Section {
|
|
|
|
Button(action: importSettings) {
|
|
|
|
Label("Import Settings...", systemImage: "square.and.arrow.down")
|
|
|
|
.frame(maxWidth: .infinity, alignment: .leading)
|
|
|
|
.contentShape(Rectangle())
|
|
|
|
}
|
2024-02-02 16:08:01 +05:30
|
|
|
.foregroundColor(.accentColor)
|
2024-02-02 04:24:16 +05:30
|
|
|
.buttonStyle(.plain)
|
|
|
|
|
|
|
|
NavigationLink(destination: LazyView(ExportSettings())) {
|
|
|
|
Label("Export Settings", systemImage: "square.and.arrow.up")
|
|
|
|
.frame(maxWidth: .infinity, alignment: .leading)
|
|
|
|
.contentShape(Rectangle())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func importSettings() {
|
|
|
|
navigation.presentingSettingsFileImporter = true
|
|
|
|
}
|
|
|
|
|
2022-01-06 20:32:53 +05:30
|
|
|
#if os(macOS)
|
|
|
|
private var windowHeight: Double {
|
|
|
|
switch selection {
|
|
|
|
case .browsing:
|
2023-07-22 22:32:59 +05:30
|
|
|
return 800
|
2022-01-06 20:32:53 +05:30
|
|
|
case .player:
|
2024-02-02 04:47:06 +05:30
|
|
|
return 550
|
2022-12-19 18:05:37 +05:30
|
|
|
case .controls:
|
2023-04-22 22:52:13 +05:30
|
|
|
return 920
|
2022-08-14 22:36:22 +05:30
|
|
|
case .quality:
|
2022-08-26 05:06:46 +05:30
|
|
|
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
|
2022-07-02 02:58:32 +05:30
|
|
|
case .advanced:
|
2024-02-02 04:24:16 +05:30
|
|
|
return 500
|
|
|
|
case .importExport:
|
|
|
|
return 580
|
2022-01-06 20:32:53 +05:30
|
|
|
case .help:
|
2022-11-19 05:08:32 +05:30
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|