mirror of
https://github.com/SideStore/SideStore.git
synced 2026-02-09 06:43:25 +01:00
Adds AddSourceViewController to add sources by URL or from list of recommended sources
This commit is contained in:
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user