summaryrefslogtreecommitdiff
path: root/Sora/Views/Settings/Section/SettingsSectionProviderView.swift
diff options
context:
space:
mode:
Diffstat (limited to 'Sora/Views/Settings/Section/SettingsSectionProviderView.swift')
-rw-r--r--Sora/Views/Settings/Section/SettingsSectionProviderView.swift72
1 files changed, 50 insertions, 22 deletions
diff --git a/Sora/Views/Settings/Section/SettingsSectionProviderView.swift b/Sora/Views/Settings/Section/SettingsSectionProviderView.swift
index cbfae37..02a8be6 100644
--- a/Sora/Views/Settings/Section/SettingsSectionProviderView.swift
+++ b/Sora/Views/Settings/Section/SettingsSectionProviderView.swift
@@ -1,16 +1,19 @@
import SwiftUI
struct SettingsSectionProviderView: View {
- @EnvironmentObject var settings: SettingsManager
+ @Environment(SettingsManager.self)
+ private var settings
@State private var showingCustomBooruSheet = false
@State private var newDomain: String = ""
@State private var newFlavor: BooruProviderFlavor = .danbooru
@State private var domainError: String?
var body: some View {
+ @Bindable var settings = settings
+
Form {
- Section(header: Text("Provider Selection")) {
- Picker("Provider", selection: $settings.preferredBooru) {
+ Section("Source") {
+ Picker("Website", selection: $settings.preferredBooru) {
ForEach(BooruProvider.allCases, id: \.self) { type in
Text(type.rawValue).tag(type)
}
@@ -22,11 +25,13 @@ struct SettingsSectionProviderView: View {
}
}
- Section(header: Text("Moebooru Feed")) {
- Toggle("Show Held Posts", isOn: $settings.showHeldMoebooruPosts)
+ if BooruProviderFlavor(provider: settings.preferredBooru) == .moebooru {
+ Section("Hidden Posts") {
+ Toggle("Show Hidden Posts", isOn: $settings.showHeldMoebooruPosts)
+ }
}
- Section(header: Text("API Credentials")) {
+ Section {
SecureField(
"API Key",
text: Binding(
@@ -65,23 +70,40 @@ struct SettingsSectionProviderView: View {
#if os(iOS)
.keyboardType(isDanbooruProvider ? .default : .numberPad)
#endif
+ } header: {
+ Text("Account")
+ } footer: {
+ Text("Add credentials only if your selected source supports them.")
}
- Section(header: Text("Custom Providers")) {
- Button("Add Custom Provider") {
+ Section {
+ Toggle("Send User Agent", isOn: $settings.sendBooruUserAgent)
+
+ if settings.sendBooruUserAgent {
+ TextField("Custom User Agent", text: $settings.customBooruUserAgent)
+ .autocorrectionDisabled(true)
+ }
+ } header: {
+ Text("Advanced")
+ } footer: {
+ Text("Only change these options if a source requires them.")
+ }
+
+ Section {
+ Button("Add Source") {
showingCustomBooruSheet = true
}
.trailingFrame()
if case .custom(let provider) = settings.preferredBooru {
- Button("Remove Custom Provider") {
+ Button("Remove Current Source") {
settings.customProviders.removeAll { $0.id == provider.id }
settings.preferredBooru = .safebooru
}
.disabled(!settings.customProviders.contains { $0.id == provider.id })
}
- Button("Remove All Custom Providers") {
+ Button("Remove All Custom Sources") {
if case .custom = settings.preferredBooru {
settings.preferredBooru = .safebooru
}
@@ -91,23 +113,27 @@ struct SettingsSectionProviderView: View {
}
}
.trailingFrame()
+ } header: {
+ Text("Custom Sources")
+ } footer: {
+ Text("Use custom sources when you want Sora to browse a compatible site.")
}
}
#if os(macOS)
.formStyle(.grouped)
#endif
- .navigationTitle("Provider")
+ .navigationTitle("Source")
#if !os(macOS)
.navigationBarTitleDisplayMode(.large)
#endif
.sheet(isPresented: $showingCustomBooruSheet) {
NavigationStack {
Form {
- Section(header: Text("Provider Details")) {
- TextField("Domain", text: $newDomain)
+ Section("Source Details") {
+ TextField("Website", text: $newDomain)
.autocorrectionDisabled(true)
- Picker("Provider Type", selection: $newFlavor) {
+ Picker("Type", selection: $newFlavor) {
ForEach(BooruProviderFlavor.allCases, id: \.self) { flavor in
Text(flavor.rawValue).tag(flavor)
}
@@ -117,7 +143,7 @@ struct SettingsSectionProviderView: View {
#if os(macOS)
.formStyle(.grouped)
#endif
- .navigationTitle("Add Custom Provider")
+ .navigationTitle("Add Source")
#if !os(macOS)
.navigationBarTitleDisplayMode(.inline)
#endif
@@ -142,7 +168,7 @@ struct SettingsSectionProviderView: View {
}
}
.alert(
- "Invalid Domain",
+ "Invalid Website",
isPresented: Binding(
get: { domainError != nil },
set: { if !$0 { domainError = nil } }
@@ -150,7 +176,9 @@ struct SettingsSectionProviderView: View {
) {
Button("OK", role: .cancel) { () }
} message: {
- Text(domainError ?? "An unknown error occurred while validating the domain.")
+ if let domainError {
+ Text(domainError)
+ }
}
}
@@ -183,19 +211,19 @@ struct SettingsSectionProviderView: View {
"^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)*\\.[a-z]{2,}$"
guard NSPredicate(format: "SELF MATCHES %@", domainRegex).evaluate(with: domain) else {
- domainError = "Please enter a valid domain name, such as yande.re."
+ domainError = "Enter a valid website, such as yande.re."
return false
}
guard !domain.contains("://"), !domain.contains("/"), !domain.contains("?") else {
- domainError = "Only enter the domain name—leave out 'http://' or extra details."
+ domainError = "Enter only the website name, without 'http://' or extra details."
return false
}
guard domain.count <= 253 else { // RFC 1035
- domainError = "This domain name is too long. It must be 253 characters or fewer."
+ domainError = "This website name is too long. It must be 253 characters or fewer."
return false
}
@@ -203,7 +231,7 @@ struct SettingsSectionProviderView: View {
let labels = domain.split(separator: ".")
guard labels.allSatisfy({ $0.count <= 63 }) else {
- domainError = "Each section of the domain name must be 63 characters or fewer."
+ domainError = "Each section of the website name must be 63 characters or fewer."
return false
}
@@ -248,6 +276,6 @@ struct SettingsSectionProviderView: View {
#Preview {
NavigationStack {
SettingsSectionProviderView()
- .environmentObject(SettingsManager())
+ .environment(SettingsManager())
}
}