merge AltStore 1.6.3, add dynamic anisette lists, merge SideJITServer integration

* Change error from Swift.Error to NSError

* Adds ResultOperation.localizedFailure

* Finish Riley's monster commit

3b38d725d7
May the Gods have mercy on my soul.

* Fix format strings I broke

* Include "Enable JIT" errors in Error Log

* Fix minimuxer status checking

* [skip ci] Update the no wifi message to include VPN

* Opens Error Log when tapping ToastView

* Fixes Error Log context menu covering cell content

* Fixes Error Log context menu appearing while scrolling

* Fixes incorrect Search FAQ URL

* Fix Error Log showing UIAlertController on iOS 14+

* Fix Error Log not showing UIAlertController on iOS <=13

* Fix wrong color in AuthenticationViewController

* Fix typo

* Fixes logging non-AltServerErrors as AltServerError.underlyingError

* Limits quitting other AltStore/SideStore processes to database migrations

* Skips logging cancelled errors

* Replaces StoreApp.latestVersion with latestSupportedVersion + latestAvailableVersion

We now store the latest supported version as a relationship on StoreApp, rather than the latest available version. This allows us to reference the latest supported version in predicates and sort descriptors.

However, we kept the underlying Core Data property name the same to avoid extra migration.

* Conforms OperatingSystemVersion to Comparable

* Parses AppVersion.minOSVersion/maxOSVersion from source JSON

* Supports non-NSManagedObjects for @Managed properties

This allows us to use @Managed with properties that may or may not be NSManagedObjects at runtime (e.g. protocols). If they are, Managed will keep strong reference to context like before.

* Supports optional @Managed properties

* Conforms AppVersion to AppProtocol

* Verifies min/max OS version before downloading app + asks user to download older app version if necessary

* Improves error message when file does not exist at AppVersion.downloadURL

* Removes unnecessary StoreApp convenience properties

* Removes unnecessary StoreApp convenience properties as well as fix other issues

* Remove Settings bundle, add SwiftUI view instead

Fix refresh all shortcut intent

* Update AuthenticationOperation.swift

Signed-off-by: June Park <rjp2030@outlook.com>

* Fix build issues given by develop

* Add availability check to fix CI build(?)

* If it's gonna be that way...

---------

Signed-off-by: June Park <rjp2030@outlook.com>
Co-authored-by: nythepegasus <nythepegasus84@gmail.com>
Co-authored-by: Riley Testut <riley@rileytestut.com>
Co-authored-by: ny <me@nythepegas.us>
This commit is contained in:
June Park
2024-08-06 10:43:52 +09:00
committed by GitHub
parent 83ece72ae1
commit 1713fccfc4
60 changed files with 2170 additions and 1067 deletions

View File

@@ -23,5 +23,6 @@ FOUNDATION_EXPORT const unsigned char AltStoreCoreVersionString[];
// Shared
#import <AltStoreCore/ALTConstants.h>
#import <AltStoreCore/ALTConnection.h>
#import <AltStoreCore/ALTWrappedError.h>
#import <AltStoreCore/NSError+ALTServerError.h>
#import <AltStoreCore/CFNotificationName+AltStore.h>

View File

@@ -0,0 +1,18 @@
//
// OperatingSystemVersion+Comparable.swift
// AltStoreCore
//
// Created by nythepegasus on 5/9/24.
//
import Foundation
extension OperatingSystemVersion: Comparable {
public static func ==(lhs: OperatingSystemVersion, rhs: OperatingSystemVersion) -> Bool {
return lhs.majorVersion == rhs.majorVersion && lhs.minorVersion == rhs.minorVersion && lhs.patchVersion == rhs.patchVersion
}
public static func <(lhs: OperatingSystemVersion, rhs: OperatingSystemVersion) -> Bool {
return lhs.stringValue.compare(rhs.stringValue, options: .numeric) == .orderedAscending
}
}

View File

@@ -0,0 +1,14 @@
//
// String+SideStore.swift
// AltStoreCore
//
// Created by nythepegasus on 5/9/24.
//
import Foundation
public extension String {
init(formatted: String, comment: String? = nil, _ args: String...) {
self.init(format: NSLocalizedString(formatted, comment: comment ?? ""), args)
}
}

View File

