Ferrite-backup/Ferrite/Views/CommonViews/HybridSecureField.swift
kingbri cc550dd208 Debrid: Various updates to API and settings
Debrid services can change their APIs at any time which negatively
impacts user experiences on Ferrite.

Add the following:
- Ability for a user to add a manually generated API key only showing the
last 4 characters for security purposes.
- Make ephemeral auth sessions toggle-able. ASWebAuthenticationView does
not automatically clear on toggle change.
- Add the savedLinks endpoint for AllDebrid so users can access their
downloads and magnets.
- Add a links section to AD's cloud view.

Signed-off-by: kingbri <bdashore3@proton.me>
2023-05-01 18:07:15 -04:00

62 lines
1.7 KiB
Swift

//
// HybridSecureField.swift
// Ferrite
//
// Created by Brian Dashore on 3/4/23.
//
import SwiftUI
struct HybridSecureField: View {
enum Field: Hashable {
case plain
case secure
}
@Binding var text: String
var onCommit: () -> Void = {}
@State private var showPassword = false
@FocusState private var focusedField: Field?
private var isFieldDisabled: Bool = false
init(text: Binding<String>, onCommit: (() -> Void)? = nil, showPassword: Bool = false) {
self._text = text
if let onCommit {
self.onCommit = onCommit
}
self.showPassword = showPassword
}
var body: some View {
HStack {
Group {
if showPassword {
TextField("Password", text: $text, onCommit: onCommit)
.focused($focusedField, equals: .plain)
} else {
SecureField("Password", text: $text, onCommit: onCommit)
.focused($focusedField, equals: .secure)
}
}
.autocorrectionDisabled(true)
.autocapitalization(.none)
.disabledAppearance(isFieldDisabled)
Button {
showPassword.toggle()
focusedField = showPassword ? .plain : .secure
} label: {
Image(systemName: showPassword ? "eye.slash.fill" : "eye.fill")
.foregroundColor(.secondary)
}
.buttonStyle(.borderless)
}
}
}
extension HybridSecureField {
public func fieldDisabled(_ isFieldDisabled: Bool) -> Self {
modifyViewProp({ $0.isFieldDisabled = isFieldDisabled })
}
}