Protocols can't be used in ObservedObjects. Observable in iOS 17 and up solves this, but Ferrite targets iOS 16 and up, so add a type-erased StateObject which supports protocols. Signed-off-by: kingbri <bdashore3@proton.me>
78 lines
2.9 KiB
Swift
78 lines
2.9 KiB
Swift
//
|
|
// DebridInfoView.swift
|
|
// Ferrite
|
|
//
|
|
// Created by Brian Dashore on 3/5/23.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
struct SettingsDebridInfoView: View {
|
|
@EnvironmentObject var debridManager: DebridManager
|
|
|
|
@Store var debridSource: DebridSource
|
|
|
|
@State private var apiKeyTempText: String = ""
|
|
|
|
var body: some View {
|
|
List {
|
|
Section(header: InlineHeader("Description")) {
|
|
VStack(alignment: .leading, spacing: 10) {
|
|
Text("\(debridSource.id.name) is a debrid service that is used for unrestricting downloads and media playback. You must pay to access the service.")
|
|
|
|
Link("Website", destination: URL(string: debridSource.id.website) ?? URL(string: "https://kingbri.dev/ferrite")!)
|
|
}
|
|
}
|
|
|
|
Section(
|
|
header: InlineHeader("Login status"),
|
|
footer: Text("A WebView will show up to prompt you for credentials")
|
|
) {
|
|
Button {
|
|
Task {
|
|
if debridSource.isLoggedIn {
|
|
//await debridManager.logoutDebrid(debridType: debridType)
|
|
} else if !debridSource.authProcessing {
|
|
//await debridManager.authenticateDebrid(debridType: debridType, apiKey: nil)
|
|
}
|
|
|
|
//apiKeyTempText = await debridManager.getManualAuthKey(debridType) ?? ""
|
|
}
|
|
} label: {
|
|
Text(
|
|
debridSource.isLoggedIn
|
|
? "Logout"
|
|
: (debridSource.authProcessing ? "Processing" : "Login")
|
|
)
|
|
.foregroundColor(debridSource.isLoggedIn ? .red : .blue)
|
|
}
|
|
}
|
|
|
|
Section(
|
|
header: InlineHeader("API key"),
|
|
footer: Text("Add a permanent API key here. Only use this if web authentication does not work!")
|
|
) {
|
|
HybridSecureField(
|
|
text: $apiKeyTempText,
|
|
onCommit: {
|
|
Task {
|
|
if !apiKeyTempText.isEmpty {
|
|
//await debridManager.authenticateDebrid(debridType: debridType, apiKey: apiKeyTempText)
|
|
//apiKeyTempText = await debridManager.getManualAuthKey(debridType) ?? ""
|
|
}
|
|
}
|
|
}
|
|
)
|
|
.fieldDisabled(debridSource.isLoggedIn)
|
|
}
|
|
.onAppear {
|
|
Task {
|
|
//apiKeyTempText = await debridManager.getManualAuthKey(debridType) ?? ""
|
|
}
|
|
}
|
|
}
|
|
.listStyle(.insetGrouped)
|
|
.navigationTitle(debridSource.id.name)
|
|
.navigationBarTitleDisplayMode(.inline)
|
|
}
|
|
}
|