@@ -26,6 +26,8 @@ public extension UserDefaults
@NSManaged var textInputSideJITServerurl: String?
@NSManaged var textInputAnisetteURL: String?
@NSManaged var customAnisetteURL: String?
@NSManaged var menuAnisetteURL: String
@NSManaged var menuAnisetteList: String
@NSManaged var preferredServerID: String?
@NSManaged var isBackgroundRefreshEnabled: Bool
@@ -81,8 +83,9 @@ public extension UserDefaults
#keyPath(UserDefaults.isLegacyDeactivationSupported): isLegacyDeactivationSupported,
#keyPath(UserDefaults.activeAppLimitIncludesExtensions): activeAppLimitIncludesExtensions,
#keyPath(UserDefaults.localServerSupportsRefreshing): localServerSupportsRefreshing,
#keyPath(UserDefaults.requiresAppGroupMigration): true
]
#keyPath(UserDefaults.requiresAppGroupMigration): true,
#keyPath(UserDefaults.menuAnisetteURL): "https://ani.sidestore.io"
] as [String : Any]
UserDefaults.standard.register(defaults: defaults)
UserDefaults.shared.register(defaults: defaults)

View File

@@ -40,7 +40,7 @@ public class AppVersion: NSManagedObject, Decodable, Fetchable
/* Relationships */
@NSManaged public private(set) var app: StoreApp?
@NSManaged public private(set) var latestVersionApp: StoreApp?
@NSManaged @objc(latestVersionApp) public internal(set) var latestSupportedVersionApp: StoreApp?
private override init(entity: NSEntityDescription, insertInto context: NSManagedObjectContext?)
{
@@ -54,6 +54,8 @@ public class AppVersion: NSManagedObject, Decodable, Fetchable
case localizedDescription
case downloadURL
case size
case minOSVersion
case maxOSVersion
}
public required init(from decoder: Decoder) throws
@@ -72,6 +74,9 @@ public class AppVersion: NSManagedObject, Decodable, Fetchable
self.downloadURL = try container.decode(URL.self, forKey: .downloadURL)
self.size = try container.decode(Int64.self, forKey: .size)
self._minOSVersion = try container.decodeIfPresent(String.self, forKey: .minOSVersion)
self._maxOSVersion = try container.decodeIfPresent(String.self, forKey: .maxOSVersion)
}
catch
{
@@ -113,4 +118,13 @@ public extension AppVersion
return appVersion
}
var isSupported: Bool {
if let minOSVersion = self.minOSVersion, !ProcessInfo.processInfo.isOperatingSystemAtLeast(minOSVersion) {
return false
} else if let maxOSVersion = self.maxOSVersion, ProcessInfo.processInfo.operatingSystemVersion > maxOSVersion {
return false
}
return true
}
}

View File

@@ -13,11 +13,11 @@ import Roxas
extension CFNotificationName
{
fileprivate static let willAccessDatabase = CFNotificationName("com.rileytestut.AltStore.WillAccessDatabase" as CFString)
fileprivate static let willMigrateDatabase = CFNotificationName("com.rileytestut.AltStore.WillMigrateDatabase" as CFString)
}
private let ReceivedWillAccessDatabaseNotification: @convention(c) (CFNotificationCenter?, UnsafeMutableRawPointer?, CFNotificationName?, UnsafeRawPointer?, CFDictionary?) -> Void = { (center, observer, name, object, userInfo) in
DatabaseManager.shared.receivedWillAccessDatabaseNotification()
private let ReceivedWillMigrateDatabaseNotification: @convention(c) (CFNotificationCenter?, UnsafeMutableRawPointer?, CFNotificationName?, UnsafeRawPointer?, CFDictionary?) -> Void = { (center, observer, name, object, userInfo) in
DatabaseManager.shared.receivedWillMigrateDatabaseNotification()
}
fileprivate class PersistentContainer: RSTPersistentContainer
@@ -52,15 +52,15 @@ public class DatabaseManager
private let coordinator = NSFileCoordinator()
private let coordinatorQueue = OperationQueue()
private var ignoreWillAccessDatabaseNotification = false
private var ignoreWillMigrateDatabaseNotification = false
private init()
{
self.persistentContainer = PersistentContainer(name: "AltStore", bundle: Bundle(for: DatabaseManager.self))
self.persistentContainer.preferredMergePolicy = MergePolicy()
let observer = Unmanaged.passUnretained(self).toOpaque()
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), observer, ReceivedWillAccessDatabaseNotification, CFNotificationName.willAccessDatabase.rawValue, nil, .deliverImmediately)
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), observer, ReceivedWillMigrateDatabaseNotification, CFNotificationName.willMigrateDatabase.rawValue, nil, .deliverImmediately)
}
}
@@ -87,10 +87,13 @@ public extension DatabaseManager
guard !self.isStarted else { return finish(nil) }
// Quit any other running AltStore processes to prevent concurrent database access during and after migration.
self.ignoreWillAccessDatabaseNotification = true
CFNotificationCenterPostNotification(CFNotificationCenterGetDarwinNotifyCenter(), .willAccessDatabase, nil, nil, true)
if self.persistentContainer.isMigrationRequired {
// Quit any other running AltStore processes to prevent concurrent database access during and after migration.
self.ignoreWillMigrateDatabaseNotification = true
CFNotificationCenterPostNotification(CFNotificationCenterGetDarwinNotifyCenter(), .willMigrateDatabase, nil, nil, true)
}
self.migrateDatabaseToAppGroupIfNeeded { (result) in
switch result
{
@@ -229,7 +232,7 @@ private extension DatabaseManager
else
{
storeApp = StoreApp.makeAltStoreApp(in: context)
storeApp.latestVersion?.version = localApp.version
storeApp.latestSupportedVersion?.version = localApp.version
storeApp.source = altStoreSource
}
@@ -417,13 +420,13 @@ private extension DatabaseManager
}
}
func receivedWillAccessDatabaseNotification()
func receivedWillMigrateDatabaseNotification()
{
defer { self.ignoreWillAccessDatabaseNotification = false }
defer { self.ignoreWillMigrateDatabaseNotification = false }
// Ignore notifications sent by the current process.
guard !self.ignoreWillAccessDatabaseNotification else { return }
guard !self.ignoreWillMigrateDatabaseNotification else { return }
exit(104)
}
}

