From 7ac485def0922144bf5876e3a54f006fa2b75e90 Mon Sep 17 00:00:00 2001 From: Magesh K <47920326+mahee96@users.noreply.github.com> Date: Fri, 13 Dec 2024 13:59:18 +0530 Subject: [PATCH] [cleanup]: remove unused code and renamed AltStore to SideStore in sources section --- AltStore/Operations/Errors/SourceError.swift | 10 +-- .../UpdateKnownSourcesOperation.swift | 4 ++ AltStore/Sources/SourcesViewController.swift | 65 ++----------------- 3 files changed, 16 insertions(+), 63 deletions(-) diff --git a/AltStore/Operations/Errors/SourceError.swift b/AltStore/Operations/Errors/SourceError.swift index 9851c73c..edf5fad3 100644 --- a/AltStore/Operations/Errors/SourceError.swift +++ b/AltStore/Operations/Errors/SourceError.swift @@ -81,7 +81,7 @@ struct SourceError: ALTLocalizedError var errorFailureReason: String { switch self.code { - case .unsupported: return String(format: NSLocalizedString("The source “%@” is not supported by this version of AltStore.", comment: ""), self.$source.name) + case .unsupported: return String(format: NSLocalizedString("The source “%@” is not supported by this version of SideStore.", comment: ""), self.$source.name) case .duplicateBundleID: let bundleIDFragment = self.bundleID.map { String(format: NSLocalizedString("the bundle identifier %@", comment: ""), $0) } ?? NSLocalizedString("the same bundle identifier", comment: "") let failureReason = String(format: NSLocalizedString("The source “%@” contains multiple apps with %@.", comment: ""), self.$source.name, bundleIDFragment) @@ -108,7 +108,7 @@ struct SourceError: ALTLocalizedError return failureReason case .blocked: - let failureReason = String(format: NSLocalizedString("The source “%@” has been blocked by AltStore for security reasons.", comment: ""), self.$source.name) + let failureReason = String(format: NSLocalizedString("The source “%@” has been blocked by SideStore for security reasons.", comment: ""), self.$source.name) return failureReason case .changedID: @@ -141,11 +141,11 @@ struct SourceError: ALTLocalizedError return failureReason case .marketplaceNotSupported: - let failureReason = String(format: NSLocalizedString("The source “%@” contains notarized apps, which are not supported by this version of AltStore.", comment: ""), self.$source.name) + let failureReason = String(format: NSLocalizedString("The source “%@” contains notarized apps, which are not supported by this version of SideStore.", comment: ""), self.$source.name) return failureReason case .marketplaceRequired: - let failureReason = String(format: NSLocalizedString("One or more apps in source “%@” are missing a marketplaceID. This most likely means they are not notarized, which is not supported by this version of AltStore.", comment: ""), self.$source.name) + let failureReason = String(format: NSLocalizedString("One or more apps in source “%@” are missing a marketplaceID. This most likely means they are not notarized, which is not supported by this version of SideStore.", comment: ""), self.$source.name) return failureReason } } @@ -186,7 +186,7 @@ struct SourceError: ALTLocalizedError return recoverySuggestion case .marketplaceRequired: - let failureReason = String(format: NSLocalizedString("AltStore can only install marketplace apps that have been notarized by Apple.", comment: ""), self.$source.name) + let failureReason = String(format: NSLocalizedString("SideStore can only install marketplace apps that have been notarized by Apple.", comment: ""), self.$source.name) return failureReason default: return nil diff --git a/AltStore/Operations/UpdateKnownSourcesOperation.swift b/AltStore/Operations/UpdateKnownSourcesOperation.swift index 2302066b..96d99eb1 100644 --- a/AltStore/Operations/UpdateKnownSourcesOperation.swift +++ b/AltStore/Operations/UpdateKnownSourcesOperation.swift @@ -74,6 +74,10 @@ class UpdateKnownSourcesOperation: ResultOperation<([KnownSource], [KnownSource] UserDefaults.shared.recommendedSources = sources.trusted UserDefaults.shared.blockedSources = sources.blocked + // Cache trusted source IDs. + UserDefaults.shared.trustedSourceIDs = sources.trusted.map { $0.identifier } + + self.finish(.success(sources)) } catch diff --git a/AltStore/Sources/SourcesViewController.swift b/AltStore/Sources/SourcesViewController.swift index c621062a..af4bdb67 100644 --- a/AltStore/Sources/SourcesViewController.swift +++ b/AltStore/Sources/SourcesViewController.swift @@ -13,27 +13,6 @@ import AltStoreCore import Roxas import Nuke -//struct SourceError: ALTLocalizedError -//{ -// enum Code: Int, ALTErrorCode -// { -// typealias Error = SourceError -// case unsupported -// } -// -// var code: Code -// var errorTitle: String? -// var errorFailure: String? -// @Managed var source: Source -// -// var errorFailureReason: String { -// switch self.code -// { -// case .unsupported: return String(format: NSLocalizedString("The source “%@” is not supported by this version of SideStore.", comment: ""), self.$source.name) -// } -// } -//} - @objc(SourcesFooterView) private final class SourcesFooterView: TextCollectionReusableView { @@ -43,8 +22,8 @@ private final class SourcesFooterView: TextCollectionReusableView private extension UIAction.Identifier { - static let showDetails = UIAction.Identifier("io.altstore.showDetails") - static let showError = UIAction.Identifier("io.altstore.showError") + static let showDetails = UIAction.Identifier("io.sidestore.showDetails") + static let showError = UIAction.Identifier("io.sidestore.showError") } final class SourcesViewController: UICollectionViewController @@ -364,7 +343,7 @@ private extension SourcesViewController case .failure(OperationError.cancelled): break case .failure(var error as SourceError): - let title = String(format: NSLocalizedString("“%@” could not be added to AltStore.", comment: ""), error.$source.name) + let title = String(format: NSLocalizedString("“%@” could not be added to SideStore.", comment: ""), error.$source.name) error.errorTitle = title self.present(error) @@ -382,6 +361,10 @@ private extension SourcesViewController // Use @Managed before calling perform() to keep // strong reference to source.managedObjectContext. @Managed var source = try result.get() + + #if !BETA + guard let trustedSourceIDs = UserDefaults.shared.trustedSourceIDs, trustedSourceIDs.contains(source.identifier) else { throw SourceError(code: .unsupported, source: source) } + #endif DispatchQueue.main.async { self.showSourceDetails(for: source) @@ -432,40 +415,6 @@ private extension SourcesViewController catch { completionHandler?(false) - -// let dispatchGroup = DispatchGroup() -// -// var sourcesByURL = [URL: Source]() -// var fetchError: Error? -// -// for sourceURL in featuredSourceURLs -// { -// dispatchGroup.enter() -// -// AppManager.shared.fetchSource(sourceURL: sourceURL, managedObjectContext: context) { result in -// // Serialize access to sourcesByURL. -// context.performAndWait { -// switch result -// { -// case .failure(let error): fetchError = error -// case .success(let source): sourcesByURL[source.sourceURL] = source -// } -// -// dispatchGroup.leave() -// } -// } -// } -// -// dispatchGroup.notify(queue: .main) { -// if let error = fetchError -// { -// print(error) -// // 1 error doesn't mean all trusted sources failed to load! Riley, why did you do this??????? -//// finish(.failure(error)) -// } -// let sources = featuredSourceURLs.compactMap { sourcesByURL[$0] } -// finish(.success(sources)) -// } self.present(error) } }