[AltStore] Update AltStore itself from UpdatesViewController

This commit is contained in:
Riley Testut
2019-06-17 16:31:10 -07:00
parent d65cef8817
commit 205fb3d7e9
7 changed files with 151 additions and 36 deletions

View File

@@ -33,9 +33,15 @@ public extension DatabaseManager
self.persistentContainer.loadPersistentStores { (description, error) in
guard error == nil else { return completionHandler(error!) }
self.isStarted = true
completionHandler(error)
self.prepareDatabase() { (result) in
switch result
{
case .failure(let error): completionHandler(error)
case .success:
self.isStarted = true
completionHandler(nil)
}
}
}
}
@@ -94,3 +100,45 @@ extension DatabaseManager
return activeTeam
}
}
private extension DatabaseManager
{
func prepareDatabase(completionHandler: @escaping (Result<Void, Error>) -> Void)
{
self.persistentContainer.performBackgroundTask { (context) in
let version = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String ?? "1.0"
let altStoreApp: App
if let app = App.first(satisfying: NSPredicate(format: "%K == %@", #keyPath(App.identifier), App.altstoreAppID), in: context)
{
altStoreApp = app
}
else
{
altStoreApp = App.makeAltStoreApp(in: context)
altStoreApp.version = version
}
if let installedApp = altStoreApp.installedApp
{
installedApp.version = version
}
else
{
let installedApp = InstalledApp(app: altStoreApp, bundleIdentifier: altStoreApp.identifier, expirationDate: Date(), context: context)
installedApp.version = version
}
do
{
try context.save()
completionHandler(.success(()))
}
catch
{
completionHandler(.failure(error))
}
}
}
}