Adds ability to change sideloaded app icons

This commit is contained in:
Riley Testut
2020-10-01 14:09:45 -07:00
parent 12f33c355a
commit 546db3fa23
7 changed files with 187 additions and 26 deletions

View File

@@ -35,6 +35,7 @@
<attribute name="bundleIdentifier" attributeType="String"/>
<attribute name="certificateSerialNumber" optional="YES" attributeType="String"/>
<attribute name="expirationDate" attributeType="Date" usesScalarValueType="NO"/>
<attribute name="hasAlternateIcon" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES"/>
<attribute name="installedDate" attributeType="Date" usesScalarValueType="NO"/>
<attribute name="isActive" attributeType="Boolean" defaultValueString="YES" usesScalarValueType="YES"/>
<attribute name="isRefreshing" transient="YES" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES"/>
@@ -164,7 +165,7 @@
<element name="Account" positionX="-36" positionY="90" width="128" height="135"/>
<element name="AppID" positionX="-27" positionY="153" width="128" height="133"/>
<element name="AppPermission" positionX="-45" positionY="90" width="128" height="90"/>
<element name="InstalledApp" positionX="-63" positionY="0" width="128" height="253"/>
<element name="InstalledApp" positionX="-63" positionY="0" width="128" height="268"/>
<element name="InstalledExtension" positionX="-45" positionY="135" width="128" height="163"/>
<element name="NewsItem" positionX="-45" positionY="126" width="128" height="238"/>
<element name="PatreonAccount" positionX="-45" positionY="117" width="128" height="105"/>

View File

@@ -41,6 +41,7 @@ public class InstalledApp: NSManagedObject, InstalledAppProtocol
@NSManaged public var isActive: Bool
@NSManaged public var needsResign: Bool
@NSManaged public var hasAlternateIcon: Bool
@NSManaged public var certificateSerialNumber: String?
@@ -104,6 +105,32 @@ public class InstalledApp: NSManagedObject, InstalledAppProtocol
self.refreshedDate = provisioningProfile.creationDate
self.expirationDate = provisioningProfile.expirationDate
}
public func loadIcon(completion: @escaping (Result<UIImage?, Error>) -> Void)
{
let hasAlternateIcon = self.hasAlternateIcon
let alternateIconURL = self.alternateIconURL
let fileURL = self.fileURL
DispatchQueue.global().async {
do
{
if hasAlternateIcon,
case let data = try Data(contentsOf: alternateIconURL),
let icon = UIImage(data: data)
{
return completion(.success(icon))
}
let application = ALTApplication(fileURL: fileURL)
completion(.success(application?.icon))
}
catch
{
completion(.failure(error))
}
}
}
}
public extension InstalledApp
@@ -269,6 +296,12 @@ public extension InstalledApp
return installedBackupAppUTI
}
class func alternateIconURL(for app: AppProtocol) -> URL
{
let installedBackupAppUTI = self.directoryURL(for: app).appendingPathComponent("AltIcon.png")
return installedBackupAppUTI
}
var directoryURL: URL {
return InstalledApp.directoryURL(for: self)
}
@@ -288,4 +321,8 @@ public extension InstalledApp
var installedBackupAppUTI: String {
return InstalledApp.installedBackupAppUTI(forBundleIdentifier: self.resignedBundleIdentifier)
}
var alternateIconURL: URL {
return InstalledApp.alternateIconURL(for: self)
}
}