mirror of
https://github.com/SideStore/SideStore.git
synced 2026-02-18 19:23:43 +01:00
Improves App ID counting + management
Fetches App ID count directly from Apple, and adds AppIDsViewController to view all App IDs for the logged-in account.
This commit is contained in:
@@ -97,7 +97,8 @@ extension AppManager
|
||||
#endif
|
||||
}
|
||||
|
||||
func authenticate(presentingViewController: UIViewController?, completionHandler: @escaping (Result<(ALTSigner, ALTAppleAPISession), Error>) -> Void)
|
||||
@discardableResult
|
||||
func authenticate(presentingViewController: UIViewController?, completionHandler: @escaping (Result<(ALTSigner, ALTAppleAPISession), Error>) -> Void) -> OperationGroup
|
||||
{
|
||||
let group = OperationGroup()
|
||||
|
||||
@@ -113,10 +114,20 @@ extension AppManager
|
||||
|
||||
let authenticationOperation = AuthenticationOperation(group: group, presentingViewController: presentingViewController)
|
||||
authenticationOperation.resultHandler = { (result) in
|
||||
switch result
|
||||
{
|
||||
case .failure(let error): group.error = error
|
||||
case .success(let signer, let session):
|
||||
group.signer = signer
|
||||
group.session = session
|
||||
}
|
||||
|
||||
completionHandler(result)
|
||||
}
|
||||
authenticationOperation.addDependency(findServerOperation)
|
||||
self.operationQueue.addOperation(authenticationOperation)
|
||||
|
||||
return group
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,6 +155,23 @@ extension AppManager
|
||||
self.operationQueue.addOperation(fetchSourceOperation)
|
||||
}
|
||||
}
|
||||
|
||||
func fetchAppIDs(completionHandler: @escaping (Result<([AppID], NSManagedObjectContext), Error>) -> Void)
|
||||
{
|
||||
var group: OperationGroup!
|
||||
group = self.authenticate(presentingViewController: nil) { (result) in
|
||||
switch result
|
||||
{
|
||||
case .failure(let error):
|
||||
completionHandler(.failure(error))
|
||||
|
||||
case .success:
|
||||
let fetchAppIDsOperation = FetchAppIDsOperation(group: group)
|
||||
fetchAppIDsOperation.resultHandler = completionHandler
|
||||
self.operationQueue.addOperation(fetchAppIDsOperation)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension AppManager
|
||||
@@ -382,6 +410,22 @@ private extension AppManager
|
||||
refreshAnisetteDataOperation.addDependency(downloadOperation)
|
||||
}
|
||||
|
||||
/* Cache App IDs */
|
||||
let fetchAppIDsOperation = FetchAppIDsOperation(group: group)
|
||||
fetchAppIDsOperation.resultHandler = { (result) in
|
||||
do
|
||||
{
|
||||
let (_, context) = try result.get()
|
||||
try context.save()
|
||||
}
|
||||
catch
|
||||
{
|
||||
print("Failed to fetch App IDs.", error)
|
||||
}
|
||||
}
|
||||
operations.forEach { fetchAppIDsOperation.addDependency($0) }
|
||||
operations.append(fetchAppIDsOperation)
|
||||
|
||||
group.addOperations(operations)
|
||||
|
||||
return group
|
||||
|
||||
Reference in New Issue
Block a user