From 254058928f77f68b0a7ecd736804a519eeccc787 Mon Sep 17 00:00:00 2001 From: kingbri Date: Thu, 23 Mar 2023 10:56:24 -0400 Subject: [PATCH] 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 --- Ferrite/Extensions/View.swift | 6 +----- Ferrite/ViewModels/DebridManager.swift | 13 +++++++++++++ .../Modifiers/CustomScopeBar.swift | 6 +++--- .../Library/Cloud/AllDebridCloudView.swift | 8 -------- .../Library/Cloud/PremiumizeCloudView.swift | 8 -------- .../Library/Cloud/RealDebridCloudView.swift | 8 -------- .../Library/DebridCloudView.swift | 19 +++++++++++++++++++ Ferrite/Views/PluginsView.swift | 14 -------------- 8 files changed, 36 insertions(+), 46 deletions(-) diff --git a/Ferrite/Extensions/View.swift b/Ferrite/Extensions/View.swift index 088ff70..ac67c54 100644 --- a/Ferrite/Extensions/View.swift +++ b/Ferrite/Extensions/View.swift @@ -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())) } } diff --git a/Ferrite/ViewModels/DebridManager.swift b/Ferrite/ViewModels/DebridManager.swift index f2dcffc..db6a32d 100644 --- a/Ferrite/ViewModels/DebridManager.swift +++ b/Ferrite/ViewModels/DebridManager.swift @@ -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? diff --git a/Ferrite/Views/CommonViews/Modifiers/CustomScopeBar.swift b/Ferrite/Views/CommonViews/Modifiers/CustomScopeBar.swift index 51bf575..f2c4cf6 100644 --- a/Ferrite/Views/CommonViews/Modifiers/CustomScopeBar.swift +++ b/Ferrite/Views/CommonViews/Modifiers/CustomScopeBar.swift @@ -9,7 +9,7 @@ import Introspect import SwiftUI struct CustomScopeBarModifier: ViewModifier { - let hostingContent: V + let scopeBarContent: V @State private var hostingController: UIHostingController? func body(content: Content) -> some View { @@ -26,7 +26,7 @@ struct CustomScopeBarModifier: 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: ViewModifier { } } else { VStack { - hostingContent + scopeBarContent content Spacer() } diff --git a/Ferrite/Views/ComponentViews/Library/Cloud/AllDebridCloudView.swift b/Ferrite/Views/ComponentViews/Library/Cloud/AllDebridCloudView.swift index eec82e8..4bc1119 100644 --- a/Ferrite/Views/ComponentViews/Library/Cloud/AllDebridCloudView.swift +++ b/Ferrite/Views/ComponentViews/Library/Cloud/AllDebridCloudView.swift @@ -84,13 +84,5 @@ struct AllDebridCloudView: View { } } } - .backport.onAppear { - viewTask = Task { - await debridManager.fetchAdCloud() - } - } - .onDisappear { - viewTask?.cancel() - } } } diff --git a/Ferrite/Views/ComponentViews/Library/Cloud/PremiumizeCloudView.swift b/Ferrite/Views/ComponentViews/Library/Cloud/PremiumizeCloudView.swift index f49b128..3b424dd 100644 --- a/Ferrite/Views/ComponentViews/Library/Cloud/PremiumizeCloudView.swift +++ b/Ferrite/Views/ComponentViews/Library/Cloud/PremiumizeCloudView.swift @@ -59,13 +59,5 @@ struct PremiumizeCloudView: View { } } } - .backport.onAppear { - viewTask = Task { - await debridManager.fetchPmCloud() - } - } - .onDisappear { - viewTask?.cancel() - } } } diff --git a/Ferrite/Views/ComponentViews/Library/Cloud/RealDebridCloudView.swift b/Ferrite/Views/ComponentViews/Library/Cloud/RealDebridCloudView.swift index e796da3..7380112 100644 --- a/Ferrite/Views/ComponentViews/Library/Cloud/RealDebridCloudView.swift +++ b/Ferrite/Views/ComponentViews/Library/Cloud/RealDebridCloudView.swift @@ -124,13 +124,5 @@ struct RealDebridCloudView: View { } } } - .backport.onAppear { - viewTask = Task { - await debridManager.fetchRdCloud() - } - } - .onDisappear { - viewTask?.cancel() - } } } diff --git a/Ferrite/Views/ComponentViews/Library/DebridCloudView.swift b/Ferrite/Views/ComponentViews/Library/DebridCloudView.swift index fb435bb..09efc10 100644 --- a/Ferrite/Views/ComponentViews/Library/DebridCloudView.swift +++ b/Ferrite/Views/ComponentViews/Library/DebridCloudView.swift @@ -12,6 +12,8 @@ struct DebridCloudView: View { @Binding var searchText: String + @State private var viewTask: Task? + 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() + } + } + } } } diff --git a/Ferrite/Views/PluginsView.swift b/Ferrite/Views/PluginsView.swift index 0c9315d..a763b45 100644 --- a/Ferrite/Views/PluginsView.swift +++ b/Ferrite/Views/PluginsView.swift @@ -12,20 +12,6 @@ struct PluginsView: View { @EnvironmentObject var pluginManager: PluginManager @EnvironmentObject var navModel: NavigationViewModel - /* - @FetchRequest( - entity: Source.entity(), - sortDescriptors: [] - ) var sources: FetchedResults - */ - - /* - @FetchRequest( - entity: Action.entity(), - sortDescriptors: [] - ) var actions: FetchedResults - */ - @AppStorage("Behavior.AutocorrectSearch") var autocorrectSearch = true @State private var installedSourcesEmpty = false