Library: Fix debrid cloud fetch in iOS 14
onAppear wasn't being called with the current implementation of the cloud tab in library. Fix this to listen to the selectedDebridType variable instead of relying on the onAppear call of a view.y Also do some further project cleanup and LOC removal Signed-off-by: kingbri <bdashore3@proton.me>
This commit is contained in:
parent
e0784b3cec
commit
254058928f
8 changed files with 36 additions and 46 deletions
|
|
@ -37,11 +37,7 @@ extension View {
|
|||
modifier(ViewDidAppearModifier(callback: callback))
|
||||
}
|
||||
|
||||
func customScopeBar(_ content: some View) -> some View {
|
||||
modifier(CustomScopeBarModifier(hostingContent: content))
|
||||
}
|
||||
|
||||
func customScopeBar(_ content: @escaping () -> some View) -> some View {
|
||||
modifier(CustomScopeBarModifier(hostingContent: content()))
|
||||
modifier(CustomScopeBarModifier(scopeBarContent: content()))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -526,6 +526,19 @@ public class DebridManager: ObservableObject {
|
|||
}
|
||||
}
|
||||
|
||||
public func fetchDebridCloud() async {
|
||||
switch selectedDebridType {
|
||||
case .realDebrid:
|
||||
await fetchRdCloud()
|
||||
case .allDebrid:
|
||||
await fetchAdCloud()
|
||||
case .premiumize:
|
||||
await fetchPmCloud()
|
||||
case .none:
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func fetchRdDownload(magnet: Magnet?, existingLink: String?) async {
|
||||
// If an existing link is passed in args, set it to that. Otherwise, find one from RD cloud.
|
||||
let torrentLink: String?
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import Introspect
|
|||
import SwiftUI
|
||||
|
||||
struct CustomScopeBarModifier<V: View>: ViewModifier {
|
||||
let hostingContent: V
|
||||
let scopeBarContent: V
|
||||
@State private var hostingController: UIHostingController<V>?
|
||||
|
||||
func body(content: Content) -> some View {
|
||||
|
|
@ -26,7 +26,7 @@ struct CustomScopeBarModifier<V: View>: ViewModifier {
|
|||
searchController.searchBar.scopeButtonTitles = [""]
|
||||
(searchController.searchBar.value(forKey: "_scopeBar") as? UIView)?.isHidden = true
|
||||
|
||||
let hostingController = UIHostingController(rootView: hostingContent)
|
||||
let hostingController = UIHostingController(rootView: scopeBarContent)
|
||||
hostingController.view.translatesAutoresizingMaskIntoConstraints = false
|
||||
hostingController.view.backgroundColor = .clear
|
||||
|
||||
|
|
@ -53,7 +53,7 @@ struct CustomScopeBarModifier<V: View>: ViewModifier {
|
|||
}
|
||||
} else {
|
||||
VStack {
|
||||
hostingContent
|
||||
scopeBarContent
|
||||
content
|
||||
Spacer()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -84,13 +84,5 @@ struct AllDebridCloudView: View {
|
|||
}
|
||||
}
|
||||
}
|
||||
.backport.onAppear {
|
||||
viewTask = Task {
|
||||
await debridManager.fetchAdCloud()
|
||||
}
|
||||
}
|
||||
.onDisappear {
|
||||
viewTask?.cancel()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -59,13 +59,5 @@ struct PremiumizeCloudView: View {
|
|||
}
|
||||
}
|
||||
}
|
||||
.backport.onAppear {
|
||||
viewTask = Task {
|
||||
await debridManager.fetchPmCloud()
|
||||
}
|
||||
}
|
||||
.onDisappear {
|
||||
viewTask?.cancel()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -124,13 +124,5 @@ struct RealDebridCloudView: View {
|
|||
}
|
||||
}
|
||||
}
|
||||
.backport.onAppear {
|
||||
viewTask = Task {
|
||||
await debridManager.fetchRdCloud()
|
||||
}
|
||||
}
|
||||
.onDisappear {
|
||||
viewTask?.cancel()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,8 @@ struct DebridCloudView: View {
|
|||
|
||||
@Binding var searchText: String
|
||||
|
||||
@State private var viewTask: Task<Void, Never>?
|
||||
|
||||
var body: some View {
|
||||
List {
|
||||
switch debridManager.selectedDebridType {
|
||||
|
|
@ -26,5 +28,22 @@ struct DebridCloudView: View {
|
|||
}
|
||||
}
|
||||
.listStyle(.plain)
|
||||
.backport.onAppear {
|
||||
viewTask = Task {
|
||||
await debridManager.fetchDebridCloud()
|
||||
}
|
||||
}
|
||||
.onDisappear {
|
||||
viewTask?.cancel()
|
||||
}
|
||||
.onChange(of: debridManager.selectedDebridType) { newType in
|
||||
viewTask?.cancel()
|
||||
|
||||
if newType != nil {
|
||||
viewTask = Task {
|
||||
await debridManager.fetchDebridCloud()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,20 +12,6 @@ struct PluginsView: View {
|
|||
@EnvironmentObject var pluginManager: PluginManager
|
||||
@EnvironmentObject var navModel: NavigationViewModel
|
||||
|
||||
/*
|
||||
@FetchRequest(
|
||||
entity: Source.entity(),
|
||||
sortDescriptors: []
|
||||
) var sources: FetchedResults<Source>
|
||||
*/
|
||||
|
||||
/*
|
||||
@FetchRequest(
|
||||
entity: Action.entity(),
|
||||
sortDescriptors: []
|
||||
) var actions: FetchedResults<Action>
|
||||
*/
|
||||
|
||||
@AppStorage("Behavior.AutocorrectSearch") var autocorrectSearch = true
|
||||
|
||||
@State private var installedSourcesEmpty = false
|
||||
|
|
|
|||
Loading…
Reference in a new issue