mirror of
https://github.com/SideStore/SideStore.git
synced 2026-02-09 06:43:25 +01:00
- Multiple fixes and CI setup
This commit is contained in:
@@ -32,10 +32,10 @@ public extension UserDefaults
|
||||
@NSManaged var isBackgroundRefreshEnabled: Bool
|
||||
@NSManaged var isIdleTimeoutDisableEnabled: Bool
|
||||
@NSManaged var isAppLimitDisabled: Bool
|
||||
@NSManaged var isBetaUpdatesEnabled: Bool
|
||||
@NSManaged var isExportResignedAppEnabled: Bool
|
||||
@NSManaged var isVerboseOperationsLoggingEnabled: Bool
|
||||
@NSManaged var isMinimuxerConsoleLoggingEnabled: Bool
|
||||
@NSManaged var recreateDatabaseOnNextStart: Bool
|
||||
@NSManaged var isPairingReset: Bool
|
||||
@NSManaged var isDebugModeEnabled: Bool
|
||||
@NSManaged var presentedLaunchReminderNotification: Bool
|
||||
@@ -89,7 +89,7 @@ public extension UserDefaults
|
||||
|
||||
@NSManaged var permissionCheckingDisabled: Bool
|
||||
@NSManaged var responseCachingDisabled: Bool
|
||||
|
||||
|
||||
class func registerDefaults()
|
||||
{
|
||||
let ios13_5 = OperatingSystemVersion(majorVersion: 13, minorVersion: 5, patchVersion: 0)
|
||||
@@ -121,11 +121,11 @@ public extension UserDefaults
|
||||
|
||||
let defaults = [
|
||||
#keyPath(UserDefaults.isAppLimitDisabled): false,
|
||||
#keyPath(UserDefaults.isBetaUpdatesEnabled): false,
|
||||
#keyPath(UserDefaults.isExportResignedAppEnabled): false,
|
||||
#keyPath(UserDefaults.isDebugModeEnabled): false,
|
||||
#keyPath(UserDefaults.isVerboseOperationsLoggingEnabled): false,
|
||||
#keyPath(UserDefaults.isMinimuxerConsoleLoggingEnabled): true, // minimuxer logging is enabled by default as before
|
||||
#keyPath(UserDefaults.isMinimuxerConsoleLoggingEnabled): false, // minimuxer logging is disabled by default for console loggin
|
||||
#keyPath(UserDefaults.recreateDatabaseOnNextStart): false,
|
||||
#keyPath(UserDefaults.isBackgroundRefreshEnabled): true,
|
||||
#keyPath(UserDefaults.isIdleTimeoutDisableEnabled): true,
|
||||
#keyPath(UserDefaults.isPairingReset): true,
|
||||
|
||||
@@ -16,10 +16,6 @@
|
||||
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>$(MARKETING_VERSION)</string>
|
||||
<key>BuildRevision</key>
|
||||
<string>$(BUILD_REVISION)</string>
|
||||
<key>BuildChannel</key>
|
||||
<string>$(BUILD_CHANNEL)</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>$(CURRENT_PROJECT_VERSION)</string>
|
||||
</dict>
|
||||
|
||||
@@ -12,7 +12,7 @@ import CoreData
|
||||
import AltSign
|
||||
|
||||
@objc(Account)
|
||||
public class Account: NSManagedObject, Fetchable
|
||||
public class Account: BaseEntity
|
||||
{
|
||||
public var localizedName: String {
|
||||
var components = PersonNameComponents()
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="23605" systemVersion="24C101" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
|
||||
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="23605" systemVersion="24D60" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
|
||||
<entity name="Account" representedClassName="Account" syncable="YES">
|
||||
<attribute name="appleID" attributeType="String"/>
|
||||
<attribute name="firstName" attributeType="String"/>
|
||||
@@ -64,11 +64,9 @@
|
||||
<attribute name="buildVersion" optional="YES" attributeType="String"/>
|
||||
<attribute name="date" attributeType="Date" usesScalarValueType="NO"/>
|
||||
<attribute name="downloadURL" attributeType="URI"/>
|
||||
<attribute name="isBeta" optional="YES" attributeType="Boolean" usesScalarValueType="YES"/>
|
||||
<attribute name="localizedDescription" optional="YES" attributeType="String"/>
|
||||
<attribute name="maxOSVersion" optional="YES" attributeType="String"/>
|
||||
<attribute name="minOSVersion" optional="YES" attributeType="String"/>
|
||||
<attribute name="revision" optional="YES" attributeType="String"/>
|
||||
<attribute name="sha256" optional="YES" attributeType="String"/>
|
||||
<attribute name="size" attributeType="Integer 64" defaultValueString="0" usesScalarValueType="YES"/>
|
||||
<attribute name="sourceID" optional="YES" attributeType="String"/>
|
||||
@@ -231,6 +229,7 @@
|
||||
<attribute name="sourceURL" attributeType="URI"/>
|
||||
<attribute name="subtitle" optional="YES" attributeType="String"/>
|
||||
<attribute name="tintColor" optional="YES" attributeType="Transformable" valueTransformerName="ALTSecureValueTransformer"/>
|
||||
<attribute name="version" optional="YES" attributeType="Integer 64" defaultValueString="1" usesScalarValueType="NO"/>
|
||||
<attribute name="websiteURL" optional="YES" attributeType="URI"/>
|
||||
<relationship name="apps" toMany="YES" deletionRule="Cascade" ordered="YES" destinationEntity="StoreApp" inverseName="source" inverseEntity="StoreApp"/>
|
||||
<relationship name="featuredApps" optional="YES" toMany="YES" deletionRule="Nullify" ordered="YES" destinationEntity="StoreApp" inverseName="featuringSource" inverseEntity="StoreApp"/>
|
||||
@@ -245,28 +244,28 @@
|
||||
<attribute name="bundleIdentifier" attributeType="String"/>
|
||||
<attribute name="category" optional="YES" attributeType="String"/>
|
||||
<attribute name="developerName" attributeType="String"/>
|
||||
<attribute name="downloadURL" attributeType="URI"/>
|
||||
<attribute name="downloadURL" optional="YES" attributeType="URI"/>
|
||||
<attribute name="featuredSortID" optional="YES" attributeType="String"/>
|
||||
<attribute name="iconURL" attributeType="URI"/>
|
||||
<attribute name="isBeta" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES"/>
|
||||
<attribute name="isHiddenWithoutPledge" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES"/>
|
||||
<attribute name="isPledged" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES"/>
|
||||
<attribute name="isPledgeRequired" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES"/>
|
||||
<attribute name="localizedDescription" attributeType="String"/>
|
||||
<attribute name="localizedDescription" optional="YES" attributeType="String"/>
|
||||
<attribute name="marketplaceID" optional="YES" attributeType="String"/>
|
||||
<attribute name="name" attributeType="String"/>
|
||||
<attribute name="pledgeAmount" optional="YES" attributeType="Decimal"/>
|
||||
<attribute name="pledgeCurrency" optional="YES" attributeType="String"/>
|
||||
<attribute name="prefersCustomPledge" optional="YES" attributeType="Boolean" usesScalarValueType="YES"/>
|
||||
<attribute name="revision" optional="YES" attributeType="String"/>
|
||||
<attribute name="screenshotURLs" attributeType="Transformable" valueTransformerName="ALTSecureValueTransformer"/>
|
||||
<attribute name="size" attributeType="Integer 32" defaultValueString="0" usesScalarValueType="YES"/>
|
||||
<attribute name="sha256" optional="YES" attributeType="String"/>
|
||||
<attribute name="size" attributeType="Integer 64" defaultValueString="0" usesScalarValueType="YES"/>
|
||||
<attribute name="sortIndex" attributeType="Integer 32" defaultValueString="0" usesScalarValueType="YES"/>
|
||||
<attribute name="sourceIdentifier" optional="YES" attributeType="String"/>
|
||||
<attribute name="subtitle" optional="YES" attributeType="String"/>
|
||||
<attribute name="tintColor" optional="YES" attributeType="Transformable" valueTransformerName="ALTSecureValueTransformer"/>
|
||||
<attribute name="version" attributeType="String"/>
|
||||
<attribute name="versionDate" attributeType="Date" usesScalarValueType="NO"/>
|
||||
<attribute name="version" optional="YES" attributeType="String"/>
|
||||
<attribute name="versionDate" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
|
||||
<attribute name="versionDescription" optional="YES" attributeType="String"/>
|
||||
<relationship name="featuringSource" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="Source" inverseName="featuredApps" inverseEntity="Source"/>
|
||||
<relationship name="installedApp" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="InstalledApp" inverseName="storeApp" inverseEntity="InstalledApp"/>
|
||||
|
||||
@@ -12,7 +12,7 @@ import CoreData
|
||||
import AltSign
|
||||
|
||||
@objc(AppID)
|
||||
public class AppID: NSManagedObject, Fetchable
|
||||
public class AppID: BaseEntity
|
||||
{
|
||||
/* Properties */
|
||||
@NSManaged public var name: String
|
||||
|
||||
@@ -12,7 +12,7 @@ import UIKit
|
||||
import AltSign
|
||||
|
||||
@objc(AppPermission) @dynamicMemberLookup
|
||||
public class AppPermission: NSManagedObject, Fetchable
|
||||
public class AppPermission: BaseEntity
|
||||
{
|
||||
/* Properties */
|
||||
@NSManaged public var type: ALTAppPermissionType
|
||||
|
||||
@@ -16,7 +16,7 @@ public extension AppScreenshot
|
||||
}
|
||||
|
||||
@objc(AppScreenshot)
|
||||
public class AppScreenshot: NSManagedObject, Fetchable, Decodable
|
||||
public class AppScreenshot: BaseEntity, Decodable
|
||||
{
|
||||
/* Properties */
|
||||
@NSManaged public private(set) var imageURL: URL
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
import CoreData
|
||||
|
||||
@objc(AppVersion)
|
||||
public class AppVersion: NSManagedObject, Decodable, Fetchable
|
||||
public class AppVersion: BaseEntity, Decodable
|
||||
{
|
||||
/* Properties */
|
||||
@NSManaged public var version: String
|
||||
@@ -22,11 +22,16 @@ public class AppVersion: NSManagedObject, Decodable, Fetchable
|
||||
}
|
||||
@NSManaged @objc(buildVersion) public private(set) var _buildVersion: String
|
||||
|
||||
@NSManaged public var date: Date
|
||||
@NSManaged public var localizedDescription: String?
|
||||
@NSManaged public var downloadURL: URL
|
||||
@NSManaged public var size: Int64
|
||||
@NSManaged public var sha256: String?
|
||||
@NSManaged public private(set) var date: Date
|
||||
@NSManaged @objc(localizedDescription) private(set) var _localizedDescription: String?
|
||||
@NSManaged public private(set) var downloadURL: URL
|
||||
@NSManaged public private(set) var size: Int64
|
||||
@NSManaged public private(set) var sha256: String?
|
||||
|
||||
@nonobjc public var localizedDescription: String {
|
||||
return self._localizedDescription ?? app?.localizedDescription ??
|
||||
"localizedDescription not set, contact the source owner to fix this"
|
||||
}
|
||||
|
||||
@nonobjc public var minOSVersion: OperatingSystemVersion? {
|
||||
guard let osVersionString = self._minOSVersion else { return nil }
|
||||
@@ -46,11 +51,7 @@ public class AppVersion: NSManagedObject, Decodable, Fetchable
|
||||
|
||||
@NSManaged public var appBundleID: String
|
||||
@NSManaged public var sourceID: String?
|
||||
|
||||
// TODO: @mahee96: retire isBeta and use a string type to decode and store values as enum
|
||||
@NSManaged public var isBeta: Bool
|
||||
@NSManaged public var revision: String?
|
||||
|
||||
|
||||
/* Relationships */
|
||||
@NSManaged public private(set) var app: StoreApp?
|
||||
@NSManaged @objc(latestVersionApp) public internal(set) var latestSupportedVersionApp: StoreApp?
|
||||
@@ -71,8 +72,6 @@ public class AppVersion: NSManagedObject, Decodable, Fetchable
|
||||
case sha256
|
||||
case minOSVersion
|
||||
case maxOSVersion
|
||||
case isBeta = "beta"
|
||||
case revision = "commitID"
|
||||
}
|
||||
|
||||
public required init(from decoder: Decoder) throws
|
||||
@@ -89,7 +88,7 @@ public class AppVersion: NSManagedObject, Decodable, Fetchable
|
||||
self.buildVersion = try container.decodeIfPresent(String.self, forKey: .buildVersion)
|
||||
|
||||
self.date = try container.decode(Date.self, forKey: .date)
|
||||
self.localizedDescription = try container.decodeIfPresent(String.self, forKey: .localizedDescription)
|
||||
self._localizedDescription = try container.decodeIfPresent(String.self, forKey: .localizedDescription)
|
||||
|
||||
self.downloadURL = try container.decode(URL.self, forKey: .downloadURL)
|
||||
self.size = try container.decode(Int64.self, forKey: .size)
|
||||
@@ -97,9 +96,6 @@ public class AppVersion: NSManagedObject, Decodable, Fetchable
|
||||
self.sha256 = try container.decodeIfPresent(String.self, forKey: .sha256)?.lowercased()
|
||||
self._minOSVersion = try container.decodeIfPresent(String.self, forKey: .minOSVersion)
|
||||
self._maxOSVersion = try container.decodeIfPresent(String.self, forKey: .maxOSVersion)
|
||||
|
||||
self.isBeta = try container.decodeIfPresent(Bool.self, forKey: .isBeta) ?? false
|
||||
self.revision = try container.decodeIfPresent(String.self, forKey: .revision)
|
||||
}
|
||||
catch
|
||||
{
|
||||
@@ -140,6 +136,8 @@ public extension AppVersion
|
||||
return NSFetchRequest<AppVersion>(entityName: "AppVersion")
|
||||
}
|
||||
|
||||
// this creates an entry into context(for each instantiation), so don't invoke unnessarily for temp things
|
||||
// create once and use mutateForData() to update it if required
|
||||
class func makeAppVersion(
|
||||
version: String,
|
||||
buildVersion: String?,
|
||||
@@ -147,6 +145,7 @@ public extension AppVersion
|
||||
localizedDescription: String? = nil,
|
||||
downloadURL: URL,
|
||||
size: Int64,
|
||||
sha256: String? = nil,
|
||||
appBundleID: String,
|
||||
sourceID: String? = nil,
|
||||
in context: NSManagedObjectContext) -> AppVersion
|
||||
@@ -155,9 +154,10 @@ public extension AppVersion
|
||||
appVersion.version = version
|
||||
appVersion.buildVersion = buildVersion
|
||||
appVersion.date = date
|
||||
appVersion.localizedDescription = localizedDescription
|
||||
appVersion._localizedDescription = localizedDescription
|
||||
appVersion.downloadURL = downloadURL
|
||||
appVersion.size = size
|
||||
appVersion.sha256 = sha256
|
||||
appVersion.appBundleID = appBundleID
|
||||
appVersion.sourceID = sourceID
|
||||
|
||||
|
||||
24
AltStoreCore/Model/BaseEntity.swift
Normal file
24
AltStoreCore/Model/BaseEntity.swift
Normal file
@@ -0,0 +1,24 @@
|
||||
//
|
||||
// BaseEntity.swift
|
||||
// AltStore
|
||||
//
|
||||
// Created by Magesh K on 28/01/25.
|
||||
// Copyright © 2025 SideStore. All rights reserved.
|
||||
//
|
||||
|
||||
import CoreData
|
||||
|
||||
public class BaseEntity: NSManagedObject, Fetchable
|
||||
{
|
||||
@nonobjc class func fetchRequest<T>() -> NSFetchRequest<T>
|
||||
{
|
||||
fatalError("method not implemented, subclass needs to provide an implementation")
|
||||
}
|
||||
|
||||
internal override init(entity: NSEntityDescription, insertInto context: NSManagedObjectContext?)
|
||||
{
|
||||
super.init(entity: entity, insertInto: context)
|
||||
|
||||
// print("\(BaseEntity.self):\(type(of: self)): Inserting: \(entity.name ?? "nil") into context: \(String(describing: context))")
|
||||
}
|
||||
}
|
||||
@@ -40,7 +40,7 @@ fileprivate class PersistentContainer: RSTPersistentContainer
|
||||
|
||||
public class DatabaseManager
|
||||
{
|
||||
public static let shared = DatabaseManager()
|
||||
public static private(set) var shared = DatabaseManager()
|
||||
|
||||
public let persistentContainer: RSTPersistentContainer
|
||||
|
||||
@@ -64,10 +64,95 @@ public class DatabaseManager
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public extension DatabaseManager
|
||||
{
|
||||
private class func loadPersistentStoresSync() {
|
||||
let container = Self.shared.persistentContainer
|
||||
let semaphore = DispatchSemaphore(value: 0) // Semaphore to wait for async completion
|
||||
|
||||
container.loadPersistentStores { description, error in
|
||||
if let error = error {
|
||||
print("Failed to load store: \(error)")
|
||||
} else {
|
||||
print("Store URL: \(description.url ?? URL(string: "unknown")!)")
|
||||
}
|
||||
|
||||
semaphore.signal() // Signal the semaphore to unblock the thread
|
||||
}
|
||||
|
||||
semaphore.wait() // Wait for the semaphore signal to unblock the thread
|
||||
print("Persistent store loading complete.")
|
||||
}
|
||||
|
||||
class func deleteDatabase() -> Bool
|
||||
{
|
||||
// delete existing database and start fresh if required
|
||||
do {
|
||||
let container = Self.shared.persistentContainer
|
||||
|
||||
var databaseStore = container.persistentStoreCoordinator.persistentStores.first
|
||||
if databaseStore == nil{
|
||||
// perform a load before acquiring the databaseStoreURL
|
||||
Self.loadPersistentStoresSync()
|
||||
databaseStore = container.persistentStoreCoordinator.persistentStores.first
|
||||
}
|
||||
|
||||
|
||||
guard let databaseStore else
|
||||
{
|
||||
print("\nDatabase Delete request FAILED: databaseStore = nil\n")
|
||||
return false
|
||||
}
|
||||
|
||||
guard let databaseStoreURL = databaseStore.url else
|
||||
{
|
||||
print("\nDatabase Delete request FAILED: databaseStoreURL = nil\n")
|
||||
return false
|
||||
}
|
||||
|
||||
// Reset the managed object context
|
||||
Self.shared.persistentContainer.viewContext.reset()
|
||||
|
||||
// Remove all existing persistent stores
|
||||
for store in Self.shared.persistentContainer.persistentStoreCoordinator.persistentStores {
|
||||
try? Self.shared.persistentContainer.persistentStoreCoordinator.remove(store)
|
||||
}
|
||||
|
||||
// Now destroy the persistent store
|
||||
try Self.shared.persistentContainer.persistentStoreCoordinator.destroyPersistentStore(
|
||||
at: databaseStoreURL,
|
||||
ofType: NSSQLiteStoreType,
|
||||
options: nil
|
||||
)
|
||||
|
||||
// just be sure
|
||||
try? FileManager.default.removeItem(at: databaseStoreURL)
|
||||
|
||||
print("\nDatabase Delete: SUCCEEDED\n")
|
||||
|
||||
return true
|
||||
}catch{
|
||||
print("\nDatabase Delete request FAILED: \(error)\n")
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
class func recreateDatabase() {
|
||||
// Try to perform delete if one exists
|
||||
_ = Self.deleteDatabase()
|
||||
|
||||
// create new instance and load persistence store
|
||||
Self.shared = DatabaseManager()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public extension DatabaseManager
|
||||
{
|
||||
func start(completionHandler: @escaping (Error?) -> Void)
|
||||
{
|
||||
|
||||
func finish(_ error: Error?)
|
||||
{
|
||||
self.dispatchQueue.async {
|
||||
@@ -42,7 +42,7 @@ public protocol InstalledAppProtocol: Fetchable
|
||||
}
|
||||
|
||||
@objc(InstalledApp)
|
||||
public class InstalledApp: NSManagedObject, InstalledAppProtocol
|
||||
public class InstalledApp: BaseEntity, InstalledAppProtocol
|
||||
{
|
||||
/* Properties */
|
||||
@NSManaged public var name: String
|
||||
@@ -76,45 +76,93 @@ public class InstalledApp: NSManagedObject, InstalledAppProtocol
|
||||
return self.storeApp == nil
|
||||
}
|
||||
|
||||
|
||||
// TODO: integrate the following into the hasUpdate such that altstore sources also work with SideStore, ex: pledge check etc for updates
|
||||
/*
|
||||
|
||||
|
||||
|
||||
|
||||
// let predicateFormat = [
|
||||
// // isActive && storeApp != nil && latestSupportedVersion != nil
|
||||
// "%K == YES AND %K != nil AND %K != nil",
|
||||
//
|
||||
// "AND",
|
||||
//
|
||||
// // latestSupportedVersion.version != installedApp.version || latestSupportedVersion.buildVersion != installedApp.storeBuildVersion
|
||||
// //
|
||||
// // We have to also check !(latestSupportedVersion.buildVersion == '' && installedApp.storeBuildVersion == nil)
|
||||
// // because latestSupportedVersion.buildVersion stores an empty string for nil, while installedApp.storeBuildVersion uses NULL.
|
||||
// "(%K != %K OR (%K != %K AND NOT (%K == '' AND %K == nil)))",
|
||||
//
|
||||
// "AND",
|
||||
//
|
||||
// // !isPledgeRequired || isPledged
|
||||
// "(%K == NO OR %K == YES)"
|
||||
// ].joined(separator: " ")
|
||||
//
|
||||
// fetchRequest.predicate = NSPredicate(format: predicateFormat,
|
||||
// #keyPath(InstalledApp.isActive), #keyPath(InstalledApp.storeApp), #keyPath(InstalledApp.storeApp.latestSupportedVersion),
|
||||
// #keyPath(InstalledApp.storeApp.latestSupportedVersion.version), #keyPath(InstalledApp.version),
|
||||
// #keyPath(InstalledApp.storeApp.latestSupportedVersion._buildVersion), #keyPath(InstalledApp.storeBuildVersion),
|
||||
// #keyPath(InstalledApp.storeApp.latestSupportedVersion._buildVersion), #keyPath(InstalledApp.storeBuildVersion),
|
||||
// #keyPath(InstalledApp.storeApp.isPledgeRequired), #keyPath(InstalledApp.storeApp.isPledged))
|
||||
//
|
||||
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
@objc public var hasUpdate: Bool {
|
||||
guard let storeApp = self.storeApp,
|
||||
let latestSupportedVersion = storeApp.latestSupportedVersion?.version else {
|
||||
// Basic validation
|
||||
guard isActive,
|
||||
let storeApp = self.storeApp,
|
||||
let latestVersion = storeApp.latestSupportedVersion else
|
||||
{
|
||||
return false
|
||||
}
|
||||
|
||||
let currentVersion = SemanticVersion(self.version)
|
||||
let latestVersion = SemanticVersion(latestSupportedVersion)
|
||||
|
||||
if currentVersion == nil || latestVersion == nil {
|
||||
return self.version < latestSupportedVersion
|
||||
// Check pledge requirements
|
||||
guard !storeApp.isPledgeRequired || storeApp.isPledged else
|
||||
{
|
||||
return false
|
||||
}
|
||||
|
||||
let isBeta = storeApp.isBeta
|
||||
// Get current semantic versions
|
||||
let currentSemVer = SemanticVersion(self.version)
|
||||
let latestSemVer = SemanticVersion(latestVersion.version)
|
||||
|
||||
// compare semantic version updates
|
||||
// - for stable releases "beta" shouldn't be true
|
||||
if !isBeta && (currentVersion! < latestVersion!) {
|
||||
return true
|
||||
// If semantic versions can't be parsed, fall back to string comparison
|
||||
if currentSemVer == nil || latestSemVer == nil {
|
||||
return !matches(latestVersion)
|
||||
}
|
||||
// let currentVer = SemanticVersion("\(currentSemVer!.major).\(currentSemVer!.minor).\(currentSemVer!.patch)")
|
||||
// let latestVer = SemanticVersion("\(latestSemVer!.major).\(latestSemVer!.minor).\(latestSemVer!.patch)")
|
||||
|
||||
if UserDefaults.standard.isBetaUpdatesEnabled {
|
||||
// NOTE: beta builds will always need commit ID suffix
|
||||
// so it doesn't matter if semantic version was bumped, because commit ID won't be same
|
||||
// and we will accept this update
|
||||
|
||||
// storeApp.revision is set in sources.json deployed at apps.json for the respective source
|
||||
let revision = storeApp.revision ?? ""
|
||||
if(isBeta && !revision.isEmpty){
|
||||
let SHORT_COMMIT_LEN = 7
|
||||
let isRevisionValid = (revision.count == SHORT_COMMIT_LEN)
|
||||
let installedAppRevision = Bundle.main.object(forInfoDictionaryKey: "BuildRevision") as? String ?? ""
|
||||
// when installing beta build over stable build installedAppRevision will be empty!
|
||||
let isBetaUpdateAvailable = (installedAppRevision != revision)
|
||||
return isRevisionValid && isBetaUpdateAvailable
|
||||
}
|
||||
}
|
||||
return false
|
||||
// // Compare by major.minor.patch
|
||||
// if latestVer! > latestVer! {
|
||||
// return true
|
||||
// }
|
||||
|
||||
// // Check beta updates if enabled
|
||||
// if UserDefaults.standard.isBetaUpdatesEnabled,
|
||||
// ReleaseTracks.betaTracks.contains(latestVersion.channel),
|
||||
// latestVer == currentVer, // major.minor.patch are matching
|
||||
// // now compare by preRelease and build to break the tie
|
||||
// // TODO: since multiple tracks can be independent, when a different version is available on selected track than installed
|
||||
// // we accept it, now ex: if the setup is consistent for upstream merge lets say from alpha to nightly and alpha can never fall behind nightly,
|
||||
// // then the preRelease+build combo will always be incremental and our below not-equals check will still work.
|
||||
// (latestSemVer!.build != currentSemVer!.build) || (latestSemVer!.preRelease != currentSemVer!.preRelease)
|
||||
// {
|
||||
// return true
|
||||
// }
|
||||
|
||||
// else include everything as-is when doing lexicographic comparison
|
||||
// NOTE: stable x.y.z is always > x.y.z-abcd+1234
|
||||
return latestSemVer! > currentSemVer!
|
||||
}
|
||||
|
||||
|
||||
public var appIDCount: Int {
|
||||
return 1 + self.appExtensions.count
|
||||
@@ -165,8 +213,8 @@ public extension InstalledApp
|
||||
|
||||
self.resignedBundleIdentifier = resignedApp.bundleIdentifier
|
||||
self.version = resignedApp.version
|
||||
// TODO: @mahee96: requires altsign-marketplace branch release or equivalent
|
||||
// self.buildVersion = resignedApp.buildVersion
|
||||
|
||||
self.buildVersion = resignedApp.buildVersion
|
||||
self.storeBuildVersion = storeBuildVersion
|
||||
|
||||
self.certificateSerialNumber = certificateSerialNumber
|
||||
@@ -239,33 +287,7 @@ public extension InstalledApp
|
||||
{
|
||||
let fetchRequest = InstalledApp.fetchRequest() as NSFetchRequest<InstalledApp>
|
||||
|
||||
// let predicateFormat = [
|
||||
// // isActive && storeApp != nil && latestSupportedVersion != nil
|
||||
// "%K == YES AND %K != nil AND %K != nil",
|
||||
|
||||
// "AND",
|
||||
|
||||
// // latestSupportedVersion.version != installedApp.version || latestSupportedVersion.buildVersion != installedApp.storeBuildVersion
|
||||
// //
|
||||
// // We have to also check !(latestSupportedVersion.buildVersion == '' && installedApp.storeBuildVersion == nil)
|
||||
// // because latestSupportedVersion.buildVersion stores an empty string for nil, while installedApp.storeBuildVersion uses NULL.
|
||||
// "(%K != %K OR (%K != %K AND NOT (%K == '' AND %K == nil)))",
|
||||
|
||||
// "AND",
|
||||
|
||||
// // !isPledgeRequired || isPledged
|
||||
// "(%K == NO OR %K == YES)"
|
||||
// ].joined(separator: " ")
|
||||
|
||||
// fetchRequest.predicate = NSPredicate(format: predicateFormat,
|
||||
// #keyPath(InstalledApp.isActive), #keyPath(InstalledApp.storeApp), #keyPath(InstalledApp.storeApp.latestSupportedVersion),
|
||||
// #keyPath(InstalledApp.storeApp.latestSupportedVersion.version), #keyPath(InstalledApp.version),
|
||||
// #keyPath(InstalledApp.storeApp.latestSupportedVersion._buildVersion), #keyPath(InstalledApp.storeBuildVersion),
|
||||
// #keyPath(InstalledApp.storeApp.latestSupportedVersion._buildVersion), #keyPath(InstalledApp.storeBuildVersion),
|
||||
// #keyPath(InstalledApp.storeApp.isPledgeRequired), #keyPath(InstalledApp.storeApp.isPledged))
|
||||
|
||||
fetchRequest.predicate = NSPredicate(format: "%K == YES AND %K == YES",
|
||||
#keyPath(InstalledApp.isActive), #keyPath(InstalledApp.hasUpdate))
|
||||
fetchRequest.predicate = NSPredicate(format: "%K == YES", #keyPath(InstalledApp.hasUpdate))
|
||||
|
||||
return fetchRequest
|
||||
}
|
||||
@@ -383,13 +405,13 @@ public extension InstalledApp
|
||||
return openAppURL
|
||||
}
|
||||
|
||||
var isUpdateAvailable: Bool {
|
||||
guard let storeApp = self.storeApp, let latestVersion = storeApp.latestSupportedVersion else { return false }
|
||||
guard !storeApp.isPledgeRequired || storeApp.isPledged else { return false }
|
||||
// var isUpdateAvailable: Bool {
|
||||
// guard let storeApp = self.storeApp, let latestVersion = storeApp.latestSupportedVersion else { return false }
|
||||
// guard !storeApp.isPledgeRequired || storeApp.isPledged else { return false }
|
||||
|
||||
let isUpdateAvailable = !self.matches(latestVersion)
|
||||
return isUpdateAvailable
|
||||
}
|
||||
// let isUpdateAvailable = !self.matches(latestVersion)
|
||||
// return isUpdateAvailable
|
||||
// }
|
||||
}
|
||||
|
||||
public extension InstalledApp
|
||||
|
||||
@@ -12,7 +12,7 @@ import CoreData
|
||||
import AltSign
|
||||
|
||||
@objc(InstalledExtension)
|
||||
public class InstalledExtension: NSManagedObject, InstalledAppProtocol
|
||||
public class InstalledExtension: BaseEntity, InstalledAppProtocol
|
||||
{
|
||||
/* Properties */
|
||||
@NSManaged public var name: String
|
||||
|
||||
@@ -24,7 +24,7 @@ extension LoggedError
|
||||
}
|
||||
|
||||
@objc(LoggedError)
|
||||
public class LoggedError: NSManagedObject, Fetchable
|
||||
public class LoggedError: BaseEntity
|
||||
{
|
||||
/* Properties */
|
||||
@NSManaged public private(set) var date: Date
|
||||
|
||||
@@ -129,77 +129,107 @@ private extension Error
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
open class MergePolicy: RSTRelationshipPreservingMergePolicy
|
||||
{
|
||||
var permissionsByGlobalAppID = [String: Set<AnyHashable>]()
|
||||
var sortedVersionIDsByGlobalAppID = [String: NSOrderedSet]()
|
||||
var sortedScreenshotIDsByGlobalAppID = [String: NSOrderedSet]()
|
||||
var featuredAppIDsBySourceID = [String: [String]]()
|
||||
|
||||
|
||||
// MARK: - Actual Constraint conflict resolution takes place here!
|
||||
open override func resolve(constraintConflicts conflicts: [NSConstraintConflict]) throws
|
||||
{
|
||||
|
||||
// When conflict.databaseObject is unavailable, it means this is the first time insertion
|
||||
guard conflicts.allSatisfy({ $0.databaseObject != nil }) else {
|
||||
for conflict in conflicts
|
||||
{
|
||||
switch conflict.conflictingObjects.first
|
||||
{
|
||||
case is StoreApp where conflict.conflictingObjects.count == 2:
|
||||
// Modified cached StoreApp while replacing it with new one, causing context-level conflict.
|
||||
// Most likely, we set up a relationship between the new StoreApp and a NewsItem,
|
||||
// causing cached StoreApp to delete it's NewsItem relationship, resulting in (resolvable) conflict.
|
||||
|
||||
if let previousApp = conflict.conflictingObjects.first(where: { !$0.isInserted }) as? StoreApp
|
||||
{
|
||||
// Delete previous permissions (different than below).
|
||||
for case let permission as AppPermission in previousApp._permissions where permission.app == nil
|
||||
{
|
||||
permission.managedObjectContext?.delete(permission)
|
||||
}
|
||||
|
||||
// Delete previous versions (different than below).
|
||||
for case let appVersion as AppVersion in previousApp._versions where appVersion.app == nil
|
||||
{
|
||||
appVersion.managedObjectContext?.delete(appVersion)
|
||||
}
|
||||
|
||||
// Delete previous screenshots (different than below).
|
||||
for case let appScreenshot as AppScreenshot in previousApp._screenshots where appScreenshot.app == nil
|
||||
{
|
||||
appScreenshot.managedObjectContext?.delete(appScreenshot)
|
||||
}
|
||||
}
|
||||
|
||||
case is AppVersion where conflict.conflictingObjects.count == 2:
|
||||
// Occurs first time fetching sources after migrating from pre-AppVersion database model.
|
||||
let conflictingAppVersions = conflict.conflictingObjects.lazy.compactMap { $0 as? AppVersion }
|
||||
|
||||
// Primary AppVersion == AppVersion whose latestVersionApp.latestVersion points back to itself.
|
||||
if let primaryAppVersion = conflictingAppVersions.first(where: { $0.latestSupportedVersionApp?.latestSupportedVersion == $0 }),
|
||||
let secondaryAppVersion = conflictingAppVersions.first(where: { $0 != primaryAppVersion })
|
||||
{
|
||||
secondaryAppVersion.managedObjectContext?.delete(secondaryAppVersion)
|
||||
print("[ALTLog] Resolving AppVersion context-level conflict. Most likely due to migrating from pre-AppVersion model version.", primaryAppVersion)
|
||||
}
|
||||
|
||||
default:
|
||||
// Unknown context-level conflict.
|
||||
assertionFailure("MergePolicy is only intended to work with database-level conflicts.")
|
||||
}
|
||||
}
|
||||
|
||||
try self.resolveWhenDatabaseObjectUnavailable(conflicts)
|
||||
try super.resolve(constraintConflicts: conflicts)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
var permissionsByGlobalAppID = [String: Set<AnyHashable>]()
|
||||
var sortedVersionIDsByGlobalAppID = [String: NSOrderedSet]()
|
||||
var sortedScreenshotIDsByGlobalAppID = [String: NSOrderedSet]()
|
||||
permissionsByGlobalAppID.removeAll()
|
||||
sortedVersionIDsByGlobalAppID.removeAll()
|
||||
sortedScreenshotIDsByGlobalAppID.removeAll()
|
||||
featuredAppIDsBySourceID.removeAll()
|
||||
|
||||
var featuredAppIDsBySourceID = [String: [String]]()
|
||||
// When conflict.databaseObject is available, it means this is replace (delete + insert) or update
|
||||
try self.resolveWhenDatabaseObjectAvailable(conflicts)
|
||||
try super.resolve(constraintConflicts: conflicts)
|
||||
|
||||
try self.performPostMergeValidationAndCorrections(for: conflicts)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
extension MergePolicy{
|
||||
|
||||
// When conflict.databaseObject is unavailable, the conflicts exist only in context level and they must be new insertions
|
||||
private func resolveWhenDatabaseObjectUnavailable(_ conflicts: [NSConstraintConflict]) throws{
|
||||
|
||||
for conflict in conflicts
|
||||
{
|
||||
switch conflict.conflictingObjects.first
|
||||
{
|
||||
case is StoreApp where conflict.conflictingObjects.count == 2:
|
||||
// Modified cached StoreApp while replacing it with new one, causing context-level conflict.
|
||||
// Most likely, we set up a relationship between the new StoreApp and a NewsItem,
|
||||
// causing cached StoreApp to delete it's NewsItem relationship, resulting in (resolvable) conflict.
|
||||
|
||||
if let previousApp = conflict.conflictingObjects.first(where: { !$0.isInserted }) as? StoreApp
|
||||
{
|
||||
// Delete previous permissions (different than below).
|
||||
for case let permission as AppPermission in previousApp._permissions where permission.app == nil
|
||||
{
|
||||
permission.managedObjectContext?.delete(permission)
|
||||
}
|
||||
|
||||
// Delete previous versions (different than below).
|
||||
for case let appVersion as AppVersion in previousApp._versions where appVersion.app == nil
|
||||
{
|
||||
appVersion.managedObjectContext?.delete(appVersion)
|
||||
}
|
||||
|
||||
// Delete previous screenshots (different than below).
|
||||
for case let appScreenshot as AppScreenshot in previousApp._screenshots where appScreenshot.app == nil
|
||||
{
|
||||
appScreenshot.managedObjectContext?.delete(appScreenshot)
|
||||
}
|
||||
}
|
||||
|
||||
case is AppVersion where conflict.conflictingObjects.count == 2:
|
||||
// Occurs first time fetching sources after migrating from pre-AppVersion database model.
|
||||
let conflictingAppVersions = conflict.conflictingObjects.lazy.compactMap { $0 as? AppVersion }
|
||||
|
||||
// Primary AppVersion == AppVersion whose latestVersionApp.latestVersion points back to itself.
|
||||
if let primaryAppVersion = conflictingAppVersions.first(where: { $0.latestSupportedVersionApp?.latestSupportedVersion == $0 }),
|
||||
let secondaryAppVersion = conflictingAppVersions.first(where: { $0 != primaryAppVersion })
|
||||
{
|
||||
secondaryAppVersion.managedObjectContext?.delete(secondaryAppVersion)
|
||||
print("[ALTLog] Resolving AppVersion context-level conflict. Most likely due to migrating from pre-AppVersion model version.", primaryAppVersion)
|
||||
}
|
||||
|
||||
default:
|
||||
// Unknown context-level conflict.
|
||||
// assertionFailure("MergePolicy is only intended to work with database-level conflicts.")
|
||||
assertionFailure("Context Conflict Detected: is there ambigious data in your incoming sources?\nConflict:\(conflict)")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// When conflict.databaseObject is available, it means this is replace (delete + insert) or update
|
||||
private func resolveWhenDatabaseObjectAvailable(_ conflicts: [NSConstraintConflict]) throws {
|
||||
|
||||
for conflict in conflicts
|
||||
{
|
||||
switch conflict.databaseObject
|
||||
{
|
||||
case let databaseObject as StoreApp:
|
||||
guard let contextApp = conflict.conflictingObjects.first as? StoreApp else { break }
|
||||
|
||||
|
||||
// Permissions
|
||||
let contextPermissions = Set(contextApp._permissions.lazy.compactMap { $0 as? AppPermission }.map { AnyHashable($0.permission) })
|
||||
for case let databasePermission as AppPermission in databaseObject._permissions /* where !contextPermissions.contains(AnyHashable(databasePermission.permission)) */ // Compiler error as of Xcode 15
|
||||
@@ -308,7 +338,13 @@ open class MergePolicy: RSTRelationshipPreservingMergePolicy
|
||||
}
|
||||
}
|
||||
|
||||
try super.resolve(constraintConflicts: conflicts)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
extension MergePolicy{
|
||||
|
||||
func performPostMergeValidationAndCorrections(for conflicts: [NSConstraintConflict]) throws{
|
||||
|
||||
for conflict in conflicts
|
||||
{
|
||||
@@ -318,23 +354,23 @@ open class MergePolicy: RSTRelationshipPreservingMergePolicy
|
||||
do
|
||||
{
|
||||
var appVersions = databaseObject.versions
|
||||
|
||||
|
||||
if let globallyUniqueID = databaseObject.globallyUniqueID
|
||||
{
|
||||
// Permissions
|
||||
if let appPermissions = permissionsByGlobalAppID[globallyUniqueID],
|
||||
case let databasePermissions = Set(databaseObject.permissions.map({ AnyHashable($0.permission) })),
|
||||
databasePermissions != appPermissions
|
||||
case let databasePermissions = Set(databaseObject.permissions.map({ AnyHashable($0.permission) })),
|
||||
databasePermissions != appPermissions
|
||||
{
|
||||
// Sorting order doesn't matter, but elements themselves don't match so throw error.
|
||||
throw MergeError.incorrectPermissions(for: databaseObject)
|
||||
}
|
||||
|
||||
|
||||
// App versions
|
||||
if let sortedAppVersionIDs = sortedVersionIDsByGlobalAppID[globallyUniqueID],
|
||||
let sortedAppVersionsIDsArray = sortedAppVersionIDs.array as? [String],
|
||||
let sortedAppVersionsIDsArray = sortedAppVersionIDs.array as? [String],
|
||||
case let databaseVersionIDs = databaseObject.versions.map({ $0.versionID }),
|
||||
databaseVersionIDs != sortedAppVersionsIDsArray
|
||||
databaseVersionIDs != sortedAppVersionsIDsArray
|
||||
{
|
||||
// databaseObject.versions post-merge doesn't match contextApp.versions pre-merge, so attempt to fix by re-sorting.
|
||||
|
||||
@@ -355,9 +391,9 @@ open class MergePolicy: RSTRelationshipPreservingMergePolicy
|
||||
|
||||
// Screenshots
|
||||
if let sortedScreenshotIDs = sortedScreenshotIDsByGlobalAppID[globallyUniqueID],
|
||||
let sortedScreenshotIDsArray = sortedScreenshotIDs.array as? [String],
|
||||
case let databaseScreenshotIDs = databaseObject.screenshots.map({ $0.screenshotID }),
|
||||
databaseScreenshotIDs != sortedScreenshotIDsArray
|
||||
let sortedScreenshotIDsArray = sortedScreenshotIDs.array as? [String],
|
||||
case let databaseScreenshotIDs = databaseObject.screenshots.map({ $0.screenshotID }),
|
||||
databaseScreenshotIDs != sortedScreenshotIDsArray
|
||||
{
|
||||
// Screenshot order is incorrect, so attempt to fix by re-sorting.
|
||||
let fixedScreenshots = databaseObject.screenshots.sorted { (screenshotA, screenshotB) in
|
||||
@@ -421,3 +457,9 @@ open class MergePolicy: RSTRelationshipPreservingMergePolicy
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension MergePolicy{
|
||||
class func getHeader(_ obj: AnyObject) -> String {
|
||||
return obj.debugDescription.components(separatedBy: "; data:").first ?? ""
|
||||
}
|
||||
}
|
||||
@@ -22,27 +22,27 @@ fileprivate extension NSManagedObject
|
||||
}
|
||||
|
||||
var storeAppVersion: String? {
|
||||
let version = self.value(forKey: #keyPath(StoreApp._version)) as? String
|
||||
let version = self.value(forKey: #keyPath(StoreApp.version)) as? String
|
||||
return version
|
||||
}
|
||||
|
||||
var storeAppVersionDate: Date? {
|
||||
let versionDate = self.value(forKey: #keyPath(StoreApp._versionDate)) as? Date
|
||||
let versionDate = self.value(forKey: #keyPath(StoreApp.versionDate)) as? Date
|
||||
return versionDate
|
||||
}
|
||||
|
||||
var storeAppVersionDescription: String? {
|
||||
let versionDescription = self.value(forKey: #keyPath(StoreApp._versionDescription)) as? String
|
||||
let versionDescription = self.value(forKey: #keyPath(StoreApp.versionDescription)) as? String
|
||||
return versionDescription
|
||||
}
|
||||
|
||||
var storeAppSize: NSNumber? {
|
||||
let size = self.value(forKey: #keyPath(StoreApp._size)) as? NSNumber
|
||||
let size = self.value(forKey: #keyPath(StoreApp.size)) as? NSNumber
|
||||
return size
|
||||
}
|
||||
|
||||
var storeAppDownloadURL: URL? {
|
||||
let downloadURL = self.value(forKey: #keyPath(StoreApp._downloadURL)) as? URL
|
||||
let downloadURL = self.value(forKey: #keyPath(StoreApp.downloadURL)) as? URL
|
||||
return downloadURL
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ fileprivate extension NSManagedObject
|
||||
let appVersion = NSEntityDescription.insertNewObject(forEntityName: AppVersion.entity().name!, into: context)
|
||||
appVersion.setValue(version, forKey: #keyPath(AppVersion.version))
|
||||
appVersion.setValue(date, forKey: #keyPath(AppVersion.date))
|
||||
appVersion.setValue(localizedDescription, forKey: #keyPath(AppVersion.localizedDescription))
|
||||
appVersion.setValue(localizedDescription, forKey: #keyPath(AppVersion._localizedDescription))
|
||||
appVersion.setValue(downloadURL, forKey: #keyPath(AppVersion.downloadURL))
|
||||
appVersion.setValue(size, forKey: #keyPath(AppVersion.size))
|
||||
appVersion.setValue(appBundleID, forKey: #keyPath(AppVersion.appBundleID))
|
||||
|
||||
@@ -10,7 +10,7 @@ import UIKit
|
||||
import CoreData
|
||||
|
||||
@objc(NewsItem)
|
||||
public class NewsItem: NSManagedObject, Decodable, Fetchable
|
||||
public class NewsItem: BaseEntity, Decodable
|
||||
{
|
||||
/* Properties */
|
||||
@NSManaged public var identifier: String
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
import CoreData
|
||||
|
||||
@objc(ManagedPatron)
|
||||
public class ManagedPatron: NSManagedObject, Fetchable
|
||||
public class ManagedPatron: BaseEntity
|
||||
{
|
||||
@NSManaged public var name: String
|
||||
@NSManaged public var identifier: String
|
||||
@@ -18,7 +18,7 @@ public class ManagedPatron: NSManagedObject, Fetchable
|
||||
{
|
||||
super.init(entity: entity, insertInto: context)
|
||||
}
|
||||
|
||||
|
||||
public init?(patron: PatreonAPI.Patron, context: NSManagedObjectContext)
|
||||
{
|
||||
// Only cache Patrons with non-nil names.
|
||||
@@ -9,7 +9,7 @@
|
||||
import CoreData
|
||||
|
||||
@objc(RefreshAttempt)
|
||||
public class RefreshAttempt: NSManagedObject, Fetchable
|
||||
public class RefreshAttempt: BaseEntity
|
||||
{
|
||||
@NSManaged public var identifier: String
|
||||
@NSManaged public var date: Date
|
||||
|
||||
@@ -52,6 +52,8 @@ public struct AppVersionFeed: Codable {
|
||||
|
||||
let downloadURL: URL
|
||||
let size: Int64
|
||||
// added in 0.6.0
|
||||
let sha256: String? // sha 256 of the uploaded IPA
|
||||
|
||||
enum CodingKeys: String, CodingKey
|
||||
{
|
||||
@@ -60,6 +62,8 @@ public struct AppVersionFeed: Codable {
|
||||
case localizedDescription
|
||||
case downloadURL
|
||||
case size
|
||||
// added in 0.6.0
|
||||
case sha256
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,7 +103,7 @@ public struct StoreAppFeed: Codable {
|
||||
let isBeta: Bool
|
||||
|
||||
// let source: Source?
|
||||
let appPermission: [AppPermissionFeed]
|
||||
let appPermissions: [AppPermissionFeed]
|
||||
let versions: [AppVersionFeed]
|
||||
|
||||
enum CodingKeys: String, CodingKey
|
||||
@@ -111,7 +115,7 @@ public struct StoreAppFeed: Codable {
|
||||
case isBeta = "beta"
|
||||
case localizedDescription
|
||||
case name
|
||||
case appPermission = "permissions"
|
||||
case appPermissions
|
||||
case platformURLs
|
||||
case screenshotURLs
|
||||
case size
|
||||
@@ -154,6 +158,7 @@ public struct NewsItemFeed: Codable {
|
||||
|
||||
|
||||
public struct SourceJSON: Codable {
|
||||
let version: Int?
|
||||
let name: String
|
||||
let identifier: String
|
||||
let sourceURL: URL
|
||||
@@ -163,6 +168,7 @@ public struct SourceJSON: Codable {
|
||||
|
||||
enum CodingKeys: String, CodingKey
|
||||
{
|
||||
case version
|
||||
case name
|
||||
case identifier
|
||||
case sourceURL
|
||||
@@ -195,9 +201,10 @@ public extension Source
|
||||
}
|
||||
|
||||
@objc(Source)
|
||||
public class Source: NSManagedObject, Fetchable, Decodable
|
||||
public class Source: BaseEntity, Decodable
|
||||
{
|
||||
/* Properties */
|
||||
@NSManaged public var version: Int
|
||||
@NSManaged public var name: String
|
||||
@NSManaged public private(set) var identifier: String
|
||||
@NSManaged public var sourceURL: URL
|
||||
@@ -246,6 +253,12 @@ public class Source: NSManagedObject, Fetchable, Decodable
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public var isSourceAtLeastV2: Bool {
|
||||
return self.version >= 2
|
||||
}
|
||||
|
||||
|
||||
// `internal` to prevent accidentally using instead of `effectiveFeaturedApps`
|
||||
@nonobjc internal var featuredApps: [StoreApp]? {
|
||||
return self._hasFeaturedApps ? self._featuredApps.array as? [StoreApp] : nil
|
||||
@@ -253,6 +266,7 @@ public class Source: NSManagedObject, Fetchable, Decodable
|
||||
|
||||
private enum CodingKeys: String, CodingKey
|
||||
{
|
||||
case version
|
||||
case name
|
||||
case sourceURL
|
||||
case subtitle
|
||||
@@ -287,6 +301,10 @@ public class Source: NSManagedObject, Fetchable, Decodable
|
||||
self.name = try container.decode(String.self, forKey: .name)
|
||||
|
||||
// Optional Values
|
||||
|
||||
// use sourceversion = 1 by default if not specified in source json
|
||||
self.version = try container.decodeIfPresent(Int.self, forKey: .version) ?? 1
|
||||
|
||||
self.subtitle = try container.decodeIfPresent(String.self, forKey: .subtitle)
|
||||
self.websiteURL = try container.decodeIfPresent(URL.self, forKey: .websiteURL)
|
||||
self.localizedDescription = try container.decodeIfPresent(String.self, forKey: .localizedDescription)
|
||||
|
||||
@@ -123,8 +123,15 @@ private struct PatreonParameters: Decodable
|
||||
var hidden: Bool?
|
||||
}
|
||||
|
||||
// added for v0.6.0
|
||||
extension StoreApp {
|
||||
//MARK: - properties
|
||||
@NSManaged public private(set) var sha256: String?
|
||||
}
|
||||
|
||||
|
||||
@objc(StoreApp)
|
||||
public class StoreApp: NSManagedObject, Decodable, Fetchable
|
||||
public class StoreApp: BaseEntity, Decodable
|
||||
{
|
||||
/* Properties */
|
||||
@NSManaged public private(set) var name: String
|
||||
@@ -132,8 +139,8 @@ public class StoreApp: NSManagedObject, Decodable, Fetchable
|
||||
@NSManaged public private(set) var subtitle: String?
|
||||
|
||||
@NSManaged public private(set) var developerName: String
|
||||
@NSManaged public private(set) var localizedDescription: String
|
||||
@NSManaged @objc(size) internal var _size: Int32
|
||||
@NSManaged public private(set) var localizedDescription: String?
|
||||
@NSManaged public private(set) var size: Int64
|
||||
|
||||
@nonobjc public var category: StoreCategory? {
|
||||
guard let _category else { return nil }
|
||||
@@ -146,14 +153,13 @@ public class StoreApp: NSManagedObject, Decodable, Fetchable
|
||||
@NSManaged public private(set) var iconURL: URL
|
||||
@NSManaged public private(set) var screenshotURLs: [URL]
|
||||
|
||||
@NSManaged @objc(downloadURL) internal var _downloadURL: URL
|
||||
@NSManaged public private(set) var downloadURL: URL?
|
||||
@NSManaged public private(set) var platformURLs: PlatformURLs?
|
||||
|
||||
@NSManaged public private(set) var tintColor: UIColor?
|
||||
|
||||
// TODO: @mahee96: retire isBeta and use a string type to decode and store values as enum
|
||||
@NSManaged public private(set) var isBeta: Bool
|
||||
@NSManaged public private(set) var revision: String?
|
||||
|
||||
// Required for Marketplace apps.
|
||||
@NSManaged public private(set) var marketplaceID: String?
|
||||
@@ -202,9 +208,9 @@ public class StoreApp: NSManagedObject, Decodable, Fetchable
|
||||
@NSManaged private var primitiveSourceIdentifier: String?
|
||||
|
||||
// Legacy (kept for backwards compatibility)
|
||||
@NSManaged @objc(version) internal private(set) var _version: String
|
||||
@NSManaged @objc(versionDate) internal private(set) var _versionDate: Date
|
||||
@NSManaged @objc(versionDescription) internal private(set) var _versionDescription: String?
|
||||
@NSManaged public private(set) var version: String?
|
||||
@NSManaged public private(set) var versionDate: Date?
|
||||
@NSManaged public private(set) var versionDescription: String?
|
||||
|
||||
/* Relationships */
|
||||
@NSManaged public var installedApp: InstalledApp?
|
||||
@@ -243,30 +249,6 @@ public class StoreApp: NSManagedObject, Decodable, Fetchable
|
||||
return self._versions.array as! [AppVersion]
|
||||
}
|
||||
|
||||
@nonobjc public var size: Int64? {
|
||||
guard let version = self.latestSupportedVersion else { return nil }
|
||||
return version.size
|
||||
}
|
||||
|
||||
@nonobjc public var version: String? {
|
||||
guard let version = self.latestSupportedVersion else { return nil }
|
||||
return version.version
|
||||
}
|
||||
|
||||
@nonobjc public var versionDescription: String? {
|
||||
guard let version = self.latestSupportedVersion else { return nil }
|
||||
return version.localizedDescription
|
||||
}
|
||||
|
||||
@nonobjc public var versionDate: Date? {
|
||||
guard let version = self.latestSupportedVersion else { return nil }
|
||||
return version.date
|
||||
}
|
||||
|
||||
@nonobjc public var downloadURL: URL? {
|
||||
guard let version = self.latestSupportedVersion else { return nil }
|
||||
return version.downloadURL
|
||||
}
|
||||
@nonobjc public var screenshots: [AppScreenshot] {
|
||||
return self._screenshots.array as! [AppScreenshot]
|
||||
}
|
||||
@@ -292,7 +274,6 @@ public class StoreApp: NSManagedObject, Decodable, Fetchable
|
||||
case permissions = "appPermissions"
|
||||
case size
|
||||
case isBeta = "beta"
|
||||
case revision = "commitID"
|
||||
case versions
|
||||
case patreon
|
||||
case category
|
||||
@@ -303,6 +284,9 @@ public class StoreApp: NSManagedObject, Decodable, Fetchable
|
||||
case versionDate
|
||||
case downloadURL
|
||||
case screenshotURLs
|
||||
|
||||
// new for v0.6.0
|
||||
case sha256
|
||||
}
|
||||
|
||||
public required init(from decoder: Decoder) throws
|
||||
@@ -316,50 +300,16 @@ public class StoreApp: NSManagedObject, Decodable, Fetchable
|
||||
{
|
||||
let container = try decoder.container(keyedBy: CodingKeys.self)
|
||||
|
||||
self.sha256 = try container.decodeIfPresent(String.self, forKey: .sha256)
|
||||
|
||||
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)
|
||||
self.localizedDescription = try container.decode(String.self, forKey: .localizedDescription)
|
||||
self.localizedDescription = try container.decodeIfPresent(String.self, forKey: .localizedDescription)
|
||||
self.iconURL = try container.decode(URL.self, forKey: .iconURL)
|
||||
|
||||
self.subtitle = try container.decodeIfPresent(String.self, forKey: .subtitle)
|
||||
self.isBeta = try container.decodeIfPresent(Bool.self, forKey: .isBeta) ?? false
|
||||
self.revision = try container.decodeIfPresent(String.self, forKey: .revision)
|
||||
|
||||
var downloadURL = try container.decodeIfPresent(URL.self, forKey: .downloadURL)
|
||||
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 = downloadURL {
|
||||
self._downloadURL = downloadURL
|
||||
} else {
|
||||
let version = try container.decode(String.self, forKey: .version)
|
||||
if let versions = try container.decodeIfPresent([AppVersion].self, forKey: .versions){
|
||||
for ver in versions {
|
||||
if ver.version == version {
|
||||
self._downloadURL = ver.downloadURL
|
||||
downloadURL = ver.downloadURL // not sure if this is needed
|
||||
}
|
||||
}
|
||||
throw DecodingError.dataCorruptedError(forKey: .downloadURL, in: container, debugDescription: "E downloadURL:String or downloadURLs:[[Platform:URL]] key required.")
|
||||
} else {
|
||||
throw DecodingError.dataCorruptedError(forKey: .downloadURL, in: container, debugDescription: "E downloadURL:String or downloadURLs:[[Platform:URL]] key required.")
|
||||
}
|
||||
// Required for Marketplace apps, but we'll verify later.
|
||||
self.marketplaceID = try container.decodeIfPresent(String.self, forKey: .marketplaceID)
|
||||
|
||||
// else {
|
||||
// throw DecodingError.dataCorruptedError(forKey: .downloadURL, in: container, debugDescription: "E downloadURL:String or downloadURLs:[[Platform:URL]] key required.")
|
||||
// }
|
||||
}
|
||||
|
||||
if let tintColorHex = try container.decodeIfPresent(String.self, forKey: .tintColor)
|
||||
{
|
||||
@@ -383,13 +333,21 @@ public class StoreApp: NSManagedObject, Decodable, Fetchable
|
||||
}
|
||||
else if let screenshotURLs = try container.decodeIfPresent([URL].self, forKey: .screenshotURLs)
|
||||
{
|
||||
// Update to iPhone 13 screen size
|
||||
let modernAspectRatio = CGSize(width: 1170, height: 2532)
|
||||
// Assume 9:16 iPhone 8 screen dimensions for legacy screenshotURLs.
|
||||
let legacyAspectRatio = CGSize(width: 750, height: 1334)
|
||||
|
||||
appScreenshots = screenshotURLs.map { imageURL in
|
||||
let screenshot = AppScreenshot(imageURL: imageURL, size: modernAspectRatio, deviceType: .iphone, context: context)
|
||||
let screenshot = AppScreenshot(imageURL: imageURL, size: legacyAspectRatio, deviceType: .iphone, context: context)
|
||||
return screenshot
|
||||
}
|
||||
|
||||
// // Update to iPhone 13 screen size
|
||||
// let modernAspectRatio = CGSize(width: 1170, height: 2532)
|
||||
|
||||
// appScreenshots = screenshotURLs.map { imageURL in
|
||||
// let screenshot = AppScreenshot(imageURL: imageURL, size: modernAspectRatio, deviceType: .iphone, context: context)
|
||||
// return screenshot
|
||||
// }
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -418,6 +376,9 @@ public class StoreApp: NSManagedObject, Decodable, Fetchable
|
||||
self._permissions = NSSet()
|
||||
}
|
||||
|
||||
// Required for Marketplace apps, but we'll verify later.
|
||||
self.marketplaceID = try container.decodeIfPresent(String.self, forKey: .marketplaceID)
|
||||
|
||||
if let versions = try container.decodeIfPresent([AppVersion].self, forKey: .versions)
|
||||
{
|
||||
//TODO: Throw error if there isn't at least one version.
|
||||
@@ -479,6 +440,28 @@ public class StoreApp: NSManagedObject, Decodable, Fetchable
|
||||
try self.setVersions([appVersion])
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
}
|
||||
|
||||
// Must _explicitly_ set to false to ensure it updates cached database value.
|
||||
self.isPledged = false
|
||||
self.prefersCustomPledge = false
|
||||
@@ -560,11 +543,13 @@ internal extension StoreApp
|
||||
}
|
||||
|
||||
// Preserve backwards compatibility by assigning legacy property values.
|
||||
self._version = latestVersion.version
|
||||
self._versionDate = latestVersion.date
|
||||
self._versionDescription = latestVersion.localizedDescription
|
||||
self._downloadURL = latestVersion.downloadURL
|
||||
self._size = Int32(latestVersion.size)
|
||||
self.version = latestVersion.version
|
||||
self.versionDate = latestVersion.date
|
||||
self.versionDescription = latestVersion.localizedDescription
|
||||
self.downloadURL = latestVersion.downloadURL
|
||||
self.size = latestVersion.size
|
||||
self.localizedDescription = latestVersion.localizedDescription
|
||||
self.sha256 = latestVersion.sha256
|
||||
}
|
||||
|
||||
func setPermissions(_ permissions: Set<AppPermission>)
|
||||
@@ -674,24 +659,63 @@ public extension StoreApp
|
||||
return NSFetchRequest<StoreApp>(entityName: "StoreApp")
|
||||
}
|
||||
|
||||
//MARK: - override in subclasses if required
|
||||
@objc func placeholderAppVersion(appVersion: AppVersion, in context: NSManagedObjectContext) -> AppVersion{
|
||||
return appVersion
|
||||
}
|
||||
//MARK: - override in subclasses if required
|
||||
@objc class func createStoreApp(in context: NSManagedObjectContext) -> StoreApp{
|
||||
return StoreApp(context: context)
|
||||
}
|
||||
|
||||
|
||||
class func isPlaceHolderVersion(_ version: AppVersion) -> Bool{
|
||||
return version.version == "0.0.0" && version.date == Date.distantPast && version.appBundleID == StoreApp.altstoreAppID
|
||||
}
|
||||
|
||||
class func isPlaceHolderStoreApp(_ app: StoreApp) -> Bool{
|
||||
return app.version == "0.0.0" && app.versionDate == Date.distantPast && app.bundleIdentifier == StoreApp.altstoreAppID
|
||||
}
|
||||
|
||||
|
||||
private static var sideStoreAppIconURL: URL {
|
||||
let iconNames = [
|
||||
"AppIcon76x76@2x~ipad",
|
||||
"AppIcon60x60@2x",
|
||||
"AppIcon"
|
||||
]
|
||||
|
||||
for iconName in iconNames {
|
||||
if let path = Bundle.main.path(forResource: iconName, ofType: "png") {
|
||||
return URL(fileURLWithPath: path)
|
||||
}
|
||||
}
|
||||
|
||||
return URL(string: "https://sidestore.io/apps-v2.json/apps/sidestore/icon.png")!
|
||||
}
|
||||
|
||||
class func makeAltStoreApp(version: String, buildVersion: String?, in context: NSManagedObjectContext) -> StoreApp
|
||||
{
|
||||
let placeholderAppID = StoreApp.altstoreAppID
|
||||
let placeholderDownloadURL = URL(string: "https://sidestore.io")!
|
||||
let placeholderSourceID = Source.altStoreIdentifier
|
||||
|
||||
let app = StoreApp(context: context)
|
||||
app.name = "SideStore"
|
||||
app.bundleIdentifier = StoreApp.altstoreAppID
|
||||
app.bundleIdentifier = placeholderAppID
|
||||
app.developerName = "Side Team"
|
||||
app.localizedDescription = "SideStore is an alternative App Store."
|
||||
app.iconURL = URL(string: "https://user-images.githubusercontent.com/705880/63392210-540c5980-c37b-11e9-968c-8742fc68ab2e.png")!
|
||||
app.iconURL = Self.sideStoreAppIconURL
|
||||
app.screenshotURLs = []
|
||||
app.sourceIdentifier = Source.altStoreIdentifier
|
||||
app.sourceIdentifier = placeholderSourceID
|
||||
|
||||
let appVersion = AppVersion.makeAppVersion(version: version,
|
||||
buildVersion: buildVersion,
|
||||
date: Date(),
|
||||
downloadURL: URL(string: "http://rileytestut.com")!,
|
||||
downloadURL: placeholderDownloadURL,
|
||||
size: 0,
|
||||
appBundleID: app.bundleIdentifier,
|
||||
sourceID: Source.altStoreIdentifier,
|
||||
sourceID: app.sourceIdentifier,
|
||||
in: context)
|
||||
try? app.setVersions([appVersion])
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ public extension Team
|
||||
}
|
||||
|
||||
@objc(Team)
|
||||
public class Team: NSManagedObject, Fetchable
|
||||
public class Team: BaseEntity
|
||||
{
|
||||
/* Properties */
|
||||
@NSManaged public var name: String
|
||||
|
||||
Reference in New Issue
Block a user