mirror of
https://github.com/SideStore/SideStore.git
synced 2026-02-09 06:43:25 +01:00
Revises appPermissions format in source JSON
Before, appPermissions was one array containing all permissions of different types. Now, we split entitlement and privacy permissions into separate “entitlements” and “privacy” child arrays.
This commit is contained in:
@@ -102,9 +102,7 @@ public class AppPermission: NSManagedObject, Decodable, Fetchable
|
||||
|
||||
private enum CodingKeys: String, CodingKey
|
||||
{
|
||||
case entitlement
|
||||
case privacyType = "privacy"
|
||||
|
||||
case name
|
||||
case usageDescription
|
||||
}
|
||||
|
||||
@@ -118,27 +116,11 @@ public class AppPermission: NSManagedObject, Decodable, Fetchable
|
||||
{
|
||||
let container = try decoder.container(keyedBy: CodingKeys.self)
|
||||
|
||||
self._permission = try container.decode(String.self, forKey: .name)
|
||||
self.usageDescription = try container.decodeIfPresent(String.self, forKey: .usageDescription)
|
||||
|
||||
if let entitlement = try container.decodeIfPresent(String.self, forKey: .entitlement)
|
||||
{
|
||||
self._permission = entitlement
|
||||
self.type = .entitlement
|
||||
}
|
||||
else if let privacyType = try container.decodeIfPresent(String.self, forKey: .privacyType)
|
||||
{
|
||||
self._permission = privacyType
|
||||
self.type = .privacy
|
||||
}
|
||||
else
|
||||
{
|
||||
self._permission = ""
|
||||
self.type = .unknown
|
||||
|
||||
// We don't want to save any unknown permissions, but can't throw error
|
||||
// without making the entire decoding fail, so just delete self instead.
|
||||
context.delete(self)
|
||||
}
|
||||
// Will be updated from StoreApp.
|
||||
self.type = .unknown
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
@@ -23,6 +23,12 @@ public extension StoreApp
|
||||
#endif
|
||||
|
||||
static let dolphinAppID = "me.oatmealdome.dolphinios-njb"
|
||||
|
||||
private struct AppPermissions: Decodable
|
||||
{
|
||||
var entitlements: [AppPermission]?
|
||||
var privacy: [AppPermission]?
|
||||
}
|
||||
}
|
||||
|
||||
@objc
|
||||
@@ -286,12 +292,23 @@ public class StoreApp: NSManagedObject, Decodable, Fetchable
|
||||
|
||||
self.isBeta = try container.decodeIfPresent(Bool.self, forKey: .isBeta) ?? false
|
||||
|
||||
let permissions = try container.decodeIfPresent([AppPermission].self, forKey: .permissions) ?? []
|
||||
for permission in permissions
|
||||
if let appPermissions = try container.decodeIfPresent(AppPermissions.self, forKey: .permissions)
|
||||
{
|
||||
permission.appBundleID = self.bundleIdentifier
|
||||
appPermissions.entitlements?.forEach { $0.type = .entitlement }
|
||||
appPermissions.privacy?.forEach { $0.type = .privacy }
|
||||
|
||||
let allPermissions = (appPermissions.entitlements ?? []) + (appPermissions.privacy ?? [])
|
||||
for permission in allPermissions
|
||||
{
|
||||
permission.appBundleID = self.bundleIdentifier
|
||||
}
|
||||
|
||||
self._permissions = NSSet(array: allPermissions)
|
||||
}
|
||||
else
|
||||
{
|
||||
self._permissions = NSSet()
|
||||
}
|
||||
self._permissions = NSSet(array: permissions)
|
||||
|
||||
if let versions = try container.decodeIfPresent([AppVersion].self, forKey: .versions)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user