View File

@@ -62,14 +62,14 @@ public class InstalledApp: NSManagedObject, InstalledAppProtocol
@objc public var hasUpdate: Bool {
if self.storeApp == nil { return false }
if self.storeApp!.latestVersion == nil { return false }
if self.storeApp!.latestSupportedVersion == nil { return false }
let currentVersion = SemanticVersion(self.version)
let latestVersion = SemanticVersion(self.storeApp!.latestVersion!.version)
let latestVersion = SemanticVersion(self.storeApp!.latestSupportedVersion!.version)
if currentVersion == nil || latestVersion == nil {
// One of the versions is not valid SemVer, fall back to comparing the version strings by character
return self.version < self.storeApp!.latestVersion!.version
return self.version < self.storeApp!.latestSupportedVersion!.version
}
return currentVersion! < latestVersion!
@@ -163,8 +163,8 @@ public extension InstalledApp
class func updatesFetchRequest() -> NSFetchRequest<InstalledApp>
{
let fetchRequest = InstalledApp.fetchRequest() as NSFetchRequest<InstalledApp>
fetchRequest.predicate = NSPredicate(format: "%K == YES AND %K == YES",
#keyPath(InstalledApp.isActive), #keyPath(InstalledApp.hasUpdate))
fetchRequest.predicate = NSPredicate(format: "%K == YES AND %K != nil AND %K != %K",
#keyPath(InstalledApp.isActive), #keyPath(InstalledApp.storeApp), #keyPath(InstalledApp.version), #keyPath(InstalledApp.storeApp.latestSupportedVersion.version))
return fetchRequest
}
@@ -275,14 +275,12 @@ public extension InstalledApp
do { try FileManager.default.createDirectory(at: appsDirectoryURL, withIntermediateDirectories: true, attributes: nil) }
catch { print("Creating App Directory Error: \(error)") }
print("`appsDirectoryURL` is set to: \(appsDirectoryURL.absoluteString)")
return appsDirectoryURL
}
class var legacyAppsDirectoryURL: URL {
let baseDirectory = FileManager.default.applicationSupportDirectory
let appsDirectoryURL = baseDirectory.appendingPathComponent("Apps")
print("legacy `appsDirectoryURL` is set to: \(appsDirectoryURL.absoluteString)")
return appsDirectoryURL
}

View File

@@ -19,6 +19,8 @@ extension LoggedError
case deactivate
case backup
case restore
case connection
case enableJIT
}
}
@@ -66,7 +68,12 @@ public class LoggedError: NSManagedObject, Fetchable
self.date = date
self._operation = operation?.rawValue
let nsError = error as NSError
let nsError: NSError
if let error = error as? ALTServerError, error.code == .underlyingError, let underlyingError = error.underlyingError {
nsError = underlyingError as NSError
} else {
nsError = error as NSError
}
self.domain = nsError.domain
self.code = Int32(nsError.code)
self.userInfo = nsError.userInfo
@@ -91,7 +98,7 @@ public extension LoggedError
return app
}
var error: Error {
var error: NSError {
let nsError = NSError(domain: self.domain, code: Int(self.code), userInfo: self.userInfo)
return nsError
}
@@ -113,6 +120,8 @@ public extension LoggedError
case .deactivate: return String(format: NSLocalizedString("Deactivate %@ Failed", comment: ""), self.appName)
case .backup: return String(format: NSLocalizedString("Backup %@ Failed", comment: ""), self.appName)
case .restore: return String(format: NSLocalizedString("Restore %@ Failed", comment: ""), self.appName)
case .connection: return String(format: NSLocalizedString("Connection during %@ Failed", comment: ""), self.appName)
case .enableJIT: return String(format: NSLocalizedString("Enabling JIT for %@ Failed", comment: ""), self.appName)
}
}
}

