mirror of
https://github.com/Ferrite-iOS/Ferrite.git
synced 2026-01-11 20:10:27 +00:00
Debrid: Allow for UI updates
Mark as an ObservableObject so the UI can see parameters that are being updated in the class. Signed-off-by: kingbri <bdashore3@proton.me>
This commit is contained in:
parent
cf0c5a30f7
commit
b80f8900b7
9 changed files with 27 additions and 32 deletions
|
|
@ -12,14 +12,14 @@ public class Premiumize: OAuthDebridSource {
|
|||
public let abbreviation = "PM"
|
||||
public let website = "https://premiumize.me"
|
||||
|
||||
public var authProcessing: Bool = false
|
||||
@Published public var authProcessing: Bool = false
|
||||
public var isLoggedIn: Bool {
|
||||
getToken() != nil
|
||||
}
|
||||
|
||||
public var IAValues: [DebridIA] = []
|
||||
public var cloudDownloads: [DebridCloudDownload] = []
|
||||
public var cloudTorrents: [DebridCloudTorrent] = []
|
||||
@Published public var IAValues: [DebridIA] = []
|
||||
@Published public var cloudDownloads: [DebridCloudDownload] = []
|
||||
@Published public var cloudTorrents: [DebridCloudTorrent] = []
|
||||
|
||||
let baseAuthUrl = "https://www.premiumize.me/authorize"
|
||||
let baseApiUrl = "https://www.premiumize.me/api"
|
||||
|
|
|
|||
|
|
@ -13,16 +13,16 @@ public class RealDebrid: PollingDebridSource {
|
|||
public let website = "https://real-debrid.com"
|
||||
public var authTask: Task<Void, Error>?
|
||||
|
||||
public var authProcessing: Bool = false
|
||||
@Published public var authProcessing: Bool = false
|
||||
|
||||
// Directly checked because the request fetch uses async
|
||||
public var isLoggedIn: Bool {
|
||||
FerriteKeychain.shared.get("RealDebrid.AccessToken") != nil
|
||||
}
|
||||
|
||||
public var IAValues: [DebridIA] = []
|
||||
public var cloudDownloads: [DebridCloudDownload] = []
|
||||
public var cloudTorrents: [DebridCloudTorrent] = []
|
||||
@Published public var IAValues: [DebridIA] = []
|
||||
@Published public var cloudDownloads: [DebridCloudDownload] = []
|
||||
@Published public var cloudTorrents: [DebridCloudTorrent] = []
|
||||
|
||||
let baseAuthUrl = "https://api.real-debrid.com/oauth/v2"
|
||||
let baseApiUrl = "https://api.real-debrid.com/rest/1.0"
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
import Foundation
|
||||
|
||||
public protocol DebridSource {
|
||||
public protocol DebridSource: ObservableObject {
|
||||
// ID of the service
|
||||
var id: String { get }
|
||||
var abbreviation: String { get }
|
||||
|
|
|
|||
|
|
@ -12,16 +12,20 @@ import SwiftUI
|
|||
public class DebridManager: ObservableObject {
|
||||
// Linked classes
|
||||
var logManager: LoggingManager?
|
||||
let realDebrid: RealDebrid = .init()
|
||||
let allDebrid: AllDebrid = .init()
|
||||
let premiumize: Premiumize = .init()
|
||||
@Published var realDebrid: RealDebrid = .init()
|
||||
@Published var allDebrid: AllDebrid = .init()
|
||||
@Published var premiumize: Premiumize = .init()
|
||||
|
||||
lazy var debridSources: [DebridSource] = [realDebrid, allDebrid, premiumize]
|
||||
lazy var debridSources: [any DebridSource] = [realDebrid, allDebrid, premiumize]
|
||||
|
||||
// UI Variables
|
||||
@Published var showWebView: Bool = false
|
||||
@Published var showAuthSession: Bool = false
|
||||
|
||||
var hasEnabledDebrids: Bool {
|
||||
debridSources.contains { $0.isLoggedIn }
|
||||
}
|
||||
|
||||
// Service agnostic variables
|
||||
@Published var enabledDebrids: Set<DebridType> = [] {
|
||||
didSet {
|
||||
|
|
@ -60,9 +64,6 @@ public class DebridManager: ObservableObject {
|
|||
// RealDebrid auth variables
|
||||
var realDebridAuthProcessing: Bool = false
|
||||
|
||||
// RealDebrid fetch variables
|
||||
@Published var realDebridIAValues: [DebridIA] = []
|
||||
|
||||
@Published var showDeleteAlert: Bool = false
|
||||
|
||||
var selectedRealDebridItem: DebridIA?
|
||||
|
|
@ -78,9 +79,6 @@ public class DebridManager: ObservableObject {
|
|||
// AllDebrid auth variables
|
||||
var allDebridAuthProcessing: Bool = false
|
||||
|
||||
// AllDebrid fetch variables
|
||||
@Published var allDebridIAValues: [DebridIA] = []
|
||||
|
||||
var selectedAllDebridItem: DebridIA?
|
||||
var selectedAllDebridFile: DebridIAFile?
|
||||
|
||||
|
|
@ -92,9 +90,6 @@ public class DebridManager: ObservableObject {
|
|||
// Premiumize auth variables
|
||||
var premiumizeAuthProcessing: Bool = false
|
||||
|
||||
// Premiumize fetch variables
|
||||
@Published var premiumizeIAValues: [DebridIA] = []
|
||||
|
||||
var selectedPremiumizeItem: DebridIA?
|
||||
var selectedPremiumizeFile: DebridIAFile?
|
||||
|
||||
|
|
@ -171,9 +166,9 @@ public class DebridManager: ObservableObject {
|
|||
|
||||
// Cleans all cached IA values in the event of a full IA refresh
|
||||
public func clearIAValues() {
|
||||
realDebridIAValues = []
|
||||
allDebridIAValues = []
|
||||
premiumizeIAValues = []
|
||||
for debridSource in debridSources {
|
||||
debridSource.IAValues = []
|
||||
}
|
||||
}
|
||||
|
||||
// Clears all selected files and items
|
||||
|
|
@ -216,7 +211,7 @@ public class DebridManager: ObservableObject {
|
|||
}
|
||||
} else if let IAIndex = premiumize.IAValues.firstIndex(where: { $0.magnet.hash == magnet.hash }), enabledDebrids.contains(.premiumize) {
|
||||
if now.timeIntervalSince1970 > premiumize.IAValues[IAIndex].expiryTimeStamp {
|
||||
premiumizeIAValues.remove(at: IAIndex)
|
||||
premiumize.IAValues.remove(at: IAIndex)
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
|
|
|
|||
|
|
@ -80,7 +80,7 @@ class ScrapingViewModel: ObservableObject {
|
|||
|
||||
cleanedSearchText = searchText.lowercased()
|
||||
|
||||
if await !debridManager.enabledDebrids.isEmpty {
|
||||
if await !debridManager.hasEnabledDebrids {
|
||||
await debridManager.clearIAValues()
|
||||
}
|
||||
|
||||
|
|
@ -114,7 +114,7 @@ class ScrapingViewModel: ObservableObject {
|
|||
var failedSourceNames: [String] = []
|
||||
for await (requestResult, sourceName) in group {
|
||||
if let requestResult {
|
||||
if await !debridManager.enabledDebrids.isEmpty {
|
||||
if await !debridManager.hasEnabledDebrids {
|
||||
await debridManager.populateDebridIA(requestResult.magnets)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ struct BookmarksView: View {
|
|||
.frame(height: 15)
|
||||
}
|
||||
.task {
|
||||
if debridManager.enabledDebrids.count > 0 {
|
||||
if debridManager.hasEnabledDebrids {
|
||||
let magnets = bookmarks.compactMap {
|
||||
if let magnetHash = $0.magnetHash {
|
||||
return Magnet(hash: magnetHash, link: $0.magnetLink)
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ struct LibraryPickerView: View {
|
|||
Text("Bookmarks").tag(NavigationViewModel.LibraryPickerSegment.bookmarks)
|
||||
Text("History").tag(NavigationViewModel.LibraryPickerSegment.history)
|
||||
|
||||
if !debridManager.enabledDebrids.isEmpty {
|
||||
if debridManager.hasEnabledDebrids {
|
||||
Text("Cloud").tag(NavigationViewModel.LibraryPickerSegment.debridCloud)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ struct SearchFilterHeaderView: View {
|
|||
|
||||
// MARK: - Cache status picker
|
||||
|
||||
if !debridManager.enabledDebrids.isEmpty {
|
||||
if debridManager.hasEnabledDebrids {
|
||||
IAFilterView()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -128,7 +128,7 @@ struct SettingsView: View {
|
|||
}
|
||||
|
||||
Section(header: InlineHeader("Default actions")) {
|
||||
if debridManager.enabledDebrids.count > 0 {
|
||||
if debridManager.hasEnabledDebrids {
|
||||
NavigationLink {
|
||||
DefaultActionPickerView(
|
||||
actionRequirement: .debrid,
|
||||
|
|
|
|||
Loading…
Reference in a new issue