users can now choose between http and https

This commit is contained in:
Vincent Meilinger
2024-01-07 17:10:47 +01:00
parent 5c7ff578c7
commit 2ed664857b
10 changed files with 105 additions and 176 deletions

View File

@@ -181,11 +181,8 @@ struct LoginTextField: View {
struct ServerAddressField: View {
@Binding var addressString: String
@State var serverAddress: String = ""
@ObservedObject var userSettings = UserSettings.shared
@State var serverProtocol: ServerProtocol = .https
@State var serverPort: String = ""
@State var useNonStandardPort: Bool = false
enum ServerProtocol: String {
case https="https://", http="http://"
@@ -205,22 +202,26 @@ struct ServerAddressField: View {
}.pickerStyle(.menu)
.tint(.white)
.font(.headline)
.onChange(of: serverProtocol) { color in
userSettings.serverProtocol = color.rawValue
}
TextField("e.g.: example.com", text: $userSettings.serverAddress)
.textFieldStyle(.plain)
.autocorrectionDisabled()
.textInputAutocapitalization(.never)
.foregroundStyle(.white)
.padding()
.background(
RoundedRectangle(cornerRadius: 10)
.foregroundColor(Color.white.opacity(0.2))
)
LoginTextField(example: "e.g.: example.com", text: $serverAddress)
}
Toggle("Use a non-standard port", isOn: $useNonStandardPort)
.tint(.white.opacity(0.2))
.foregroundStyle(.white)
.font(.headline)
.padding(.top)
if useNonStandardPort {
LoginTextField(example: "e.g.: 80", text: $serverPort)
}
LoginLabel(text: "Full server address")
.padding(.top)
Text(createServerAddressString())
Text(userSettings.serverProtocol + userSettings.serverAddress)
.foregroundColor(.white)
.padding(.vertical, 5)
}
@@ -230,26 +231,13 @@ struct ServerAddressField: View {
.stroke(.white, lineWidth: 2)
.foregroundColor(.clear)
)
}.animation(.easeInOut, value: useNonStandardPort)
}
func createServerAddressString() -> String {
if useNonStandardPort && serverPort != "" {
addressString = serverProtocol.rawValue + serverAddress + ":" + serverPort
} else {
addressString = serverProtocol.rawValue + serverAddress
}
return addressString
}
}
struct ServerAddressField_Preview: PreviewProvider {
static var previews: some View {
ServerAddressField(addressString: .constant(""),
serverAddress: "example.com",
serverProtocol: .https,
serverPort: "80",
useNonStandardPort: true)
ServerAddressField()
.previewLayout(.sizeThatFits)
.padding()
.background(Color.nextcloudBlue)