2019-05-09 15:29:54 -07:00
|
|
|
//
|
2019-07-31 14:07:00 -07:00
|
|
|
// StoreApp.swift
|
2019-05-09 15:29:54 -07:00
|
|
|
// AltStore
|
|
|
|
|
//
|
2019-05-20 21:24:53 +02:00
|
|
|
// Created by Riley Testut on 5/20/19.
|
2019-05-09 15:29:54 -07:00
|
|
|
// Copyright © 2019 Riley Testut. All rights reserved.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
import Foundation
|
2019-05-20 21:24:53 +02:00
|
|
|
import CoreData
|
2019-05-09 15:29:54 -07:00
|
|
|
|
2019-05-30 17:10:50 -07:00
|
|
|
import Roxas
|
2019-07-28 15:08:13 -07:00
|
|
|
import AltSign
|
2019-05-30 17:10:50 -07:00
|
|
|
|
2025-02-09 17:28:24 +05:30
|
|
|
import SemanticVersion
|
|
|
|
|
|
|
|
|
|
public enum ReleaseTracks: String, CodingKey, CaseIterable
|
|
|
|
|
{
|
|
|
|
|
case unknown
|
|
|
|
|
case local
|
|
|
|
|
|
|
|
|
|
case alpha
|
2025-02-16 20:28:57 +05:30
|
|
|
case nightly = "nightly"
|
2025-02-09 17:28:24 +05:30
|
|
|
case stable
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static var betaTracks: [ReleaseTracks] {
|
|
|
|
|
ReleaseTracks.allCases.filter(isBetaTrack)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static var nonBetaTracks: [ReleaseTracks] {
|
|
|
|
|
ReleaseTracks.allCases.filter { !isBetaTrack($0) }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static func isBetaTrack(_ key: ReleaseTracks) -> Bool {
|
2025-02-16 20:28:57 +05:30
|
|
|
key == .alpha || key == .nightly
|
2025-02-09 17:28:24 +05:30
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2020-09-03 16:39:08 -07:00
|
|
|
public extension StoreApp
|
2019-06-17 16:31:10 -07:00
|
|
|
{
|
2020-04-01 11:51:00 -07:00
|
|
|
#if ALPHA
|
2022-12-30 16:51:36 -05:00
|
|
|
static let altstoreAppID = Bundle.Info.appbundleIdentifier
|
2020-04-01 11:51:00 -07:00
|
|
|
#elseif BETA
|
2022-12-30 16:51:36 -05:00
|
|
|
static let altstoreAppID = Bundle.Info.appbundleIdentifier
|
2019-09-12 13:04:15 -07:00
|
|
|
#else
|
2022-12-30 16:51:36 -05:00
|
|
|
static let altstoreAppID = Bundle.Info.appbundleIdentifier
|
2019-09-12 13:04:15 -07:00
|
|
|
#endif
|
2025-02-09 17:28:24 +05:30
|
|
|
|
2020-05-08 11:45:23 -07:00
|
|
|
static let dolphinAppID = "me.oatmealdome.dolphinios-njb"
|
2019-06-17 16:31:10 -07:00
|
|
|
}
|
|
|
|
|
|
2021-09-15 20:55:41 -04:00
|
|
|
@objc
|
2023-01-04 09:31:28 -05:00
|
|
|
public enum Platform: UInt, Codable {
|
2021-09-15 20:55:41 -04:00
|
|
|
case ios
|
|
|
|
|
case tvos
|
|
|
|
|
case macos
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@objc
|
|
|
|
|
public final class PlatformURL: NSManagedObject, Decodable {
|
|
|
|
|
/* Properties */
|
|
|
|
|
@NSManaged public private(set) var platform: Platform
|
|
|
|
|
@NSManaged public private(set) var downloadURL: URL
|
2025-02-09 17:28:24 +05:30
|
|
|
|
|
|
|
|
|
2021-09-15 20:55:41 -04:00
|
|
|
private enum CodingKeys: String, CodingKey
|
|
|
|
|
{
|
|
|
|
|
case platform
|
|
|
|
|
case downloadURL
|
|
|
|
|
}
|
2025-02-09 17:28:24 +05:30
|
|
|
|
|
|
|
|
|
2021-09-15 20:55:41 -04:00
|
|
|
public init(from decoder: Decoder) throws
|
|
|
|
|
{
|
|
|
|
|
guard let context = decoder.managedObjectContext else { preconditionFailure("Decoder must have non-nil NSManagedObjectContext.") }
|
2025-02-09 17:28:24 +05:30
|
|
|
|
2021-09-15 20:55:41 -04:00
|
|
|
// Must initialize with context in order for child context saves to work correctly.
|
|
|
|
|
super.init(entity: PlatformURL.entity(), insertInto: context)
|
2025-02-09 17:28:24 +05:30
|
|
|
|
2021-09-15 20:55:41 -04:00
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
let container = try decoder.container(keyedBy: CodingKeys.self)
|
|
|
|
|
self.platform = try container.decode(Platform.self, forKey: .platform)
|
|
|
|
|
self.downloadURL = try container.decode(URL.self, forKey: .downloadURL)
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
if let context = self.managedObjectContext
|
|
|
|
|
{
|
|
|
|
|
context.delete(self)
|
|
|
|
|
}
|
2025-02-09 17:28:24 +05:30
|
|
|
|
2021-09-15 20:55:41 -04:00
|
|
|
throw error
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
extension PlatformURL: Comparable {
|
|
|
|
|
public static func < (lhs: PlatformURL, rhs: PlatformURL) -> Bool {
|
|
|
|
|
return lhs.platform.rawValue < rhs.platform.rawValue
|
|
|
|
|
}
|
2025-02-09 17:28:24 +05:30
|
|
|
|
2021-09-15 20:55:41 -04:00
|
|
|
public static func > (lhs: PlatformURL, rhs: PlatformURL) -> Bool {
|
|
|
|
|
return lhs.platform.rawValue > rhs.platform.rawValue
|
|
|
|
|
}
|
2025-02-09 17:28:24 +05:30
|
|
|
|
2021-09-15 20:55:41 -04:00
|
|
|
public static func <= (lhs: PlatformURL, rhs: PlatformURL) -> Bool {
|
|
|
|
|
return lhs.platform.rawValue <= rhs.platform.rawValue
|
|
|
|
|
}
|
2025-02-09 17:28:24 +05:30
|
|
|
|
2021-09-15 20:55:41 -04:00
|
|
|
public static func >= (lhs: PlatformURL, rhs: PlatformURL) -> Bool {
|
|
|
|
|
return lhs.platform.rawValue >= rhs.platform.rawValue
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public typealias PlatformURLs = [PlatformURL]
|
|
|
|
|
|
2024-02-16 14:21:06 -06:00
|
|
|
private struct PatreonParameters: Decodable
|
2023-11-15 13:41:05 -06:00
|
|
|
{
|
2024-02-16 14:21:06 -06:00
|
|
|
struct Pledge: Decodable
|
2023-11-15 13:41:05 -06:00
|
|
|
{
|
2024-02-16 14:21:06 -06:00
|
|
|
var amount: Decimal
|
|
|
|
|
var isCustom: Bool
|
2025-02-09 17:28:24 +05:30
|
|
|
|
2024-02-16 14:21:06 -06:00
|
|
|
init(from decoder: Decoder) throws
|
|
|
|
|
{
|
|
|
|
|
let container = try decoder.singleValueContainer()
|
2025-02-09 17:28:24 +05:30
|
|
|
|
2024-02-16 14:21:06 -06:00
|
|
|
if let stringValue = try? container.decode(String.self), stringValue == "custom"
|
|
|
|
|
{
|
|
|
|
|
self.amount = 0 // Use 0 as amount internally to simplify logic.
|
|
|
|
|
self.isCustom = true
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Unless the value is "custom", throw error if value is not Decimal.
|
|
|
|
|
self.amount = try container.decode(Decimal.self)
|
|
|
|
|
self.isCustom = false
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-11-15 13:41:05 -06:00
|
|
|
}
|
2025-02-09 17:28:24 +05:30
|
|
|
|
2024-02-16 14:21:06 -06:00
|
|
|
var pledge: Pledge?
|
|
|
|
|
var currency: String?
|
|
|
|
|
var tiers: Set<String>?
|
|
|
|
|
var benefit: String?
|
|
|
|
|
var hidden: Bool?
|
2023-11-15 13:41:05 -06:00
|
|
|
}
|
|
|
|
|
|
2025-02-08 04:45:22 +05:30
|
|
|
|
2025-02-09 17:28:24 +05:30
|
|
|
extension StoreApp {
|
|
|
|
|
|
|
|
|
|
//MARK: - relationships
|
|
|
|
|
@NSManaged @objc(releaseTracks) private(set) var _releaseTracks: NSOrderedSet?
|
|
|
|
|
|
|
|
|
|
private var releaseTracks: [ReleaseTrack]?{
|
|
|
|
|
return _releaseTracks?.array as? [ReleaseTrack]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private func releaseTrackFor(track: String) -> ReleaseTrack? {
|
|
|
|
|
return releaseTracks?.first(where: { $0.track == track })
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private var stableTrack: ReleaseTrack? {
|
|
|
|
|
releaseTrackFor(track: ReleaseTracks.stable.stringValue)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private var betaReleases: [AppVersion]? {
|
|
|
|
|
// If beta track is selected, use it instead
|
|
|
|
|
if UserDefaults.standard.isBetaUpdatesEnabled,
|
|
|
|
|
let betaTrack = UserDefaults.standard.betaUdpatesTrack {
|
|
|
|
|
|
|
|
|
|
// Filter and flatten beta and stable releases
|
|
|
|
|
let betaReleases = releaseTrackFor(track: betaTrack)?.releases?.compactMap { $0 }
|
|
|
|
|
|
|
|
|
|
// Ensure both beta and stable releases are found and supported
|
|
|
|
|
if let latestBeta = betaReleases?.first(where: { $0.isSupported }),
|
|
|
|
|
let latestStable = stableTrack?.releases?.first(where: { $0.isSupported }),
|
|
|
|
|
let stableSemVer = SemanticVersion(latestStable.version),
|
|
|
|
|
let betaSemVer = SemanticVersion(latestBeta.version),
|
|
|
|
|
betaSemVer >= stableSemVer
|
|
|
|
|
{
|
|
|
|
|
return betaReleases
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private func getReleases(default releases: ReleaseTrack?) -> [AppVersion]?
|
|
|
|
|
{
|
|
|
|
|
return betaReleases ?? releases?.releases?.compactMap { $0 }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2019-07-31 14:07:00 -07:00
|
|
|
@objc(StoreApp)
|
2025-02-08 04:45:22 +05:30
|
|
|
public class StoreApp: BaseEntity, Decodable
|
2019-05-09 15:29:54 -07:00
|
|
|
{
|
2019-05-20 21:24:53 +02:00
|
|
|
/* Properties */
|
2020-09-03 16:39:08 -07:00
|
|
|
@NSManaged public private(set) var name: String
|
|
|
|
|
@NSManaged public private(set) var bundleIdentifier: String
|
|
|
|
|
@NSManaged public private(set) var subtitle: String?
|
2025-02-09 17:28:24 +05:30
|
|
|
|
2020-09-03 16:39:08 -07:00
|
|
|
@NSManaged public private(set) var developerName: String
|
2025-02-08 13:11:27 +05:30
|
|
|
@NSManaged public private(set) var localizedDescription: String
|
|
|
|
|
@NSManaged @objc(size) internal var _size: Int32
|
2025-02-09 17:28:24 +05:30
|
|
|
|
2023-12-07 18:04:48 -06:00
|
|
|
@nonobjc public var category: StoreCategory? {
|
|
|
|
|
guard let _category else { return nil }
|
2025-02-09 17:28:24 +05:30
|
|
|
|
2023-12-07 18:04:48 -06:00
|
|
|
let category = StoreCategory(rawValue: _category)
|
|
|
|
|
return category
|
|
|
|
|
}
|
|
|
|
|
@NSManaged @objc(category) public private(set) var _category: String?
|
2025-02-09 17:28:24 +05:30
|
|
|
|
2020-09-03 16:39:08 -07:00
|
|
|
@NSManaged public private(set) var iconURL: URL
|
|
|
|
|
@NSManaged public private(set) var screenshotURLs: [URL]
|
2025-02-09 17:28:24 +05:30
|
|
|
|
2025-02-08 04:45:22 +05:30
|
|
|
@NSManaged public private(set) var downloadURL: URL?
|
2021-09-15 20:55:41 -04:00
|
|
|
@NSManaged public private(set) var platformURLs: PlatformURLs?
|
|
|
|
|
|
2020-09-03 16:39:08 -07:00
|
|
|
@NSManaged public private(set) var tintColor: UIColor?
|
2025-02-08 13:11:27 +05:30
|
|
|
|
2024-02-15 15:34:28 -06:00
|
|
|
// Required for Marketplace apps.
|
|
|
|
|
@NSManaged public private(set) var marketplaceID: String?
|
|
|
|
|
|
2023-11-15 13:41:05 -06:00
|
|
|
@NSManaged public var isPledged: Bool
|
|
|
|
|
@NSManaged public private(set) var isPledgeRequired: Bool
|
|
|
|
|
@NSManaged public private(set) var isHiddenWithoutPledge: Bool
|
|
|
|
|
@NSManaged public private(set) var pledgeCurrency: String?
|
2024-02-16 14:21:06 -06:00
|
|
|
@NSManaged public private(set) var prefersCustomPledge: Bool
|
2025-02-09 17:28:24 +05:30
|
|
|
|
2023-11-15 13:41:05 -06:00
|
|
|
@nonobjc public var pledgeAmount: Decimal? { _pledgeAmount as? Decimal }
|
|
|
|
|
@NSManaged @objc(pledgeAmount) private var _pledgeAmount: NSDecimalNumber?
|
2025-02-09 17:28:24 +05:30
|
|
|
|
2023-05-18 15:50:53 -05:00
|
|
|
@NSManaged public var sortIndex: Int32
|
2023-12-08 14:32:57 -06:00
|
|
|
@NSManaged public var featuredSortID: String?
|
2025-02-09 17:28:24 +05:30
|
|
|
|
2022-09-12 17:05:55 -07:00
|
|
|
@objc public internal(set) var sourceIdentifier: String? {
|
|
|
|
|
get {
|
|
|
|
|
self.willAccessValue(forKey: #keyPath(sourceIdentifier))
|
|
|
|
|
defer { self.didAccessValue(forKey: #keyPath(sourceIdentifier)) }
|
2025-02-09 17:28:24 +05:30
|
|
|
|
2022-09-12 17:05:55 -07:00
|
|
|
let sourceIdentifier = self.primitiveSourceIdentifier
|
|
|
|
|
return sourceIdentifier
|
|
|
|
|
}
|
|
|
|
|
set {
|
|
|
|
|
self.willChangeValue(forKey: #keyPath(sourceIdentifier))
|
|
|
|
|
self.primitiveSourceIdentifier = newValue
|
|
|
|
|
self.didChangeValue(forKey: #keyPath(sourceIdentifier))
|
2025-02-09 17:28:24 +05:30
|
|
|
|
2022-09-12 17:05:55 -07:00
|
|
|
for version in self.versions
|
|
|
|
|
{
|
|
|
|
|
version.sourceID = newValue
|
|
|
|
|
}
|
2025-02-09 17:28:24 +05:30
|
|
|
|
2023-05-30 15:28:26 -05:00
|
|
|
for permission in self.permissions
|
|
|
|
|
{
|
|
|
|
|
permission.sourceID = self.sourceIdentifier ?? ""
|
|
|
|
|
}
|
2025-02-09 17:28:24 +05:30
|
|
|
|
2025-02-08 13:11:27 +05:30
|
|
|
for screenshot in self.allScreenshots
|
2023-10-11 15:05:27 -05:00
|
|
|
{
|
|
|
|
|
screenshot.sourceID = self.sourceIdentifier ?? ""
|
|
|
|
|
}
|
2022-09-12 17:05:55 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@NSManaged private var primitiveSourceIdentifier: String?
|
2025-02-09 17:28:24 +05:30
|
|
|
|
2023-05-18 15:50:53 -05:00
|
|
|
// Legacy (kept for backwards compatibility)
|
2025-02-08 04:45:22 +05:30
|
|
|
@NSManaged public private(set) var version: String?
|
|
|
|
|
@NSManaged public private(set) var versionDate: Date?
|
|
|
|
|
@NSManaged public private(set) var versionDescription: String?
|
2025-02-09 17:28:24 +05:30
|
|
|
|
2019-05-20 21:26:01 +02:00
|
|
|
/* Relationships */
|
2020-09-03 16:39:08 -07:00
|
|
|
@NSManaged public var installedApp: InstalledApp?
|
|
|
|
|
@NSManaged public var newsItems: Set<NewsItem>
|
2025-02-09 17:28:24 +05:30
|
|
|
|
2020-09-03 16:39:08 -07:00
|
|
|
@NSManaged @objc(source) public var _source: Source?
|
2023-04-04 13:46:04 -05:00
|
|
|
@NSManaged public internal(set) var featuringSource: Source?
|
2025-02-09 17:28:24 +05:30
|
|
|
|
2024-08-06 10:43:52 +09:00
|
|
|
@NSManaged @objc(latestVersion) public private(set) var latestSupportedVersion: AppVersion?
|
2022-09-12 15:42:33 -07:00
|
|
|
@NSManaged @objc(versions) public private(set) var _versions: NSOrderedSet
|
2025-02-09 17:28:24 +05:30
|
|
|
|
2022-09-08 16:14:28 -05:00
|
|
|
@NSManaged public private(set) var loggedErrors: NSSet /* Set<LoggedError> */ // Use NSSet to avoid eagerly fetching values.
|
2025-02-09 17:28:24 +05:30
|
|
|
|
2023-11-20 14:06:04 -06:00
|
|
|
/* Non-Core Data Properties */
|
2025-02-09 17:28:24 +05:30
|
|
|
|
2023-11-20 14:06:04 -06:00
|
|
|
// Used to set isPledged after fetching source.
|
|
|
|
|
public var _tierIDs: Set<String>?
|
|
|
|
|
public var _rewardID: String?
|
2025-02-08 13:11:27 +05:30
|
|
|
|
2020-09-03 16:39:08 -07:00
|
|
|
@nonobjc public var source: Source? {
|
2020-03-24 13:27:44 -07:00
|
|
|
set {
|
|
|
|
|
self._source = newValue
|
|
|
|
|
self.sourceIdentifier = newValue?.identifier
|
|
|
|
|
}
|
|
|
|
|
get {
|
|
|
|
|
return self._source
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-02-08 13:11:27 +05:30
|
|
|
|
2023-05-12 18:26:24 -05:00
|
|
|
@nonobjc public var permissions: Set<AppPermission> {
|
|
|
|
|
return self._permissions as! Set<AppPermission>
|
2019-07-24 12:23:54 -07:00
|
|
|
}
|
2023-05-12 18:26:24 -05:00
|
|
|
@NSManaged @objc(permissions) internal private(set) var _permissions: NSSet // Use NSSet to avoid eagerly fetching values.
|
2025-02-09 17:28:24 +05:30
|
|
|
|
2022-09-12 15:42:33 -07:00
|
|
|
@nonobjc public var versions: [AppVersion] {
|
|
|
|
|
return self._versions.array as! [AppVersion]
|
|
|
|
|
}
|
2025-02-09 17:28:24 +05:30
|
|
|
|
2025-02-08 13:11:27 +05:30
|
|
|
@nonobjc public var allScreenshots: [AppScreenshot] {
|
2023-10-11 15:05:27 -05:00
|
|
|
return self._screenshots.array as! [AppScreenshot]
|
|
|
|
|
}
|
|
|
|
|
@NSManaged @objc(screenshots) private(set) var _screenshots: NSOrderedSet
|
2025-02-08 13:11:27 +05:30
|
|
|
|
2019-05-20 21:24:53 +02:00
|
|
|
private override init(entity: NSEntityDescription, insertInto context: NSManagedObjectContext?)
|
|
|
|
|
{
|
|
|
|
|
super.init(entity: entity, insertInto: context)
|
|
|
|
|
}
|
2025-02-09 17:28:24 +05:30
|
|
|
|
2019-05-20 21:24:53 +02:00
|
|
|
private enum CodingKeys: String, CodingKey
|
|
|
|
|
{
|
|
|
|
|
case name
|
2019-07-28 15:08:13 -07:00
|
|
|
case bundleIdentifier
|
2024-02-15 15:34:28 -06:00
|
|
|
case marketplaceID
|
2019-05-20 21:24:53 +02:00
|
|
|
case developerName
|
|
|
|
|
case localizedDescription
|
2019-08-20 19:06:03 -05:00
|
|
|
case iconURL
|
2021-09-15 20:55:41 -04:00
|
|
|
case platformURLs
|
2023-10-11 15:05:27 -05:00
|
|
|
case screenshots
|
2019-07-16 14:25:09 -07:00
|
|
|
case tintColor
|
|
|
|
|
case subtitle
|
2023-05-12 18:26:24 -05:00
|
|
|
case permissions = "appPermissions"
|
2019-07-29 16:02:15 -07:00
|
|
|
case size
|
2025-02-09 17:28:24 +05:30
|
|
|
case isBeta = "beta" // backward compatibility for altstore source format
|
2022-09-12 17:05:55 -07:00
|
|
|
case versions
|
2023-11-15 13:41:05 -06:00
|
|
|
case patreon
|
2023-12-07 18:04:48 -06:00
|
|
|
case category
|
2025-02-09 17:28:24 +05:30
|
|
|
|
2023-10-11 15:05:27 -05:00
|
|
|
// Legacy
|
|
|
|
|
case version
|
|
|
|
|
case versionDescription
|
|
|
|
|
case versionDate
|
|
|
|
|
case downloadURL
|
|
|
|
|
case screenshotURLs
|
2025-02-08 13:11:27 +05:30
|
|
|
|
2025-02-09 17:28:24 +05:30
|
|
|
// v2 source format
|
|
|
|
|
case releaseTracks = "releaseChannels"
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-03 16:39:08 -07:00
|
|
|
public required init(from decoder: Decoder) throws
|
2019-05-20 21:24:53 +02:00
|
|
|
{
|
|
|
|
|
guard let context = decoder.managedObjectContext else { preconditionFailure("Decoder must have non-nil NSManagedObjectContext.") }
|
2025-02-08 13:11:27 +05:30
|
|
|
|
2020-08-27 16:23:50 -07:00
|
|
|
// Must initialize with context in order for child context saves to work correctly.
|
|
|
|
|
super.init(entity: StoreApp.entity(), insertInto: context)
|
2025-02-08 13:11:27 +05:30
|
|
|
|
2020-08-27 16:23:50 -07:00
|
|
|
do
|
2019-07-16 14:25:09 -07:00
|
|
|
{
|
2020-08-27 16:23:50 -07:00
|
|
|
let container = try decoder.container(keyedBy: CodingKeys.self)
|
|
|
|
|
self.name = try container.decode(String.self, forKey: .name)
|
|
|
|
|
self.bundleIdentifier = try container.decode(String.self, forKey: .bundleIdentifier)
|
|
|
|
|
self.developerName = try container.decode(String.self, forKey: .developerName)
|
2025-02-08 13:11:27 +05:30
|
|
|
self.localizedDescription = try container.decode(String.self, forKey: .localizedDescription)
|
2023-12-07 18:04:48 -06:00
|
|
|
self.iconURL = try container.decode(URL.self, forKey: .iconURL)
|
2025-02-09 17:28:24 +05:30
|
|
|
|
2020-08-27 16:23:50 -07:00
|
|
|
self.subtitle = try container.decodeIfPresent(String.self, forKey: .subtitle)
|
2025-02-09 17:28:24 +05:30
|
|
|
|
2025-02-08 13:11:27 +05:30
|
|
|
// Required for Marketplace apps, but we'll verify later.
|
|
|
|
|
self.marketplaceID = try container.decodeIfPresent(String.self, forKey: .marketplaceID)
|
|
|
|
|
|
2020-08-27 16:23:50 -07:00
|
|
|
if let tintColorHex = try container.decodeIfPresent(String.self, forKey: .tintColor)
|
|
|
|
|
{
|
|
|
|
|
guard let tintColor = UIColor(hexString: tintColorHex) else {
|
|
|
|
|
throw DecodingError.dataCorruptedError(forKey: .tintColor, in: container, debugDescription: "Hex code is invalid.")
|
|
|
|
|
}
|
2025-02-09 17:28:24 +05:30
|
|
|
|
2020-08-27 16:23:50 -07:00
|
|
|
self.tintColor = tintColor
|
2019-07-16 14:25:09 -07:00
|
|
|
}
|
2025-02-09 17:28:24 +05:30
|
|
|
|
2023-12-07 18:04:48 -06:00
|
|
|
if let rawCategory = try container.decodeIfPresent(String.self, forKey: .category)
|
|
|
|
|
{
|
|
|
|
|
self._category = rawCategory.lowercased() // Store raw (lowercased) category value.
|
|
|
|
|
}
|
2025-02-09 17:28:24 +05:30
|
|
|
|
2023-10-13 13:40:08 -05:00
|
|
|
let appScreenshots: [AppScreenshot]
|
2025-02-09 17:28:24 +05:30
|
|
|
|
2023-10-13 13:40:08 -05:00
|
|
|
if let screenshots = try container.decodeIfPresent(AppScreenshots.self, forKey: .screenshots)
|
2023-10-11 15:05:27 -05:00
|
|
|
{
|
2023-10-13 13:40:08 -05:00
|
|
|
appScreenshots = screenshots.screenshots
|
2023-10-11 15:05:27 -05:00
|
|
|
}
|
|
|
|
|
else if let screenshotURLs = try container.decodeIfPresent([URL].self, forKey: .screenshotURLs)
|
|
|
|
|
{
|
2025-02-08 04:45:22 +05:30
|
|
|
// Assume 9:16 iPhone 8 screen dimensions for legacy screenshotURLs.
|
|
|
|
|
let legacyAspectRatio = CGSize(width: 750, height: 1334)
|
2025-02-09 17:28:24 +05:30
|
|
|
|
2023-10-13 13:40:08 -05:00
|
|
|
appScreenshots = screenshotURLs.map { imageURL in
|
2025-02-08 04:45:22 +05:30
|
|
|
let screenshot = AppScreenshot(imageURL: imageURL, size: legacyAspectRatio, deviceType: .iphone, context: context)
|
2023-10-11 15:05:27 -05:00
|
|
|
return screenshot
|
|
|
|
|
}
|
2025-02-08 04:45:22 +05:30
|
|
|
|
|
|
|
|
// // Update to iPhone 13 screen size
|
|
|
|
|
// let modernAspectRatio = CGSize(width: 1170, height: 2532)
|
2025-02-08 13:11:27 +05:30
|
|
|
|
2025-02-08 04:45:22 +05:30
|
|
|
// appScreenshots = screenshotURLs.map { imageURL in
|
|
|
|
|
// let screenshot = AppScreenshot(imageURL: imageURL, size: modernAspectRatio, deviceType: .iphone, context: context)
|
|
|
|
|
// return screenshot
|
|
|
|
|
// }
|
2023-10-11 15:05:27 -05:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2023-10-13 13:40:08 -05:00
|
|
|
appScreenshots = []
|
|
|
|
|
}
|
2025-02-09 17:28:24 +05:30
|
|
|
|
2023-10-13 13:40:08 -05:00
|
|
|
for screenshot in appScreenshots
|
|
|
|
|
{
|
|
|
|
|
screenshot.appBundleID = self.bundleIdentifier
|
2023-10-11 15:05:27 -05:00
|
|
|
}
|
2025-02-09 17:28:24 +05:30
|
|
|
|
2023-10-13 13:40:08 -05:00
|
|
|
self.setScreenshots(appScreenshots)
|
2025-02-09 17:28:24 +05:30
|
|
|
|
2023-05-30 12:57:45 -05:00
|
|
|
if let appPermissions = try container.decodeIfPresent(AppPermissions.self, forKey: .permissions)
|
|
|
|
|
{
|
2023-10-10 14:47:00 -05:00
|
|
|
let allPermissions = appPermissions.entitlements + appPermissions.privacy
|
2023-05-30 12:57:45 -05:00
|
|
|
for permission in allPermissions
|
|
|
|
|
{
|
|
|
|
|
permission.appBundleID = self.bundleIdentifier
|
|
|
|
|
}
|
2025-02-09 17:28:24 +05:30
|
|
|
|
2023-05-30 12:57:45 -05:00
|
|
|
self._permissions = NSSet(array: allPermissions)
|
|
|
|
|
}
|
|
|
|
|
else
|
2023-05-12 18:26:24 -05:00
|
|
|
{
|
2023-05-30 12:57:45 -05:00
|
|
|
self._permissions = NSSet()
|
2023-05-12 18:26:24 -05:00
|
|
|
}
|
2025-02-08 04:45:22 +05:30
|
|
|
|
2025-02-09 17:28:24 +05:30
|
|
|
try self.decodeVersions(from: decoder) // pre-req for downloadURL procesing
|
|
|
|
|
|
2025-02-08 04:45:22 +05:30
|
|
|
// latestSupportedVersion is set by this point if one was available
|
|
|
|
|
let platformURLs = try container.decodeIfPresent(PlatformURLs.self.self, forKey: .platformURLs)
|
|
|
|
|
if let platformURLs = platformURLs {
|
|
|
|
|
self.platformURLs = platformURLs
|
|
|
|
|
// Backwards compatibility, use the fiirst (iOS will be first since sorted that way)
|
|
|
|
|
if let first = platformURLs.sorted().first {
|
|
|
|
|
self.downloadURL = first.downloadURL
|
|
|
|
|
} else {
|
|
|
|
|
throw DecodingError.dataCorruptedError(forKey: .platformURLs, in: container, debugDescription: "platformURLs has no entries")
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
} else if let downloadURL = try container.decodeIfPresent(URL.self, forKey: .downloadURL) {
|
|
|
|
|
self.downloadURL = downloadURL
|
|
|
|
|
} else {
|
|
|
|
|
// capture it first coz field might still be faulted by coredata
|
|
|
|
|
guard let _ = self.downloadURL else
|
|
|
|
|
{
|
|
|
|
|
let error = DecodingError.dataCorruptedError(forKey: .downloadURL, in: container, debugDescription: "E downloadURL:String or downloadURLs:[[Platform:URL]] key required.")
|
|
|
|
|
throw error
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-02-08 13:11:27 +05:30
|
|
|
|
2023-11-15 13:41:05 -06:00
|
|
|
// Must _explicitly_ set to false to ensure it updates cached database value.
|
|
|
|
|
self.isPledged = false
|
2024-02-16 14:21:06 -06:00
|
|
|
self.prefersCustomPledge = false
|
2025-02-09 17:28:24 +05:30
|
|
|
|
2023-11-15 13:41:05 -06:00
|
|
|
if let patreon = try container.decodeIfPresent(PatreonParameters.self, forKey: .patreon)
|
|
|
|
|
{
|
|
|
|
|
self.isPledgeRequired = true
|
|
|
|
|
self.isHiddenWithoutPledge = patreon.hidden ?? false // Default to showing Patreon apps
|
2025-02-09 17:28:24 +05:30
|
|
|
|
2023-11-15 13:41:05 -06:00
|
|
|
if let pledge = patreon.pledge
|
|
|
|
|
{
|
2024-02-16 14:21:06 -06:00
|
|
|
self._pledgeAmount = pledge.amount as NSDecimalNumber
|
2023-11-15 13:41:05 -06:00
|
|
|
self.pledgeCurrency = patreon.currency ?? "USD" // Only set pledge currency if explicitly given pledge.
|
2024-02-16 14:21:06 -06:00
|
|
|
self.prefersCustomPledge = pledge.isCustom
|
2023-11-15 13:41:05 -06:00
|
|
|
}
|
|
|
|
|
else if patreon.pledge == nil && patreon.tiers == nil && patreon.benefit == nil
|
|
|
|
|
{
|
|
|
|
|
// No conditions, so default to pledgeAmount of 0 to simplify logic.
|
|
|
|
|
self._pledgeAmount = 0 as NSDecimalNumber
|
|
|
|
|
}
|
2025-02-09 17:28:24 +05:30
|
|
|
|
2023-11-20 14:06:04 -06:00
|
|
|
self._tierIDs = patreon.tiers
|
|
|
|
|
self._rewardID = patreon.benefit
|
2023-11-15 13:41:05 -06:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
self.isPledgeRequired = false
|
|
|
|
|
self.isHiddenWithoutPledge = false
|
|
|
|
|
self._pledgeAmount = nil
|
|
|
|
|
self.pledgeCurrency = nil
|
2025-02-09 17:28:24 +05:30
|
|
|
|
2023-11-20 14:06:04 -06:00
|
|
|
self._tierIDs = nil
|
|
|
|
|
self._rewardID = nil
|
2023-11-15 13:41:05 -06:00
|
|
|
}
|
2020-08-27 16:23:50 -07:00
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
if let context = self.managedObjectContext
|
|
|
|
|
{
|
|
|
|
|
context.delete(self)
|
|
|
|
|
}
|
2025-02-09 17:28:24 +05:30
|
|
|
|
2020-08-27 16:23:50 -07:00
|
|
|
throw error
|
2019-07-16 14:25:09 -07:00
|
|
|
}
|
2019-05-20 21:24:53 +02:00
|
|
|
}
|
2025-02-09 17:28:24 +05:30
|
|
|
|
|
|
|
|
private func decodeVersions(from decoder: Decoder) throws {
|
|
|
|
|
let container = try decoder.container(keyedBy: CodingKeys.self)
|
|
|
|
|
|
|
|
|
|
if let releaseTracks = try container.decodeIfPresent([ReleaseTrack].self, forKey: .releaseTracks){
|
|
|
|
|
self._releaseTracks = NSOrderedSet(array: releaseTracks)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// get channel info if present, else default to stable
|
|
|
|
|
var channel = ReleaseTracks.stable.stringValue
|
|
|
|
|
|
|
|
|
|
var versions = getReleases(default: stableTrack) ?? []
|
|
|
|
|
if versions.isEmpty {
|
|
|
|
|
if let appVersions = try container.decodeIfPresent([AppVersion].self, forKey: .versions)
|
|
|
|
|
{
|
|
|
|
|
versions = appVersions
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if try container.decodeIfPresent(Bool.self, forKey: .isBeta) ?? false
|
|
|
|
|
{
|
2025-02-16 20:28:57 +05:30
|
|
|
channel = ReleaseTracks.nightly.stringValue
|
2025-02-09 17:28:24 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// create one from the storeApp description and use it as current
|
|
|
|
|
let newRelease = try createNewAppVersion(decoder: decoder)
|
|
|
|
|
.mutateForData(
|
|
|
|
|
channel: channel,
|
|
|
|
|
appBundleID: self.bundleIdentifier
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
versions = [newRelease]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (index, version) in zip(0..., versions)
|
|
|
|
|
{
|
|
|
|
|
version.appBundleID = self.bundleIdentifier
|
|
|
|
|
|
|
|
|
|
// ignore setting, if it was already updated by ReleaseTracks in V2 sources
|
|
|
|
|
if version.channel == .unknown {
|
|
|
|
|
_ = version.mutateForData(channel: channel)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if self.marketplaceID != nil
|
|
|
|
|
{
|
|
|
|
|
struct IndexCodingKey: CodingKey
|
|
|
|
|
{
|
|
|
|
|
var stringValue: String { self.intValue?.description ?? "" }
|
|
|
|
|
var intValue: Int?
|
|
|
|
|
|
|
|
|
|
init?(stringValue: String)
|
|
|
|
|
{
|
|
|
|
|
fatalError()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
init(intValue: Int)
|
|
|
|
|
{
|
|
|
|
|
self.intValue = intValue
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Marketplace apps must provide build version.
|
|
|
|
|
guard version.buildVersion != nil else {
|
|
|
|
|
let codingPath = container.codingPath + [CodingKeys.versions as CodingKey] + [IndexCodingKey(intValue: index) as CodingKey]
|
|
|
|
|
let context = DecodingError.Context(codingPath: codingPath, debugDescription: "Notarized apps must provide a build version.")
|
|
|
|
|
throw DecodingError.keyNotFound(AppVersion.CodingKeys.buildVersion, context)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try self.setVersions(versions)
|
|
|
|
|
}
|
2025-02-08 13:11:27 +05:30
|
|
|
|
2025-02-09 17:28:24 +05:30
|
|
|
func createNewAppVersion(decoder: Decoder) throws -> AppVersion {
|
|
|
|
|
guard let context = decoder.managedObjectContext else { preconditionFailure("Decoder must have non-nil NSManagedObjectContext.") }
|
|
|
|
|
let container = try decoder.container(keyedBy: CodingKeys.self)
|
|
|
|
|
//
|
|
|
|
|
let version = try container.decode(String.self, forKey: .version)
|
|
|
|
|
let versionDate = try container.decode(Date.self, forKey: .versionDate)
|
|
|
|
|
let versionDescription = try container.decodeIfPresent(String.self, forKey: .versionDescription)
|
|
|
|
|
|
|
|
|
|
let downloadURL = try container.decode(URL.self, forKey: .downloadURL)
|
|
|
|
|
let size = try container.decode(Int32.self, forKey: .size)
|
|
|
|
|
|
|
|
|
|
return AppVersion.makeAppVersion(version: version,
|
|
|
|
|
buildVersion: nil,
|
|
|
|
|
date: versionDate,
|
|
|
|
|
localizedDescription: versionDescription,
|
|
|
|
|
downloadURL: downloadURL,
|
|
|
|
|
size: Int64(size),
|
|
|
|
|
appBundleID: self.bundleIdentifier,
|
|
|
|
|
in: context)
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-08 14:32:57 -06:00
|
|
|
public override func awakeFromInsert()
|
|
|
|
|
{
|
|
|
|
|
super.awakeFromInsert()
|
2025-02-09 17:28:24 +05:30
|
|
|
|
2023-12-08 14:32:57 -06:00
|
|
|
self.featuredSortID = UUID().uuidString
|
|
|
|
|
}
|
2019-05-20 21:24:53 +02:00
|
|
|
}
|
|
|
|
|
|
2024-08-06 10:43:52 +09:00
|
|
|
internal extension StoreApp
|
2022-09-12 17:05:55 -07:00
|
|
|
{
|
2025-02-09 17:28:24 +05:30
|
|
|
func setVersions(_ versions: [AppVersion]) throws
|
|
|
|
|
{
|
2022-11-23 19:08:31 -06:00
|
|
|
guard let latestVersion = versions.first else {
|
|
|
|
|
throw MergeError.noVersions(for: self)
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-12 17:05:55 -07:00
|
|
|
self._versions = NSOrderedSet(array: versions)
|
2025-02-08 13:11:27 +05:30
|
|
|
|
2024-08-06 10:43:52 +09:00
|
|
|
let latestSupportedVersion = versions.first(where: { $0.isSupported })
|
|
|
|
|
self.latestSupportedVersion = latestSupportedVersion
|
2025-02-09 17:28:24 +05:30
|
|
|
|
2024-08-06 10:43:52 +09:00
|
|
|
for case let version as AppVersion in self._versions
|
|
|
|
|
{
|
|
|
|
|
if version == latestSupportedVersion
|
|
|
|
|
{
|
|
|
|
|
version.latestSupportedVersionApp = self
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Ensure we replace any previous relationship when merging.
|
|
|
|
|
version.latestSupportedVersionApp = nil
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-02-08 13:11:27 +05:30
|
|
|
|
2022-09-12 17:05:55 -07:00
|
|
|
// Preserve backwards compatibility by assigning legacy property values.
|
2025-02-08 04:45:22 +05:30
|
|
|
self.version = latestVersion.version
|
|
|
|
|
self.versionDate = latestVersion.date
|
|
|
|
|
self.versionDescription = latestVersion.localizedDescription
|
|
|
|
|
self.downloadURL = latestVersion.downloadURL
|
2025-02-08 13:11:27 +05:30
|
|
|
self._size = Int32(latestVersion.size)
|
2022-09-12 17:05:55 -07:00
|
|
|
}
|
2025-02-09 17:28:24 +05:30
|
|
|
|
2023-05-12 18:26:24 -05:00
|
|
|
func setPermissions(_ permissions: Set<AppPermission>)
|
|
|
|
|
{
|
|
|
|
|
for case let permission as AppPermission in self._permissions
|
|
|
|
|
{
|
|
|
|
|
if permissions.contains(permission)
|
|
|
|
|
{
|
|
|
|
|
permission.app = self
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
permission.app = nil
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-02-09 17:28:24 +05:30
|
|
|
|
2023-05-12 18:26:24 -05:00
|
|
|
self._permissions = permissions as NSSet
|
|
|
|
|
}
|
2025-02-09 17:28:24 +05:30
|
|
|
|
2023-10-11 15:05:27 -05:00
|
|
|
func setScreenshots(_ screenshots: [AppScreenshot])
|
|
|
|
|
{
|
|
|
|
|
for case let screenshot as AppScreenshot in self._screenshots
|
|
|
|
|
{
|
|
|
|
|
if screenshots.contains(screenshot)
|
|
|
|
|
{
|
|
|
|
|
screenshot.app = self
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
screenshot.app = nil
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-02-09 17:28:24 +05:30
|
|
|
|
2023-10-11 15:05:27 -05:00
|
|
|
self._screenshots = NSOrderedSet(array: screenshots)
|
2025-02-09 17:28:24 +05:30
|
|
|
|
2023-10-11 15:05:27 -05:00
|
|
|
// Backwards compatibility
|
|
|
|
|
self.screenshotURLs = screenshots.map { $0.imageURL }
|
|
|
|
|
}
|
2022-09-12 17:05:55 -07:00
|
|
|
}
|
|
|
|
|
|
2023-10-13 13:40:08 -05:00
|
|
|
public extension StoreApp
|
|
|
|
|
{
|
|
|
|
|
func screenshots(for deviceType: ALTDeviceType) -> [AppScreenshot]
|
|
|
|
|
{
|
|
|
|
|
//TODO: Support multiple device types
|
2025-02-08 13:11:27 +05:30
|
|
|
let filteredScreenshots = self.allScreenshots.filter { $0.deviceType == deviceType }
|
2023-10-13 13:40:08 -05:00
|
|
|
return filteredScreenshots
|
|
|
|
|
}
|
2025-02-09 17:28:24 +05:30
|
|
|
|
2023-10-13 13:40:08 -05:00
|
|
|
func preferredScreenshots() -> [AppScreenshot]
|
|
|
|
|
{
|
|
|
|
|
let deviceType: ALTDeviceType
|
2025-02-09 17:28:24 +05:30
|
|
|
|
2023-10-13 13:40:08 -05:00
|
|
|
if UIDevice.current.model.contains("iPad")
|
|
|
|
|
{
|
|
|
|
|
deviceType = .ipad
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
deviceType = .iphone
|
|
|
|
|
}
|
2025-02-09 17:28:24 +05:30
|
|
|
|
2023-10-13 13:40:08 -05:00
|
|
|
let preferredScreenshots = self.screenshots(for: deviceType)
|
|
|
|
|
guard !preferredScreenshots.isEmpty else {
|
|
|
|
|
// There are no screenshots for deviceType, so return _all_ screenshots instead.
|
2025-02-08 13:11:27 +05:30
|
|
|
return self.allScreenshots
|
2023-10-13 13:40:08 -05:00
|
|
|
}
|
2025-02-09 17:28:24 +05:30
|
|
|
|
2023-10-13 13:40:08 -05:00
|
|
|
return preferredScreenshots
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-03 16:39:08 -07:00
|
|
|
public extension StoreApp
|
2019-05-20 21:24:53 +02:00
|
|
|
{
|
2024-08-06 10:43:52 +09:00
|
|
|
var latestAvailableVersion: AppVersion? {
|
|
|
|
|
return self._versions.firstObject as? AppVersion
|
|
|
|
|
}
|
2025-02-09 17:28:24 +05:30
|
|
|
|
2023-04-04 17:14:52 -05:00
|
|
|
var globallyUniqueID: String? {
|
|
|
|
|
guard let sourceIdentifier = self.sourceIdentifier else { return nil }
|
2025-02-09 17:28:24 +05:30
|
|
|
|
2023-04-04 17:14:52 -05:00
|
|
|
let globallyUniqueID = self.bundleIdentifier + "|" + sourceIdentifier
|
|
|
|
|
return globallyUniqueID
|
|
|
|
|
}
|
2023-11-29 18:08:42 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public extension StoreApp
|
|
|
|
|
{
|
|
|
|
|
class var visibleAppsPredicate: NSPredicate {
|
|
|
|
|
let predicate = NSPredicate(format: "(%K != %@) AND ((%K == NO) OR (%K == NO) OR (%K == YES))",
|
|
|
|
|
#keyPath(StoreApp.bundleIdentifier), StoreApp.altstoreAppID,
|
|
|
|
|
#keyPath(StoreApp.isPledgeRequired),
|
|
|
|
|
#keyPath(StoreApp.isHiddenWithoutPledge),
|
|
|
|
|
#keyPath(StoreApp.isPledged))
|
|
|
|
|
return predicate
|
|
|
|
|
}
|
2025-02-09 17:28:24 +05:30
|
|
|
|
2023-12-07 18:11:25 -06:00
|
|
|
class var otherCategoryPredicate: NSPredicate {
|
|
|
|
|
let knownCategories = StoreCategory.allCases.lazy.filter { $0 != .other }.map { $0.rawValue }
|
2025-02-09 17:28:24 +05:30
|
|
|
|
2023-12-07 18:11:25 -06:00
|
|
|
let predicate = NSPredicate(format: "%K == nil OR NOT (%K IN %@)", #keyPath(StoreApp._category), #keyPath(StoreApp._category), Array(knownCategories))
|
|
|
|
|
return predicate
|
|
|
|
|
}
|
2025-02-09 17:28:24 +05:30
|
|
|
|
2019-07-31 14:07:00 -07:00
|
|
|
@nonobjc class func fetchRequest() -> NSFetchRequest<StoreApp>
|
2019-05-20 21:24:53 +02:00
|
|
|
{
|
2019-07-31 14:07:00 -07:00
|
|
|
return NSFetchRequest<StoreApp>(entityName: "StoreApp")
|
2019-05-20 21:24:53 +02:00
|
|
|
}
|
2025-02-09 17:28:24 +05:30
|
|
|
|
2025-02-08 04:45:22 +05:30
|
|
|
private static var sideStoreAppIconURL: URL {
|
|
|
|
|
let iconNames = [
|
|
|
|
|
"AppIcon76x76@2x~ipad",
|
|
|
|
|
"AppIcon60x60@2x",
|
|
|
|
|
"AppIcon"
|
|
|
|
|
]
|
2025-02-09 17:28:24 +05:30
|
|
|
|
2025-02-08 04:45:22 +05:30
|
|
|
for iconName in iconNames {
|
|
|
|
|
if let path = Bundle.main.path(forResource: iconName, ofType: "png") {
|
|
|
|
|
return URL(fileURLWithPath: path)
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-02-09 17:28:24 +05:30
|
|
|
|
2025-02-08 04:45:22 +05:30
|
|
|
return URL(string: "https://sidestore.io/apps-v2.json/apps/sidestore/icon.png")!
|
|
|
|
|
}
|
2025-02-09 17:28:24 +05:30
|
|
|
|
2023-05-18 14:51:26 -05:00
|
|
|
class func makeAltStoreApp(version: String, buildVersion: String?, in context: NSManagedObjectContext) -> StoreApp
|
2019-06-17 16:31:10 -07:00
|
|
|
{
|
2025-02-09 17:28:24 +05:30
|
|
|
let placeholderBundleId = StoreApp.altstoreAppID
|
2025-02-08 04:45:22 +05:30
|
|
|
let placeholderDownloadURL = URL(string: "https://sidestore.io")!
|
|
|
|
|
let placeholderSourceID = Source.altStoreIdentifier
|
2025-02-09 17:28:24 +05:30
|
|
|
let placeholderVersion = "0.0.0"
|
|
|
|
|
let placeholderDate = Date.distantPast
|
|
|
|
|
// let placeholderDate = Date(timeIntervalSinceReferenceDate: 0)
|
|
|
|
|
// let placeholderDate = Date(timeIntervalSince1970: 0)
|
|
|
|
|
var placeholderChannel = ReleaseTracks.stable.stringValue // placeholder is always assumed to be from stable channel
|
|
|
|
|
let placeholderSize: Int32 = 0
|
|
|
|
|
|
|
|
|
|
#if BETA
|
2025-02-16 20:28:57 +05:30
|
|
|
placeholderChannel = ReleaseTracks.nightly.stringValue
|
2025-02-09 17:28:24 +05:30
|
|
|
#endif
|
|
|
|
|
|
2019-07-31 14:07:00 -07:00
|
|
|
let app = StoreApp(context: context)
|
2022-11-05 23:50:07 -07:00
|
|
|
app.name = "SideStore"
|
2025-02-09 17:28:24 +05:30
|
|
|
app.bundleIdentifier = placeholderBundleId
|
2023-02-02 08:09:15 -08:00
|
|
|
app.developerName = "Side Team"
|
|
|
|
|
app.localizedDescription = "SideStore is an alternative App Store."
|
2025-02-09 17:28:24 +05:30
|
|
|
app.iconURL = sideStoreAppIconURL
|
2019-08-20 19:06:03 -05:00
|
|
|
app.screenshotURLs = []
|
2025-02-08 04:45:22 +05:30
|
|
|
app.sourceIdentifier = placeholderSourceID
|
2025-02-09 17:28:24 +05:30
|
|
|
|
|
|
|
|
let appVersion = AppVersion.makeAppVersion(version: placeholderVersion,
|
2023-05-18 14:51:26 -05:00
|
|
|
buildVersion: buildVersion,
|
2025-02-09 17:28:24 +05:30
|
|
|
channel: placeholderChannel,
|
|
|
|
|
date: placeholderDate,
|
2025-02-08 04:45:22 +05:30
|
|
|
downloadURL: placeholderDownloadURL,
|
2025-02-09 17:28:24 +05:30
|
|
|
size: Int64(app._size),
|
2022-09-12 17:05:55 -07:00
|
|
|
appBundleID: app.bundleIdentifier,
|
2025-02-08 04:45:22 +05:30
|
|
|
sourceID: app.sourceIdentifier,
|
2022-09-12 17:05:55 -07:00
|
|
|
in: context)
|
2022-11-23 19:08:31 -06:00
|
|
|
try? app.setVersions([appVersion])
|
2025-02-08 13:11:27 +05:30
|
|
|
|
2023-02-02 08:09:15 -08:00
|
|
|
|
2019-06-17 16:31:10 -07:00
|
|
|
return app
|
|
|
|
|
}
|
2019-05-09 15:29:54 -07:00
|
|
|
}
|