[AltStoreCore] Adds Source.isRecommended

Also replaces legacy “Trusted Sources” references with “Recommended Sources”
This commit is contained in:
Riley Testut
2023-10-16 18:18:06 -05:00
committed by Magesh K
parent 9ddc27f6ca
commit d53e36633d
5 changed files with 30 additions and 18 deletions

View File

@@ -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))

View File

@@ -178,11 +178,11 @@ final class VerifyAppOperation: ResultOperation<Void>
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(()))
}
}

View File

@@ -1,69 +0,0 @@
//
// KnownSource.swift
// AltStore
//
// Created by Riley Testut on 5/16/23.
// Copyright © 2023 Riley Testut. All rights reserved.
//
import Foundation
struct KnownSource: Decodable
{
var identifier: String
var sourceURL: URL?
var bundleIDs: [String]?
}
private extension KnownSource
{
var dictionaryRepresentation: [String: Any] {
let dictionary: [String: Any?] = [
KnownSource.CodingKeys.identifier.stringValue: identifier,
KnownSource.CodingKeys.sourceURL.stringValue: self.sourceURL?.absoluteString,
KnownSource.CodingKeys.bundleIDs.stringValue: self.bundleIDs
]
return dictionary.compactMapValues { $0 }
}
init?(dictionary: [String: Any])
{
guard let identifier = dictionary[CodingKeys.identifier.stringValue] as? String else { return nil }
self.identifier = identifier
if let sourceURLString = dictionary[CodingKeys.sourceURL.stringValue] as? String
{
self.sourceURL = URL(string: sourceURLString)
}
let bundleIDs = dictionary[CodingKeys.bundleIDs.stringValue] as? [String]
self.bundleIDs = bundleIDs
}
}
extension UserDefaults
{
// Cache trusted sources just in case we need to check whether source is trusted or not.
@nonobjc var trustedSources: [KnownSource]? {
get {
guard let sources = _trustedSources?.compactMap({ KnownSource(dictionary: $0) }) else { return nil }
return sources
}
set {
_trustedSources = newValue?.map { $0.dictionaryRepresentation }
}
}
@NSManaged @objc(trustedSources) private var _trustedSources: [[String: Any]]?
@nonobjc var blockedSources: [KnownSource]? {
get {
guard let sources = _blockedSources?.compactMap({ KnownSource(dictionary: $0) }) else { return nil }
return sources
}
set {
_blockedSources = newValue?.map { $0.dictionaryRepresentation }
}
}
@NSManaged @objc(blockedSources) private var _blockedSources: [[String: Any]]?
}