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 {
|
2022-07-04 01:52:57 +05:30
|
|
|
case locations, browsing, player, history, sponsorBlock, advanced, help
|
2021-09-29 19:59:17 +05:30
|
|
|
}
|
2022-01-06 20:32:53 +05:30
|
|
|
|
2022-07-04 01:52:57 +05:30
|
|
|
@State private var selection = Tabs.locations
|
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
|
|
|
|
2021-11-13 02:16:15 +05:30
|
|
|
@EnvironmentObject<AccountsModel> private var accounts
|
2022-07-02 02:58:32 +05:30
|
|
|
@EnvironmentObject<NavigationModel> private var navigation
|
|
|
|
@EnvironmentObject<SettingsModel> private var model
|
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 {
|
2022-07-02 02:58:32 +05:30
|
|
|
settings
|
|
|
|
.environmentObject(model)
|
|
|
|
.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-07-04 01:52:57 +05:30
|
|
|
Form {
|
|
|
|
LocationsSettings()
|
|
|
|
}
|
|
|
|
.tabItem {
|
|
|
|
Label("Locations", systemImage: "globe")
|
|
|
|
}
|
|
|
|
.tag(Tabs.locations)
|
|
|
|
|
2021-11-05 04:55:51 +05:30
|
|
|
Form {
|
|
|
|
BrowsingSettings()
|
|
|
|
}
|
|
|
|
.tabItem {
|
|
|
|
Label("Browsing", systemImage: "list.and.film")
|
|
|
|
}
|
|
|
|
.tag(Tabs.browsing)
|
|
|
|
|
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-01-06 20:32:53 +05:30
|
|
|
.tag(Tabs.player)
|
2021-12-27 02:44:46 +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-01-06 20:32:53 +05:30
|
|
|
.tag(Tabs.history)
|
2021-10-23 17:42:53 +05:30
|
|
|
|
2021-09-25 13:48:22 +05:30
|
|
|
Form {
|
2022-01-06 20:32:53 +05:30
|
|
|
SponsorBlockSettings()
|
2021-09-25 13:48:22 +05:30
|
|
|
}
|
|
|
|
.tabItem {
|
2022-01-06 20:32:53 +05:30
|
|
|
Label("SponsorBlock", systemImage: "dollarsign.circle")
|
2021-09-25 13:48:22 +05:30
|
|
|
}
|
2022-01-06 20:32:53 +05:30
|
|
|
.tag(Tabs.sponsorBlock)
|
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")
|
|
|
|
}
|
|
|
|
.tag(Tabs.advanced)
|
|
|
|
|
2022-01-06 20:32:53 +05:30
|
|
|
Form {
|
|
|
|
Help()
|
|
|
|
}
|
|
|
|
.tabItem {
|
|
|
|
Label("Help", systemImage: "questionmark.circle")
|
|
|
|
}
|
|
|
|
.tag(Tabs.help)
|
2021-09-25 13:48:22 +05:30
|
|
|
}
|
|
|
|
.padding(20)
|
2022-01-06 20:32:53 +05:30
|
|
|
.frame(width: 480, height: windowHeight)
|
2021-09-25 13:48:22 +05:30
|
|
|
#else
|
2022-06-26 18:47:18 +05:30
|
|
|
Group {
|
|
|
|
#if os(tvOS)
|
|
|
|
settingsList
|
|
|
|
#else
|
|
|
|
NavigationView {
|
|
|
|
settingsList
|
2021-11-28 20:07:55 +05:30
|
|
|
}
|
2022-06-26 18:47:18 +05:30
|
|
|
#endif
|
|
|
|
}
|
2022-07-02 02:58:32 +05:30
|
|
|
|
2022-06-26 18:47:18 +05:30
|
|
|
#endif
|
|
|
|
}
|
2021-11-28 20:07:55 +05:30
|
|
|
|
2022-06-26 18:47:18 +05:30
|
|
|
#if !os(macOS)
|
|
|
|
var settingsList: some View {
|
|
|
|
List {
|
|
|
|
#if os(tvOS)
|
|
|
|
AccountSelectionView()
|
|
|
|
Divider()
|
|
|
|
#endif
|
2022-01-06 20:32:53 +05:30
|
|
|
|
2022-06-26 18:47:18 +05:30
|
|
|
Section {
|
|
|
|
#if os(tvOS)
|
2022-01-06 20:32:53 +05:30
|
|
|
NavigationLink {
|
2022-06-26 18:47:18 +05:30
|
|
|
EditFavorites()
|
2022-01-06 20:32:53 +05:30
|
|
|
} label: {
|
2022-06-26 18:47:18 +05:30
|
|
|
Label("Favorites", systemImage: "heart.fill")
|
2022-01-06 20:32:53 +05:30
|
|
|
}
|
2022-06-26 18:47:18 +05:30
|
|
|
#endif
|
2022-01-06 20:32:53 +05:30
|
|
|
|
2022-07-04 01:52:57 +05:30
|
|
|
NavigationLink {
|
|
|
|
LocationsSettings()
|
|
|
|
} label: {
|
|
|
|
Label("Locations", systemImage: "globe")
|
|
|
|
}
|
|
|
|
|
2022-06-26 18:47:18 +05:30
|
|
|
NavigationLink {
|
|
|
|
BrowsingSettings()
|
|
|
|
} label: {
|
|
|
|
Label("Browsing", systemImage: "list.and.film")
|
|
|
|
}
|
2022-01-06 20:32:53 +05:30
|
|
|
|
2022-06-26 18:47:18 +05:30
|
|
|
NavigationLink {
|
|
|
|
PlayerSettings()
|
|
|
|
} label: {
|
|
|
|
Label("Player", systemImage: "play.rectangle")
|
2022-01-06 20:32:53 +05:30
|
|
|
}
|
|
|
|
|
2022-06-26 18:47:18 +05:30
|
|
|
NavigationLink {
|
|
|
|
HistorySettings()
|
|
|
|
} label: {
|
|
|
|
Label("History", systemImage: "clock.arrow.circlepath")
|
|
|
|
}
|
|
|
|
|
|
|
|
NavigationLink {
|
|
|
|
SponsorBlockSettings()
|
|
|
|
} label: {
|
|
|
|
Label("SponsorBlock", systemImage: "dollarsign.circle")
|
2022-01-06 20:32:53 +05:30
|
|
|
}
|
2022-07-02 02:58:32 +05:30
|
|
|
|
|
|
|
NavigationLink {
|
|
|
|
AdvancedSettings()
|
|
|
|
} label: {
|
|
|
|
Label("Advanced", systemImage: "wrench.and.screwdriver")
|
|
|
|
}
|
2021-09-25 13:48:22 +05:30
|
|
|
}
|
2022-06-26 18:47:18 +05:30
|
|
|
|
2022-07-04 04:09:05 +05:30
|
|
|
Section(footer: helpFooter) {
|
2022-06-26 18:47:18 +05:30
|
|
|
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
|
|
|
}
|
2022-06-26 18:47:18 +05:30
|
|
|
.navigationTitle("Settings")
|
|
|
|
.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
|
|
|
|
2022-01-06 20:32:53 +05:30
|
|
|
#if os(macOS)
|
|
|
|
private var windowHeight: Double {
|
|
|
|
switch selection {
|
|
|
|
case .browsing:
|
2022-06-27 03:47:32 +05:30
|
|
|
return 390
|
2022-01-06 20:32:53 +05:30
|
|
|
case .player:
|
2022-07-11 23:31:27 +05:30
|
|
|
return 420
|
2022-01-06 20:32:53 +05:30
|
|
|
case .history:
|
|
|
|
return 480
|
|
|
|
case .sponsorBlock:
|
2022-01-08 00:16:47 +05:30
|
|
|
return 660
|
2022-07-02 02:58:32 +05:30
|
|
|
case .locations:
|
|
|
|
return 480
|
|
|
|
case .advanced:
|
2022-07-11 23:31:27 +05:30
|
|
|
return 340
|
2022-01-06 20:32:53 +05:30
|
|
|
case .help:
|
2022-07-04 03:43:06 +05:30
|
|
|
return 600
|
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)
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|