diff --git a/AltStore.xcodeproj/project.pbxproj b/AltStore.xcodeproj/project.pbxproj index bc1f7738..ecd34ec9 100644 --- a/AltStore.xcodeproj/project.pbxproj +++ b/AltStore.xcodeproj/project.pbxproj @@ -389,7 +389,6 @@ D586D39B28EF58B0000E101F /* AltTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D586D39A28EF58B0000E101F /* AltTests.swift */; }; D58916FE28C7C55C00E39C8B /* LoggedError.swift in Sources */ = {isa = PBXBuildFile; fileRef = D58916FD28C7C55C00E39C8B /* LoggedError.swift */; }; D5893F802A1419E800E767CD /* NSManagedObjectContext+Conveniences.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5893F7E2A14183200E767CD /* NSManagedObjectContext+Conveniences.swift */; }; - D5893F822A141E4900E767CD /* KnownSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5893F812A141E4900E767CD /* KnownSource.swift */; }; D58D5F2E26DFE68E00E55E38 /* LaunchAtLogin in Frameworks */ = {isa = PBXBuildFile; productRef = D58D5F2D26DFE68E00E55E38 /* LaunchAtLogin */; }; D59162AB29BA60A9005CBF47 /* SourceHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D59162AA29BA60A9005CBF47 /* SourceHeaderView.swift */; }; D59162AD29BA616A005CBF47 /* SourceHeaderView.xib in Resources */ = {isa = PBXBuildFile; fileRef = D59162AC29BA616A005CBF47 /* SourceHeaderView.xib */; }; @@ -434,6 +433,7 @@ D5F5AF7D28ECEA990067C736 /* ErrorDetailsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5F5AF7C28ECEA990067C736 /* ErrorDetailsViewController.swift */; }; D5F99A1828D11DB500476A16 /* AltStore10ToAltStore11.xcmappingmodel in Sources */ = {isa = PBXBuildFile; fileRef = D5F99A1728D11DB500476A16 /* AltStore10ToAltStore11.xcmappingmodel */; }; D5F99A1A28D12B1400476A16 /* StoreApp10ToStoreApp11Policy.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5F99A1928D12B1400476A16 /* StoreApp10ToStoreApp11Policy.swift */; }; + D5FB28EE2ADDF89800A1C337 /* KnownSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5893F812A141E4900E767CD /* KnownSource.swift */; }; D5FB7A0E2AA25A4E00EF863D /* Previews.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = D5FB7A0D2AA25A4E00EF863D /* Previews.xcassets */; }; D5FB7A212AA284ED00EF863D /* EnableJIT.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5FB7A1A2AA284ED00EF863D /* EnableJIT.swift */; }; D5FB7A242AA284ED00EF863D /* Logger+AltJIT.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5FB7A1D2AA284ED00EF863D /* Logger+AltJIT.swift */; }; @@ -1382,7 +1382,6 @@ BF41B807233433C100C593A3 /* LoadingState.swift */, D5DAE0932804B0B80034D8D4 /* ScreenshotProcessor.swift */, D5A2193329B14F94002229FC /* DeprecatedAPIs.swift */, - D5893F812A141E4900E767CD /* KnownSource.swift */, ); path = Types; sourceTree = ""; @@ -1616,6 +1615,7 @@ children = ( BFB39B5B252BC10E00D1BE50 /* Managed.swift */, D5F48B4929CD0B67002B52A4 /* AsyncManaged.swift */, + D5893F812A141E4900E767CD /* KnownSource.swift */, BF66EE8E2501AEBC007EE018 /* ALTAppPermissions.h */, BF66EE912501AEBC007EE018 /* ALTAppPermissions.m */, BF66EE922501AEBC007EE018 /* ALTPatreonBenefitType.h */, @@ -3022,6 +3022,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + D5FB28EE2ADDF89800A1C337 /* KnownSource.swift in Sources */, BF66EED32501AECA007EE018 /* AltStore2ToAltStore3.xcmappingmodel in Sources */, BF66EEA52501AEC5007EE018 /* Benefit.swift in Sources */, BF66EED22501AECA007EE018 /* AltStore4ToAltStore5.xcmappingmodel in Sources */, @@ -3138,7 +3139,6 @@ D540E93828EE1BDE000F1B0F /* ErrorDetailsViewController.swift in Sources */, D513F6162A12CE4E0061EAA1 /* SourceError.swift in Sources */, BF56D2AC23DF8E170006506D /* FetchAppIDsOperation.swift in Sources */, - D5893F822A141E4900E767CD /* KnownSource.swift in Sources */, BFC1F38D22AEE3A4003AC21A /* DownloadAppOperation.swift in Sources */, BFE6073A231ADF82002B0E8E /* SettingsViewController.swift in Sources */, D57F2C9126E0070200B9FA39 /* EnableJITOperation.swift in Sources */, diff --git a/AltStore/Operations/UpdateKnownSourcesOperation.swift b/AltStore/Operations/UpdateKnownSourcesOperation.swift index e553b5f1..24de3061 100644 --- a/AltStore/Operations/UpdateKnownSourcesOperation.swift +++ b/AltStore/Operations/UpdateKnownSourcesOperation.swift @@ -8,6 +8,8 @@ import Foundation +import AltStoreCore + private extension URL { #if STAGING @@ -66,7 +68,7 @@ class UpdateKnownSourcesOperation: ResultOperation<([KnownSource], [KnownSource] let sources = (trusted: response.trusted ?? [], blocked: response.blocked ?? []) // Cache sources - UserDefaults.shared.trustedSources = sources.trusted + UserDefaults.shared.recommendedSources = sources.trusted UserDefaults.shared.blockedSources = sources.blocked self.finish(.success(sources)) diff --git a/AltStore/Operations/VerifyAppOperation.swift b/AltStore/Operations/VerifyAppOperation.swift index 7f857179..0094a8a5 100644 --- a/AltStore/Operations/VerifyAppOperation.swift +++ b/AltStore/Operations/VerifyAppOperation.swift @@ -178,11 +178,11 @@ final class VerifyAppOperation: ResultOperation throw error #endif - if let trustedSources = UserDefaults.shared.trustedSources, let sourceID = await self.context.$appVersion.sourceID + if let recommendedSources = UserDefaults.shared.recommendedSources, let sourceID = await self.context.$appVersion.sourceID { - let isTrusted = trustedSources.contains { $0.identifier == sourceID } - guard !isTrusted else { - // Don't enforce permission checking for Trusted Sources while 2.0 is in beta. + let isRecommended = recommendedSources.contains { $0.identifier == sourceID } + guard !isRecommended else { + // Don't enforce permission checking for Recommended Sources while 2.0 is in beta. return self.finish(.success(())) } } diff --git a/AltStoreCore/Model/Source.swift b/AltStoreCore/Model/Source.swift index 288cb5ca..e22e46e8 100644 --- a/AltStoreCore/Model/Source.swift +++ b/AltStoreCore/Model/Source.swift @@ -376,6 +376,16 @@ public extension Source return isAdded } } + + var isRecommended: Bool { + guard let recommendedSources = UserDefaults.shared.recommendedSources else { return false } + + // TODO: Support alternate URLs + let isRecommended = recommendedSources.contains { source in + return source.identifier == self.identifier || source.sourceURL?.absoluteString.lowercased() == self.sourceURL.absoluteString + } + return isRecommended + } } internal extension Source diff --git a/AltStore/Types/KnownSource.swift b/AltStoreCore/Types/KnownSource.swift similarity index 72% rename from AltStore/Types/KnownSource.swift rename to AltStoreCore/Types/KnownSource.swift index dd961843..6f365ac4 100644 --- a/AltStore/Types/KnownSource.swift +++ b/AltStoreCore/Types/KnownSource.swift @@ -8,11 +8,11 @@ import Foundation -struct KnownSource: Decodable +public struct KnownSource: Decodable { - var identifier: String - var sourceURL: URL? - var bundleIDs: [String]? + public var identifier: String + public var sourceURL: URL? + public var bundleIDs: [String]? } private extension KnownSource @@ -42,19 +42,19 @@ private extension KnownSource } } -extension UserDefaults +public extension UserDefaults { - // Cache trusted sources just in case we need to check whether source is trusted or not. - @nonobjc var trustedSources: [KnownSource]? { + // Cache recommended sources just in case we need to check whether source is recommended or not. + @nonobjc var recommendedSources: [KnownSource]? { get { - guard let sources = _trustedSources?.compactMap({ KnownSource(dictionary: $0) }) else { return nil } + guard let sources = _recommendedSources?.compactMap({ KnownSource(dictionary: $0) }) else { return nil } return sources } set { - _trustedSources = newValue?.map { $0.dictionaryRepresentation } + _recommendedSources = newValue?.map { $0.dictionaryRepresentation } } } - @NSManaged @objc(trustedSources) private var _trustedSources: [[String: Any]]? + @NSManaged @objc(recommendedSources) private var _recommendedSources: [[String: Any]]? @nonobjc var blockedSources: [KnownSource]? { get {