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