mirror of
https://github.com/SideStore/SideStore.git
synced 2026-02-14 17:23:25 +01:00
[AltStore] Update apps from UpdatesViewController
This commit is contained in:
@@ -45,11 +45,22 @@ class DownloadAppOperation: ResultOperation<InstalledApp>
|
||||
DatabaseManager.shared.persistentContainer.performBackgroundTask { (context) in
|
||||
let app = context.object(with: self.app.objectID) as! App
|
||||
|
||||
let installedApp = InstalledApp(app: app,
|
||||
let installedApp: InstalledApp
|
||||
|
||||
if let app = app.installedApp
|
||||
{
|
||||
installedApp = app
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
installedApp = InstalledApp(app: app,
|
||||
bundleIdentifier: app.identifier,
|
||||
expirationDate: Date(),
|
||||
context: context)
|
||||
}
|
||||
|
||||
installedApp.version = app.version
|
||||
self.finish(.success(installedApp))
|
||||
}
|
||||
}
|
||||
|
||||
53
AltStore/Operations/FetchAppsOperation.swift
Normal file
53
AltStore/Operations/FetchAppsOperation.swift
Normal file
@@ -0,0 +1,53 @@
|
||||
//
|
||||
// FetchAppsOperation.swift
|
||||
// AltStore
|
||||
//
|
||||
// Created by Riley Testut on 6/17/19.
|
||||
// Copyright © 2019 Riley Testut. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Roxas
|
||||
|
||||
@objc(FetchAppsOperation)
|
||||
class FetchAppsOperation: ResultOperation<[App]>
|
||||
{
|
||||
private let session = URLSession(configuration: .default)
|
||||
|
||||
private lazy var dateFormatter: DateFormatter = {
|
||||
let dateFormatter = DateFormatter()
|
||||
dateFormatter.dateFormat = "yyyy-MM-dd"
|
||||
return dateFormatter
|
||||
}()
|
||||
|
||||
override func main()
|
||||
{
|
||||
super.main()
|
||||
|
||||
let appsURL = URL(string: "https://www.dropbox.com/s/z5tj1tx8zgeqbms/Apps.json?dl=1")!
|
||||
|
||||
let dataTask = self.session.dataTask(with: appsURL) { (data, response, error) in
|
||||
DatabaseManager.shared.persistentContainer.performBackgroundTask { (context) in
|
||||
do
|
||||
{
|
||||
let (data, _) = try Result((data, response), error).get()
|
||||
|
||||
let decoder = JSONDecoder()
|
||||
decoder.dateDecodingStrategy = .formatted(self.dateFormatter)
|
||||
decoder.managedObjectContext = context
|
||||
|
||||
let apps = try decoder.decode([App].self, from: data)
|
||||
self.finish(.success(apps))
|
||||
}
|
||||
catch
|
||||
{
|
||||
self.finish(.failure(error))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
self.progress.addChild(dataTask.progress, withPendingUnitCount: 1)
|
||||
|
||||
dataTask.resume()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user