2021-09-25 08:18:22 +00:00
|
|
|
import Defaults
|
|
|
|
import Foundation
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct SettingsView: View {
|
2021-09-29 14:29:17 +00:00
|
|
|
#if os(macOS)
|
|
|
|
private enum Tabs: Hashable {
|
2022-06-07 23:14:47 +00:00
|
|
|
case instances, browsing, player, history, sponsorBlock, help
|
2021-09-29 14:29:17 +00:00
|
|
|
}
|
2022-01-06 15:02:53 +00:00
|
|
|
|
|
|
|
@State private var selection = Tabs.instances
|
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
|
|
|
|
2021-11-12 20:46:15 +00:00
|
|
|
@EnvironmentObject<AccountsModel> private var accounts
|
|
|
|
|
2021-11-28 14:37:55 +00:00
|
|
|
@State private var presentingInstanceForm = false
|
|
|
|
@State private var savedFormInstanceID: Instance.ID?
|
|
|
|
|
|
|
|
@Default(.instances) private var instances
|
|
|
|
|
2021-09-25 08:18:22 +00:00
|
|
|
var body: some View {
|
|
|
|
#if os(macOS)
|
2022-01-06 15:02:53 +00:00
|
|
|
TabView(selection: $selection) {
|
2021-09-25 08:18:22 +00:00
|
|
|
Form {
|
2021-10-23 11:51:02 +00:00
|
|
|
InstancesSettings()
|
2021-11-12 20:46:15 +00:00
|
|
|
.environmentObject(accounts)
|
2021-09-25 08:18:22 +00:00
|
|
|
}
|
|
|
|
.tabItem {
|
|
|
|
Label("Instances", systemImage: "server.rack")
|
|
|
|
}
|
|
|
|
.tag(Tabs.instances)
|
|
|
|
|
2021-11-04 23:25:51 +00:00
|
|
|
Form {
|
|
|
|
BrowsingSettings()
|
|
|
|
}
|
|
|
|
.tabItem {
|
|
|
|
Label("Browsing", systemImage: "list.and.film")
|
|
|
|
}
|
|
|
|
.tag(Tabs.browsing)
|
|
|
|
|
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-01-06 15:02:53 +00:00
|
|
|
.tag(Tabs.player)
|
2021-12-26 21:14:46 +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-01-06 15:02:53 +00:00
|
|
|
.tag(Tabs.history)
|
2021-10-23 12:12:53 +00:00
|
|
|
|
2021-09-25 08:18:22 +00:00
|
|
|
Form {
|
2022-01-06 15:02:53 +00:00
|
|
|
SponsorBlockSettings()
|
2021-09-25 08:18:22 +00:00
|
|
|
}
|
|
|
|
.tabItem {
|
2022-01-06 15:02:53 +00:00
|
|
|
Label("SponsorBlock", systemImage: "dollarsign.circle")
|
2021-09-25 08:18:22 +00:00
|
|
|
}
|
2022-01-06 15:02:53 +00:00
|
|
|
.tag(Tabs.sponsorBlock)
|
2021-12-07 23:09:49 +00:00
|
|
|
|
2022-01-06 15:02:53 +00:00
|
|
|
Form {
|
|
|
|
Help()
|
|
|
|
}
|
|
|
|
.tabItem {
|
|
|
|
Label("Help", systemImage: "questionmark.circle")
|
|
|
|
}
|
|
|
|
.tag(Tabs.help)
|
2021-09-25 08:18:22 +00:00
|
|
|
}
|
|
|
|
.padding(20)
|
2022-01-06 15:02:53 +00:00
|
|
|
.frame(width: 480, height: windowHeight)
|
2021-09-25 08:18:22 +00:00
|
|
|
#else
|
|
|
|
NavigationView {
|
|
|
|
List {
|
2021-09-28 18:06:05 +00:00
|
|
|
#if os(tvOS)
|
|
|
|
AccountSelectionView()
|
|
|
|
#endif
|
2021-11-28 14:37:55 +00:00
|
|
|
|
|
|
|
Section(header: Text("Instances")) {
|
|
|
|
ForEach(instances) { instance in
|
|
|
|
AccountsNavigationLink(instance: instance)
|
|
|
|
}
|
|
|
|
addInstanceButton
|
|
|
|
}
|
|
|
|
|
2022-01-06 15:02:53 +00:00
|
|
|
#if os(tvOS)
|
|
|
|
Divider()
|
|
|
|
#endif
|
|
|
|
|
|
|
|
Section {
|
|
|
|
#if os(tvOS)
|
|
|
|
NavigationLink {
|
|
|
|
EditFavorites()
|
|
|
|
} label: {
|
|
|
|
Label("Favorites", systemImage: "heart.fill")
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
NavigationLink {
|
|
|
|
BrowsingSettings()
|
|
|
|
} label: {
|
|
|
|
Label("Browsing", systemImage: "list.and.film")
|
|
|
|
}
|
|
|
|
|
|
|
|
NavigationLink {
|
|
|
|
PlayerSettings()
|
|
|
|
} label: {
|
|
|
|
Label("Player", systemImage: "play.rectangle")
|
|
|
|
}
|
|
|
|
|
|
|
|
NavigationLink {
|
|
|
|
HistorySettings()
|
|
|
|
} label: {
|
|
|
|
Label("History", systemImage: "clock.arrow.circlepath")
|
|
|
|
}
|
|
|
|
|
|
|
|
NavigationLink {
|
|
|
|
SponsorBlockSettings()
|
|
|
|
} label: {
|
|
|
|
Label("SponsorBlock", systemImage: "dollarsign.circle")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Section(footer: versionString) {
|
|
|
|
NavigationLink {
|
|
|
|
Help()
|
|
|
|
} label: {
|
|
|
|
Label("Help", systemImage: "questionmark.circle")
|
|
|
|
}
|
|
|
|
}
|
2021-09-25 08:18:22 +00:00
|
|
|
}
|
|
|
|
.navigationTitle("Settings")
|
2021-09-26 22:03:33 +00:00
|
|
|
.toolbar {
|
2022-01-06 15:02:53 +00:00
|
|
|
ToolbarItem(placement: .navigationBarLeading) {
|
2021-09-26 22:03:33 +00:00
|
|
|
#if !os(tvOS)
|
2021-09-28 18:06:05 +00:00
|
|
|
Button("Done") {
|
2021-11-28 14:37:55 +00:00
|
|
|
presentationMode.wrappedValue.dismiss()
|
2021-09-28 18:06:05 +00:00
|
|
|
}
|
2021-09-26 22:03:33 +00:00
|
|
|
.keyboardShortcut(.cancelAction)
|
|
|
|
#endif
|
2021-09-25 08:18:22 +00:00
|
|
|
}
|
2021-09-26 22:03:33 +00:00
|
|
|
}
|
2021-09-28 18:06:05 +00:00
|
|
|
.frame(maxWidth: 1000)
|
2021-09-26 22:03:33 +00:00
|
|
|
#if os(iOS)
|
|
|
|
.listStyle(.insetGrouped)
|
|
|
|
#endif
|
2021-09-25 08:18:22 +00:00
|
|
|
}
|
2021-11-28 14:37:55 +00:00
|
|
|
.sheet(isPresented: $presentingInstanceForm) {
|
|
|
|
InstanceForm(savedInstanceID: $savedFormInstanceID)
|
|
|
|
}
|
2021-09-28 18:06:05 +00:00
|
|
|
#if os(tvOS)
|
2021-12-05 17:09:25 +00:00
|
|
|
.background(Color.background(scheme: colorScheme))
|
2021-09-28 18:06:05 +00:00
|
|
|
#endif
|
2021-09-25 08:18:22 +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 .instances:
|
|
|
|
return 390
|
|
|
|
case .browsing:
|
|
|
|
return 350
|
|
|
|
case .player:
|
2022-04-16 17:50:02 +00:00
|
|
|
return 450
|
2022-01-06 15:02:53 +00:00
|
|
|
case .history:
|
|
|
|
return 480
|
|
|
|
case .sponsorBlock:
|
2022-01-07 18:46:47 +00:00
|
|
|
return 660
|
2022-01-06 15:02:53 +00:00
|
|
|
case .help:
|
|
|
|
return 570
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
private var versionString: some View {
|
|
|
|
Text("Yattee \(YatteeApp.version) (build \(YatteeApp.build))")
|
|
|
|
#if os(tvOS)
|
|
|
|
.foregroundColor(.secondary)
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2021-11-28 14:37:55 +00:00
|
|
|
private var addInstanceButton: some View {
|
2022-01-06 15:02:53 +00:00
|
|
|
Button {
|
2021-11-28 14:37:55 +00:00
|
|
|
presentingInstanceForm = true
|
2022-01-06 15:02:53 +00:00
|
|
|
} label: {
|
|
|
|
Label("Add Instance...", systemImage: "plus")
|
2021-11-28 14:37:55 +00:00
|
|
|
}
|
|
|
|
}
|
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)
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|