Adds AddSourceViewController to add sources by URL or from list of recommended sources

This commit is contained in:
Riley Testut
2023-10-18 18:56:40 -05:00
committed by Magesh K
parent 2aebaf80e0
commit 98125e93aa
13 changed files with 1096 additions and 23 deletions

View File

@@ -358,7 +358,7 @@ extension AppManager
}
}
func add(@AsyncManaged _ source: Source, message: String? = nil, presentingViewController: UIViewController) async throws
func add(@AsyncManaged _ source: Source, message: String? = NSLocalizedString("Make sure to only add sources that you trust.", comment: ""), presentingViewController: UIViewController) async throws
{
let (sourceName, sourceURL) = await $source.perform { ($0.name, $0.sourceURL) }
@@ -366,9 +366,8 @@ extension AppManager
async let fetchedSource = try await self.fetchSource(sourceURL: sourceURL, managedObjectContext: context) // Fetch source async while showing alert.
let title = String(format: NSLocalizedString("Would you like to add the source “%@”?", comment: ""), sourceName)
let message = message ?? NSLocalizedString("Make sure to only add sources that you trust.", comment: "")
let action = await UIAlertAction(title: NSLocalizedString("Add Source", comment: ""), style: .default)
try await presentingViewController.presentConfirmationAlert(title: title, message: message, primaryAction: action)
try await presentingViewController.presentConfirmationAlert(title: title, message: message ?? "", primaryAction: action)
// Wait for fetch to finish before saving context to make
// sure there isn't already a source with this identifier.
@@ -412,10 +411,11 @@ extension AppManager
extension AppManager
{
@available(*, renamed: "fetchSource(sourceURL:managedObjectContext:)")
@discardableResult
func fetchSource(sourceURL: URL,
managedObjectContext: NSManagedObjectContext = DatabaseManager.shared.persistentContainer.newBackgroundContext(),
dependencies: [Foundation.Operation] = [],
completionHandler: @escaping (Result<Source, Error>) -> Void)
completionHandler: @escaping (Result<Source, Error>) -> Void) -> FetchSourceOperation
{
let fetchSourceOperation = FetchSourceOperation(sourceURL: sourceURL, managedObjectContext: managedObjectContext)
fetchSourceOperation.resultHandler = { (result) in
@@ -435,6 +435,8 @@ extension AppManager
}
self.run([fetchSourceOperation], context: nil)
return fetchSourceOperation
}
@available(*, renamed: "fetchSources")