Shows detailed source “About” page when adding 3rd-party sources

Allows users to preview sources before adding them to their AltStore.
This commit is contained in:
Riley Testut
2023-04-04 15:41:44 -05:00
parent 93b18974c1
commit 5c419aa333
12 changed files with 1718 additions and 31 deletions

View File

@@ -178,6 +178,15 @@ private extension SourcesViewController
let dataSource = RSTArrayCollectionViewDataSource<Source>(items: [])
return dataSource
}
@IBSegueAction
func makeSourceDetailViewController(_ coder: NSCoder, sender: Any?) -> UIViewController?
{
guard let source = sender as? Source else { return nil }
let sourceDetailViewController = SourceDetailViewController(source: source, coder: coder)
return sourceDetailViewController
}
}
private extension SourcesViewController
@@ -208,7 +217,7 @@ private extension SourcesViewController
self.present(alertController, animated: true, completion: nil)
}
func addSource(url: URL, isTrusted: Bool = false, completionHandler: ((Result<Void, Error>) -> Void)? = nil)
func addSource(url: URL, completionHandler: ((Result<Void, Error>) -> Void)? = nil)
{
guard self.view.window != nil else { return }
@@ -241,6 +250,7 @@ private extension SourcesViewController
}
}
//TODO: Remove this now that trusted sources aren't necessary.
var dependencies: [Foundation.Operation] = []
if let fetchTrustedSourcesOperation = self.fetchTrustedSourcesOperation
{
@@ -252,34 +262,13 @@ private extension SourcesViewController
AppManager.shared.fetchSource(sourceURL: url, dependencies: dependencies) { (result) in
do
{
let source = try result.get()
let sourceName = source.name
let managedObjectContext = source.managedObjectContext
// Hide warning when adding a featured trusted source.
let message = isTrusted ? nil : NSLocalizedString("Make sure to only add sources that you trust.", comment: "")
@Managed var source = try result.get()
DispatchQueue.main.async {
let alertController = UIAlertController(title: String(format: NSLocalizedString("Would you like to add the source “%@”?", comment: ""), sourceName),
message: message, preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: UIAlertAction.cancel.title, style: UIAlertAction.cancel.style) { _ in
finish(.failure(OperationError.cancelled))
})
alertController.addAction(UIAlertAction(title: NSLocalizedString("Add Source", comment: ""), style: UIAlertAction.ok.style) { _ in
managedObjectContext?.perform {
do
{
try managedObjectContext?.save()
finish(.success(()))
}
catch
{
finish(.failure(error))
}
}
})
self.present(alertController, animated: true, completion: nil)
self.showSourceDetails(for: source)
}
finish(.success(()))
}
catch
{
@@ -396,7 +385,7 @@ private extension SourcesViewController
sender.progress = completedProgress
let source = self.dataSource.item(at: indexPath)
self.addSource(url: source.sourceURL, isTrusted: true) { _ in
self.addSource(url: source.sourceURL) { _ in
//FIXME: Handle cell reuse.
sender.progress = nil
}
@@ -431,6 +420,11 @@ private extension SourcesViewController
self.present(alertController, animated: true, completion: nil)
}
func showSourceDetails(for source: Source)
{
self.performSegue(withIdentifier: "showSourceDetails", sender: source)
}
}
extension SourcesViewController
@@ -440,9 +434,7 @@ extension SourcesViewController
self.collectionView.deselectItem(at: indexPath, animated: true)
let source = self.dataSource.item(at: indexPath)
guard let error = source.error else { return }
self.present(error)
self.showSourceDetails(for: source)
}
}
@@ -593,7 +585,7 @@ extension SourcesViewController
}
let addAction = UIAction(title: String(format: NSLocalizedString("Add “%@”", comment: ""), source.name), image: UIImage(systemName: "plus")) { (action) in
self.addSource(url: source.sourceURL, isTrusted: true)
self.addSource(url: source.sourceURL)
}
var actions: [UIAction] = []