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

220 lines
6.5 KiB
Swift
Raw Normal View History

2021-09-25 13:48:22 +05:30
import Defaults
import Foundation
import SwiftUI
struct SettingsView: View {
#if os(macOS)
private enum Tabs: Hashable {
2022-01-06 20:32:53 +05:30
case instances, browsing, player, history, sponsorBlock, updates, help
}
2022-01-06 20:32:53 +05:30
@State private var selection = Tabs.instances
#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
2021-11-13 02:16:15 +05:30
@EnvironmentObject<AccountsModel> private var accounts
2021-11-28 20:07:55 +05:30
@State private var presentingInstanceForm = false
@State private var savedFormInstanceID: Instance.ID?
@Default(.instances) private var instances
2021-09-25 13:48:22 +05:30
var body: some View {
#if os(macOS)
2022-01-06 20:32:53 +05:30
TabView(selection: $selection) {
2021-09-25 13:48:22 +05:30
Form {
2021-10-23 17:21:02 +05:30
InstancesSettings()
2021-11-13 02:16:15 +05:30
.environmentObject(accounts)
2021-09-25 13:48:22 +05:30
}
.tabItem {
Label("Instances", systemImage: "server.rack")
}
.tag(Tabs.instances)
2021-11-05 04:55:51 +05:30
Form {
BrowsingSettings()
}
.tabItem {
Label("Browsing", systemImage: "list.and.film")
}
.tag(Tabs.browsing)
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-01-06 20:32:53 +05:30
.tag(Tabs.player)
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
Form {
UpdatesSettings()
}
.tabItem {
Label("Updates", systemImage: "gearshape.2")
}
.tag(Tabs.updates)
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
NavigationView {
List {
#if os(tvOS)
AccountSelectionView()
#endif
2021-11-28 20:07:55 +05:30
Section(header: Text("Instances")) {
ForEach(instances) { instance in
AccountsNavigationLink(instance: instance)
}
addInstanceButton
}
2022-01-06 20:32:53 +05:30
#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 13:48:22 +05:30
}
.navigationTitle("Settings")
2021-09-27 03:33:33 +05:30
.toolbar {
2022-01-06 20:32:53 +05:30
ToolbarItem(placement: .navigationBarLeading) {
2021-09-27 03:33:33 +05:30
#if !os(tvOS)
Button("Done") {
2021-11-28 20:07:55 +05:30
presentationMode.wrappedValue.dismiss()
}
2021-09-27 03:33:33 +05:30
.keyboardShortcut(.cancelAction)
#endif
2021-09-25 13:48:22 +05:30
}
2021-09-27 03:33:33 +05:30
}
.frame(maxWidth: 1000)
2021-09-27 03:33:33 +05:30
#if os(iOS)
.listStyle(.insetGrouped)
#endif
2021-09-25 13:48:22 +05:30
}
2021-11-28 20:07:55 +05:30
.sheet(isPresented: $presentingInstanceForm) {
InstanceForm(savedInstanceID: $savedFormInstanceID)
}
#if os(tvOS)
.background(Color.background(scheme: colorScheme))
#endif
2021-09-25 13:48:22 +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 .instances:
return 390
case .browsing:
return 350
case .player:
return 450
case .history:
return 480
case .sponsorBlock:
2022-01-08 00:16:47 +05:30
return 660
2022-01-06 20:32:53 +05:30
case .updates:
return 200
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 20:07:55 +05:30
private var addInstanceButton: some View {
2022-01-06 20:32:53 +05:30
Button {
2021-11-28 20:07:55 +05:30
presentingInstanceForm = true
2022-01-06 20:32:53 +05:30
} label: {
Label("Add Instance...", systemImage: "plus")
2021-11-28 20:07:55 +05:30
}
}
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
}
}