From 68a87f55bf386d7c827365a0d672118f156be103 Mon Sep 17 00:00:00 2001 From: Riley Testut Date: Tue, 30 May 2023 12:57:45 -0500 Subject: [PATCH] Revises `appPermissions` format in source JSON MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- AltStoreCore/Model/AppPermission.swift | 26 ++++---------------------- AltStoreCore/Model/StoreApp.swift | 25 +++++++++++++++++++++---- 2 files changed, 25 insertions(+), 26 deletions(-) diff --git a/AltStoreCore/Model/AppPermission.swift b/AltStoreCore/Model/AppPermission.swift index 35ade8bb..1a699f33 100644 --- a/AltStoreCore/Model/AppPermission.swift +++ b/AltStoreCore/Model/AppPermission.swift @@ -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 { diff --git a/AltStoreCore/Model/StoreApp.swift b/AltStoreCore/Model/StoreApp.swift index 217a1dc6..c469b484 100644 --- a/AltStoreCore/Model/StoreApp.swift +++ b/AltStoreCore/Model/StoreApp.swift @@ -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) {