87 lines
2.5 KiB
Swift
87 lines
2.5 KiB
Swift
import Models
|
|
import Services
|
|
import SwiftUI
|
|
import Utils
|
|
import Views
|
|
|
|
class SelfHostSettingsViewModel: ObservableObject {
|
|
@State var showCreateError = false
|
|
}
|
|
|
|
struct SelfHostSettingsView: View {
|
|
@State var apiServerAddress = ""
|
|
@State var webServerAddress = ""
|
|
@State var ttsServerAddress = ""
|
|
|
|
@State var showConfirmAlert = false
|
|
|
|
@Environment(\.dismiss) private var dismiss
|
|
|
|
@EnvironmentObject var dataService: DataService
|
|
@StateObject var viewModel = SelfHostSettingsViewModel()
|
|
|
|
var allFieldsSet: Bool {
|
|
apiServerAddress.count > 0 && webServerAddress.count > 0 && ttsServerAddress.count > 0
|
|
}
|
|
|
|
var saveButton: some View {
|
|
Button(action: {
|
|
showConfirmAlert = true
|
|
}, label: {
|
|
Text("Save")
|
|
})
|
|
.disabled(!allFieldsSet)
|
|
}
|
|
|
|
var body: some View {
|
|
Form {
|
|
Section("API Server Base URL") {
|
|
TextField("URL", text: $apiServerAddress, prompt: Text("https://api-prod.omnivore.app"))
|
|
.keyboardType(.URL)
|
|
}
|
|
|
|
Section("Web Server URL") {
|
|
TextField("URL", text: $webServerAddress, prompt: Text("https://omnivore.app"))
|
|
.keyboardType(.URL)
|
|
}
|
|
|
|
Section("Text-to-speech Server URL") {
|
|
TextField("URL", text: $ttsServerAddress, prompt: Text("https://tts.omnivore.app"))
|
|
.keyboardType(.URL)
|
|
}
|
|
|
|
Section {
|
|
Section {
|
|
Text("""
|
|
Omnivore is a free and open-source project and allows self-hosting.
|
|
|
|
If you have chosen to deploy your own server instance, fill in the \
|
|
above fields to connect to your private self-hosted instance.
|
|
|
|
[Learn more about self-hosting Omnivore](https://docs.omnivore.app/self-hosting/self-hosting.html)
|
|
""")
|
|
.accentColor(.blue)
|
|
}
|
|
}
|
|
}
|
|
.accentColor(.appGrayText)
|
|
.alert(isPresented: $showConfirmAlert) {
|
|
Alert(
|
|
title: Text("Changing your environment settings will close the app."),
|
|
dismissButton: .cancel(Text("Ok")) {
|
|
AppEnvironment.setCustom(serverBaseURL: apiServerAddress, webAppBaseURL: webServerAddress, ttsBaseURL: ttsServerAddress)
|
|
dataService.switchAppEnvironment(appEnvironment: AppEnvironment.custom)
|
|
}
|
|
)
|
|
}
|
|
.navigationViewStyle(.stack)
|
|
.navigationTitle("Self-hosting Options")
|
|
.navigationBarTitleDisplayMode(.inline)
|
|
.navigationBarItems(leading:
|
|
Button(action: {
|
|
dismiss()
|
|
}, label: { Text("Cancel") }),
|
|
trailing: saveButton)
|
|
}
|
|
}
|