Limits adding sources to allowed identifiers in non-BETA builds

This commit is contained in:
Riley Testut
2020-10-05 14:48:48 -07:00
parent 00e8b7c80e
commit 1f8e16dce8
4 changed files with 71 additions and 23 deletions

View File

@@ -12,6 +12,24 @@ import CoreData
import AltStoreCore
import Roxas
struct SourceError: LocalizedError
{
enum Code
{
case unsupported
}
var code: Code
@Managed var source: Source
var errorDescription: String? {
switch self.code
{
case .unsupported: return String(format: NSLocalizedString("The source “%@” is not supported by this version of AltStore.", comment: ""), self.$source.name)
}
}
}
class SourcesViewController: UICollectionViewController
{
var deepLinkSourceURL: URL? {
@@ -28,6 +46,11 @@ class SourcesViewController: UICollectionViewController
super.viewDidLoad()
self.collectionView.dataSource = self.dataSource
#if !BETA
// Hide "Add Source" button for public version while in beta.
self.navigationItem.leftBarButtonItem = nil
#endif
}
override func viewWillAppear(_ animated: Bool)
@@ -143,6 +166,10 @@ private extension SourcesViewController
let sourceName = source.name
let managedObjectContext = source.managedObjectContext
#if !BETA
guard Source.allowedIdentifiers.contains(source.identifier) else { throw SourceError(code: .unsupported, source: source) }
#endif
DispatchQueue.main.async {
let alertController = UIAlertController(title: String(format: NSLocalizedString("Would you like to add the source “%@”?", comment: ""), sourceName),
message: NSLocalizedString("Sources control what apps appear in AltStore. Make sure to only add sources that you trust.", comment: ""), preferredStyle: .alert)