From 8add1d0f4ad908cdb5abfbbc6fc728b9d2a016cf Mon Sep 17 00:00:00 2001 From: Riley Testut Date: Thu, 30 Nov 2023 14:33:08 -0600 Subject: [PATCH] Supports remotely disabling workaround for downloading Patreon attachments In case our workaround for downloading Patreon post attachments breaks, we can remotely disable it and force AltStore to use its fallback instead (taking user to post directly). --- AltStore/Operations/DownloadAppOperation.swift | 5 +++++ AltStore/Operations/FetchSourceOperation.swift | 5 +++++ AltStoreCore/Extensions/UserDefaults+AltStore.swift | 1 + AltStoreCore/Types/ALTSourceUserInfoKey.h | 1 + AltStoreCore/Types/ALTSourceUserInfoKey.m | 1 + 5 files changed, 13 insertions(+) diff --git a/AltStore/Operations/DownloadAppOperation.swift b/AltStore/Operations/DownloadAppOperation.swift index 38aa4228..d0d518a8 100644 --- a/AltStore/Operations/DownloadAppOperation.swift +++ b/AltStore/Operations/DownloadAppOperation.swift @@ -289,6 +289,11 @@ private extension DownloadAppOperation { func downloadPatreonApp(from patreonURL: URL) async throws -> URL { + guard !UserDefaults.shared.skipPatreonDownloads else { + // Skip all hacks, take user straight to Patreon post. + return try await downloadFromPatreonPost() + } + do { // User is pledged to this app, attempt to download. diff --git a/AltStore/Operations/FetchSourceOperation.swift b/AltStore/Operations/FetchSourceOperation.swift index c161f797..b47c6ffa 100644 --- a/AltStore/Operations/FetchSourceOperation.swift +++ b/AltStore/Operations/FetchSourceOperation.swift @@ -153,6 +153,11 @@ final class FetchSourceOperation: ResultOperation let identifier = source.identifier + if identifier == Source.altStoreIdentifier, let skipPatreonDownloads = source.userInfo?[.skipPatreonDownloads] + { + UserDefaults.shared.skipPatreonDownloads = (skipPatreonDownloads == "true") + } + try self.verify(source, response: response) try self.verifyPledges(for: source, in: childContext) diff --git a/AltStoreCore/Extensions/UserDefaults+AltStore.swift b/AltStoreCore/Extensions/UserDefaults+AltStore.swift index 0a4b1f7a..fcff08b0 100644 --- a/AltStoreCore/Extensions/UserDefaults+AltStore.swift +++ b/AltStoreCore/Extensions/UserDefaults+AltStore.swift @@ -51,6 +51,7 @@ public extension UserDefaults @NSManaged var trustedSourceIDs: [String]? @NSManaged var trustedServerURL: String? + @NSManaged var skipPatreonDownloads: Bool @nonobjc var activeAppsLimit: Int? { diff --git a/AltStoreCore/Types/ALTSourceUserInfoKey.h b/AltStoreCore/Types/ALTSourceUserInfoKey.h index f18a0365..5621334e 100644 --- a/AltStoreCore/Types/ALTSourceUserInfoKey.h +++ b/AltStoreCore/Types/ALTSourceUserInfoKey.h @@ -10,3 +10,4 @@ typedef NSString *ALTSourceUserInfoKey NS_TYPED_EXTENSIBLE_ENUM; extern ALTSourceUserInfoKey const ALTSourceUserInfoKeyPatreonAccessToken; +extern ALTSourceUserInfoKey const ALTSourceUserInfoKeySkipPatreonDownloads; diff --git a/AltStoreCore/Types/ALTSourceUserInfoKey.m b/AltStoreCore/Types/ALTSourceUserInfoKey.m index 4d715cdc..d326b71f 100644 --- a/AltStoreCore/Types/ALTSourceUserInfoKey.m +++ b/AltStoreCore/Types/ALTSourceUserInfoKey.m @@ -9,3 +9,4 @@ #import "ALTSourceUserInfoKey.h" ALTSourceUserInfoKey const ALTSourceUserInfoKeyPatreonAccessToken = @"patreonAccessToken"; +ALTSourceUserInfoKey const ALTSourceUserInfoKeySkipPatreonDownloads = @"skipPatreonDownloads";