View File

@@ -44,7 +44,7 @@ open class MergePolicy: RSTRelationshipPreservingMergePolicy
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.latestVersionApp?.latestVersion == $0 }),
if let primaryAppVersion = conflictingAppVersions.first(where: { $0.latestSupportedVersionApp?.latestSupportedVersion == $0 }),
let secondaryAppVersion = conflictingAppVersions.first(where: { $0 != primaryAppVersion })
{
secondaryAppVersion.managedObjectContext?.delete(secondaryAppVersion)

View File

@@ -48,7 +48,7 @@ fileprivate extension NSManagedObject
func setStoreAppLatestVersion(_ appVersion: NSManagedObject)
{
self.setValue(appVersion, forKey: #keyPath(StoreApp.latestVersion))
self.setValue(appVersion, forKey: #keyPath(StoreApp.latestSupportedVersion))
let versions = NSOrderedSet(array: [appVersion])
self.setValue(versions, forKey: #keyPath(StoreApp._versions))

View File

@@ -146,7 +146,7 @@ public class StoreApp: NSManagedObject, Decodable, Fetchable
@NSManaged @objc(source) public var _source: Source?
@NSManaged @objc(permissions) public var _permissions: NSOrderedSet
@NSManaged public private(set) var latestVersion: AppVersion?
@NSManaged @objc(latestVersion) public private(set) var latestSupportedVersion: AppVersion?
@NSManaged @objc(versions) public private(set) var _versions: NSOrderedSet
@NSManaged public private(set) var loggedErrors: NSSet /* Set<LoggedError> */ // Use NSSet to avoid eagerly fetching values.
@@ -169,31 +169,6 @@ public class StoreApp: NSManagedObject, Decodable, Fetchable
return self._versions.array as! [AppVersion]
}
@nonobjc public var size: Int64? {
guard let version = self.latestVersion else { return nil }
return version.size
}
@nonobjc public var version: String? {
guard let version = self.latestVersion else { return nil }
return version.version
}
@nonobjc public var versionDescription: String? {
guard let version = self.latestVersion else { return nil }
return version.localizedDescription
}
@nonobjc public var versionDate: Date? {
guard let version = self.latestVersion else { return nil }
return version.date
}
@nonobjc public var downloadURL: URL? {
guard let version = self.latestVersion else { return nil }
return version.downloadURL
}
private override init(entity: NSEntityDescription, insertInto context: NSManagedObjectContext?)
{
super.init(entity: entity, insertInto: context)
@@ -314,16 +289,30 @@ public class StoreApp: NSManagedObject, Decodable, Fetchable
}
}
private extension StoreApp
internal extension StoreApp
{
func setVersions(_ versions: [AppVersion])
{
guard let latestVersion = versions.first else { preconditionFailure("StoreApp must have at least one AppVersion.") }
self.latestVersion = latestVersion
self._versions = NSOrderedSet(array: versions)
let latestSupportedVersion = versions.first(where: { $0.isSupported })
self.latestSupportedVersion = latestSupportedVersion
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
}
}
// Preserve backwards compatibility by assigning legacy property values.
guard let latestVersion = versions.first else { preconditionFailure("StoreApp must have at least one AppVersion.") }
self._version = latestVersion.version
self._versionDate = latestVersion.date
self._versionDescription = latestVersion.localizedDescription
@@ -334,6 +323,10 @@ private extension StoreApp
public extension StoreApp
{
var latestAvailableVersion: AppVersion? {
return self._versions.firstObject as? AppVersion
}
@nonobjc class func fetchRequest() -> NSFetchRequest<StoreApp>
{
return NSFetchRequest<StoreApp>(entityName: "StoreApp")

View File

@@ -40,7 +40,7 @@ extension ALTApplication: AppProtocol
extension StoreApp: AppProtocol
{
public var url: URL? {
return self.downloadURL
return self.latestAvailableVersion?.downloadURL
}
}
@@ -50,3 +50,17 @@ extension InstalledApp: AppProtocol
return self.fileURL
}
}
extension AppVersion: AppProtocol {
public var name: String {
return self.app?.name ?? self.bundleIdentifier
}
public var bundleIdentifier: String {
return self.appBundleID
}
public var url: URL? {
return self.downloadURL
}
}