[AltStore] Tracks background refresh attempts for debugging

This commit is contained in:
Riley Testut
2019-07-31 13:35:12 -07:00
parent 7385d109cd
commit caf424df91
7 changed files with 418 additions and 136 deletions

View File

@@ -56,6 +56,17 @@
</uniquenessConstraint>
</uniquenessConstraints>
</entity>
<entity name="RefreshAttempt" representedClassName="RefreshAttempt" syncable="YES">
<attribute name="date" attributeType="Date" usesScalarValueType="NO" syncable="YES"/>
<attribute name="errorDescription" optional="YES" attributeType="String" syncable="YES"/>
<attribute name="identifier" attributeType="String" syncable="YES"/>
<attribute name="isSuccess" attributeType="Boolean" defaultValueString="YES" usesScalarValueType="YES" syncable="YES"/>
<uniquenessConstraints>
<uniquenessConstraint>
<constraint value="identifier"/>
</uniquenessConstraint>
</uniquenessConstraints>
</entity>
<entity name="Source" representedClassName="Source" syncable="YES">
<attribute name="identifier" attributeType="String" syncable="YES"/>
<attribute name="name" attributeType="String" syncable="YES"/>
@@ -84,7 +95,8 @@
<element name="App" positionX="-63" positionY="-18" width="128" height="300"/>
<element name="AppPermission" positionX="-45" positionY="90" width="128" height="90"/>
<element name="InstalledApp" positionX="-63" positionY="0" width="128" height="150"/>
<element name="Team" positionX="-45" positionY="81" width="128" height="120"/>
<element name="Source" positionX="-45" positionY="99" width="128" height="105"/>
<element name="Team" positionX="-45" positionY="81" width="128" height="120"/>
<element name="RefreshAttempt" positionX="-45" positionY="117" width="128" height="105"/>
</elements>
</model>

View File

@@ -0,0 +1,51 @@
//
// RefreshAttempt.swift
// AltStore
//
// Created by Riley Testut on 7/31/19.
// Copyright © 2019 Riley Testut. All rights reserved.
//
import CoreData
@objc(RefreshAttempt)
class RefreshAttempt: NSManagedObject, Fetchable
{
@NSManaged var identifier: String
@NSManaged var date: Date
@NSManaged var isSuccess: Bool
@NSManaged var errorDescription: String?
private override init(entity: NSEntityDescription, insertInto context: NSManagedObjectContext?)
{
super.init(entity: entity, insertInto: context)
}
init<T>(identifier: String, result: Result<T, Error>, context: NSManagedObjectContext)
{
super.init(entity: RefreshAttempt.entity(), insertInto: context)
self.identifier = identifier
self.date = Date()
switch result
{
case .success:
self.isSuccess = true
self.errorDescription = nil
case .failure(let error):
self.isSuccess = false
self.errorDescription = error.localizedDescription
}
}
}
extension RefreshAttempt
{
@nonobjc class func fetchRequest() -> NSFetchRequest<RefreshAttempt>
{
return NSFetchRequest<RefreshAttempt>(entityName: "RefreshAttempt")
}
}