2021-11-28 14:37:55 +00:00
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct InstanceSettings: View {
|
2022-07-21 21:52:09 +00:00
|
|
|
let instance: Instance
|
2021-11-28 14:37:55 +00:00
|
|
|
|
|
|
|
@State private var accountsChanged = false
|
|
|
|
@State private var presentingAccountForm = false
|
|
|
|
|
|
|
|
@State private var frontendURL = ""
|
2022-07-21 21:52:09 +00:00
|
|
|
@State private var proxiesVideos = false
|
2021-11-28 14:37:55 +00:00
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
List {
|
2022-01-06 15:02:53 +00:00
|
|
|
Section(header: Text("Accounts")) {
|
2021-11-28 14:37:55 +00:00
|
|
|
if instance.app.supportsAccounts {
|
2022-07-21 21:52:09 +00:00
|
|
|
ForEach(InstancesModel.accounts(instance.id), id: \.self) { account in
|
2021-11-28 14:37:55 +00:00
|
|
|
#if os(tvOS)
|
|
|
|
Button(account.description) {}
|
|
|
|
.contextMenu {
|
|
|
|
Button("Remove") { removeAccount(account) }
|
|
|
|
Button("Cancel", role: .cancel) {}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
ZStack {
|
|
|
|
NavigationLink(destination: EmptyView()) {
|
|
|
|
EmptyView()
|
|
|
|
}
|
|
|
|
.disabled(true)
|
|
|
|
.hidden()
|
|
|
|
|
|
|
|
HStack {
|
|
|
|
Text(account.description)
|
|
|
|
Spacer()
|
|
|
|
}
|
|
|
|
.contextMenu {
|
2022-01-06 15:02:53 +00:00
|
|
|
Button {
|
|
|
|
removeAccount(account)
|
|
|
|
} label: {
|
|
|
|
Label("Remove", systemImage: "trash")
|
|
|
|
}
|
2021-11-28 14:37:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
.redrawOn(change: accountsChanged)
|
|
|
|
|
2022-01-06 15:02:53 +00:00
|
|
|
Button {
|
2021-11-28 14:37:55 +00:00
|
|
|
presentingAccountForm = true
|
2022-01-06 15:02:53 +00:00
|
|
|
} label: {
|
|
|
|
Label("Add Account...", systemImage: "plus")
|
2021-11-28 14:37:55 +00:00
|
|
|
}
|
|
|
|
.sheet(isPresented: $presentingAccountForm, onDismiss: { accountsChanged.toggle() }) {
|
|
|
|
AccountForm(instance: instance)
|
|
|
|
}
|
|
|
|
#if !os(tvOS)
|
|
|
|
.listStyle(.insetGrouped)
|
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
Text("Accounts are not supported for the application of this instance")
|
|
|
|
.foregroundColor(.secondary)
|
|
|
|
}
|
|
|
|
}
|
2022-01-06 15:02:53 +00:00
|
|
|
if instance.app.hasFrontendURL {
|
|
|
|
Section(header: Text("Frontend URL")) {
|
|
|
|
TextField(
|
|
|
|
"Frontend URL",
|
|
|
|
text: $frontendURL
|
|
|
|
)
|
|
|
|
.onAppear {
|
|
|
|
frontendURL = instance.frontendURL ?? ""
|
|
|
|
}
|
|
|
|
.onChange(of: frontendURL) { newValue in
|
|
|
|
InstancesModel.setFrontendURL(instance, newValue)
|
|
|
|
}
|
|
|
|
.labelsHidden()
|
|
|
|
.autocapitalization(.none)
|
|
|
|
.keyboardType(.URL)
|
|
|
|
}
|
|
|
|
}
|
2022-07-21 21:52:09 +00:00
|
|
|
|
|
|
|
if instance.app.allowsDisablingVidoesProxying {
|
|
|
|
proxiesVideosToggle
|
|
|
|
.onAppear {
|
|
|
|
proxiesVideos = instance.proxiesVideos
|
|
|
|
}
|
|
|
|
.onChange(of: proxiesVideos) { newValue in
|
|
|
|
InstancesModel.setProxiesVideos(instance, newValue)
|
|
|
|
}
|
|
|
|
}
|
2021-11-28 14:37:55 +00:00
|
|
|
}
|
|
|
|
#if os(tvOS)
|
|
|
|
.frame(maxWidth: 1000)
|
|
|
|
#elseif os(iOS)
|
|
|
|
.listStyle(.insetGrouped)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
.navigationTitle(instance.description)
|
|
|
|
}
|
|
|
|
|
2022-07-21 21:52:09 +00:00
|
|
|
private var proxiesVideosToggle: some View {
|
|
|
|
Toggle("Proxy videos", isOn: $proxiesVideos)
|
|
|
|
}
|
|
|
|
|
2021-11-28 14:37:55 +00:00
|
|
|
private func removeAccount(_ account: Account) {
|
|
|
|
AccountsModel.remove(account)
|
|
|
|
accountsChanged.toggle()
|
|
|
|
}
|
|
|
|
}
|