mirror of
https://github.com/SideStore/SideStore.git
synced 2026-02-15 01:33:25 +01:00
[AltStore] Update AltStore itself from UpdatesViewController
This commit is contained in:
@@ -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))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user