From 55f4aa7debe5c2f0d8765f53347ab7de8c617d7f Mon Sep 17 00:00:00 2001 From: Magesh K <47920326+mahee96@users.noreply.github.com> Date: Sun, 12 Jan 2025 18:01:11 +0530 Subject: [PATCH] [debug]: enabled back appropriate preprocessor debug blocks as before wherever applicable --- AltBackup/ViewController.swift | 2 +- AltStore/AppDelegate.swift | 6 +-- AltStore/My Apps/MyAppsViewController.swift | 24 +++++------ .../Operations/AuthenticationOperation.swift | 7 ++-- .../FetchProvisioningProfilesOperation.swift | 30 +++++++------- .../Operations/RemoveAppBackupOperation.swift | 1 + AltStore/Operations/ResignAppOperation.swift | 15 +++---- AltStore/Settings/PatreonViewController.swift | 9 +++-- .../Extensions/UserDefaults+AltStore.swift | 1 + AltStoreCore/Model/DatabaseManager.swift | 40 ++++++++++--------- 10 files changed, 72 insertions(+), 63 deletions(-) diff --git a/AltBackup/ViewController.swift b/AltBackup/ViewController.swift index eca547bb..c0cf2565 100644 --- a/AltBackup/ViewController.swift +++ b/AltBackup/ViewController.swift @@ -82,7 +82,7 @@ class ViewController: UIViewController self.activityIndicatorView.color = .altstoreText self.activityIndicatorView.startAnimating() - // TODO: @mahee96: Disabled this buttons which were present for debugging purpose. + // TODO: @mahee96: Disabled these backup/restore buttons in altbackup.app screen which were present for debugging purpose. // Can find something useful for these later, but these are not required by this backup/restore app // #if DEBUG // let button1 = UIButton(type: .system) diff --git a/AltStore/AppDelegate.swift b/AltStore/AppDelegate.swift index efd9f378..85010718 100644 --- a/AltStore/AppDelegate.swift +++ b/AltStore/AppDelegate.swift @@ -294,9 +294,9 @@ extension AppDelegate UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .sound]) { (success, error) in } -// #if DEBUG -// UIApplication.shared.registerForRemoteNotifications() -// #endif + #if DEBUG && targetEnvironment(simulator) + UIApplication.shared.registerForRemoteNotifications() + #endif } func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) diff --git a/AltStore/My Apps/MyAppsViewController.swift b/AltStore/My Apps/MyAppsViewController.swift index 4337979c..273f201c 100644 --- a/AltStore/My Apps/MyAppsViewController.swift +++ b/AltStore/My Apps/MyAppsViewController.swift @@ -1930,11 +1930,12 @@ extension MyAppsViewController var outError: NSError? = nil self.coordinator.coordinate(readingItemAt: backupDirectoryURL, options: [.withoutChanges], error: &outError) { (backupDirectoryURL) in -// #if DEBUG -// backupExists = true -// #else + + #if DEBUG && targetEnvironment(simulator) + backupExists = true + #else backupExists = FileManager.default.fileExists(atPath: backupDirectoryURL.path) -// #endif + #endif } if backupExists @@ -1965,13 +1966,12 @@ extension MyAppsViewController } -// #if DEBUG -// if installedApp.bundleIdentifier != StoreApp.altstoreAppID -// { -// actions.append(removeAction) -// } -// -// #else + #if DEBUG && targetEnvironment(simulator) + if installedApp.bundleIdentifier != StoreApp.altstoreAppID + { + actions.append(removeAction) + } + #else if (UserDefaults.standard.legacySideloadedApps ?? []).contains(installedApp.bundleIdentifier) { @@ -1985,7 +1985,7 @@ extension MyAppsViewController actions.append(removeAction) } -// #endif + #endif } // Change the order of entries to make changes to how the context menu is displayed diff --git a/AltStore/Operations/AuthenticationOperation.swift b/AltStore/Operations/AuthenticationOperation.swift index 57995c3c..3e8fa711 100644 --- a/AltStore/Operations/AuthenticationOperation.swift +++ b/AltStore/Operations/AuthenticationOperation.swift @@ -715,9 +715,10 @@ private extension AuthenticationOperation // If we're not using the same certificate used to install AltStore, warn user that they need to refresh. guard !provisioningProfile.certificates.contains(signer.certificate) else { return completionHandler(false) } -//#if DEBUG +// #if DEBUG && targetEnvironment(simulator) // completionHandler(false) -//#else +// #else + DispatchQueue.main.async { let context = AuthenticatedOperationContext(context: self.context) context.operations.removeAllObjects() // Prevent deadlock due to endless waiting on previous operations to finish. @@ -733,7 +734,7 @@ private extension AuthenticationOperation completionHandler(false) } } -//#endif +// #endif } } diff --git a/AltStore/Operations/FetchProvisioningProfilesOperation.swift b/AltStore/Operations/FetchProvisioningProfilesOperation.swift index 8e1cb112..d6f7ce01 100644 --- a/AltStore/Operations/FetchProvisioningProfilesOperation.swift +++ b/AltStore/Operations/FetchProvisioningProfilesOperation.swift @@ -134,19 +134,21 @@ extension FetchProvisioningProfilesOperation // or if installedApp.team is nil but resignedBundleIdentifier contains the team's identifier. let teamsMatch = installedApp.team?.identifier == team.identifier || (installedApp.team == nil && installedApp.resignedBundleIdentifier.contains(team.identifier)) -// #if DEBUG -// -// if app.isAltStoreApp -// { -// // Use legacy bundle ID format for AltStore. -// preferredBundleID = teamsMatch ? installedApp.resignedBundleIdentifier : nil -// } -// else -// { -// preferredBundleID = teamsMatch ? installedApp.resignedBundleIdentifier : nil -// } -// -// #else + // TODO: @mahee96: Try to keep the debug build and release build operations similar, refactor later with proper reasoning + // for now, restricted it to debug on simulator only + #if DEBUG && targetEnvironment(simulator) + + if app.isAltStoreApp + { + // Use legacy bundle ID format for AltStore. + preferredBundleID = teamsMatch ? installedApp.resignedBundleIdentifier : nil + } + else + { + preferredBundleID = teamsMatch ? installedApp.resignedBundleIdentifier : nil + } + + #else if teamsMatch { @@ -160,7 +162,7 @@ extension FetchProvisioningProfilesOperation preferredBundleID = nil } - // #endif + #endif } else { diff --git a/AltStore/Operations/RemoveAppBackupOperation.swift b/AltStore/Operations/RemoveAppBackupOperation.swift index c72320b1..113b130a 100644 --- a/AltStore/Operations/RemoveAppBackupOperation.swift +++ b/AltStore/Operations/RemoveAppBackupOperation.swift @@ -58,6 +58,7 @@ final class RemoveAppBackupOperation: ResultOperation } catch let error as CocoaError where error.code == CocoaError.Code.fileNoSuchFile { + // TODO: @mahee96: Find out why should in debug builds the app-groups is not expected to match // #if DEBUG // // // When debugging, it's expected that app groups don't match, so ignore. diff --git a/AltStore/Operations/ResignAppOperation.swift b/AltStore/Operations/ResignAppOperation.swift index 49c5f9b2..7f165297 100644 --- a/AltStore/Operations/ResignAppOperation.swift +++ b/AltStore/Operations/ResignAppOperation.swift @@ -244,13 +244,14 @@ private extension ResignAppOperation { for case let fileURL as URL in enumerator { -// #if DEBUG -// guard !fileURL.lastPathComponent.lowercased().contains(".xctest") else { -// // Remove embedded XCTest (+ dSYM) bundle from copied app bundle. -// try FileManager.default.removeItem(at: fileURL) -// continue -// } -// #endif + // for both sim and device, in debug mode builds, remove the tests bundles (if any) + #if DEBUG + guard !fileURL.lastPathComponent.lowercased().contains(".xctest") else { + // Remove embedded XCTest (+ dSYM) bundle from copied app bundle. + try FileManager.default.removeItem(at: fileURL) + continue + } + #endif guard let appExtension = Bundle(url: fileURL) else { throw ALTError(.missingAppBundle) } try prepare(appExtension) diff --git a/AltStore/Settings/PatreonViewController.swift b/AltStore/Settings/PatreonViewController.swift index 61b05616..dd945161 100644 --- a/AltStore/Settings/PatreonViewController.swift +++ b/AltStore/Settings/PatreonViewController.swift @@ -318,11 +318,12 @@ extension PatreonViewController case .none: footerView.button.isIndicatingActivity = true case .success?: footerView.button.isHidden = true case .failure?: -// #if DEBUG -// let debug = true -// #else + // In simulator debug builds only enable debug mode flag + #if DEBUG && targetEnvironment(simulator) + let debug = true + #else let debug = false -// #endif + #endif if self.patronsDataSource.itemCount == 0 || debug { diff --git a/AltStoreCore/Extensions/UserDefaults+AltStore.swift b/AltStoreCore/Extensions/UserDefaults+AltStore.swift index 021d4e7a..79011098 100644 --- a/AltStoreCore/Extensions/UserDefaults+AltStore.swift +++ b/AltStoreCore/Extensions/UserDefaults+AltStore.swift @@ -107,6 +107,7 @@ public extension UserDefaults (ProcessInfo.processInfo.isOperatingSystemAtLeast(ios14) && !ProcessInfo.processInfo.isOperatingSystemAtLeast(ios15_7_2)) || (ProcessInfo.processInfo.isOperatingSystemAtLeast(ios16) && !ProcessInfo.processInfo.isOperatingSystemAtLeast(ios16_2)) + // TODO: @mahee96: why should the permissions checking be any different, for now, it shouldn't so commented debug mode code // #if DEBUG // let permissionCheckingDisabled = true // #else diff --git a/AltStoreCore/Model/DatabaseManager.swift b/AltStoreCore/Model/DatabaseManager.swift index 6a2ec236..cdc89656 100644 --- a/AltStoreCore/Model/DatabaseManager.swift +++ b/AltStoreCore/Model/DatabaseManager.swift @@ -87,21 +87,22 @@ public extension DatabaseManager guard !self.isStarted else { return finish(nil) } -// #if DEBUG -// // Wrap in #if DEBUG to *ensure* we never accidentally delete production databases. -// if ProcessInfo.processInfo.isPreview -// { -// do -// { -// print("!!! Purging database for preview...") -// try FileManager.default.removeItem(at: PersistentContainer.defaultDirectoryURL()) -// } -// catch -// { -// print("Failed to remove database directory for preview.", error) -// } -// } -// #endif + // In simulator, when previews are generated, it initializes the db, in doing so this removal may be required + #if DEBUG && targetEnvironment(simulator) + // Wrap in #if DEBUG to *ensure* we never accidentally delete production databases. + if ProcessInfo.processInfo.isPreview + { + do + { + print("!!! Purging database for preview...") + try FileManager.default.removeItem(at: PersistentContainer.defaultDirectoryURL()) + } + catch + { + print("Failed to remove database directory for preview.", error) + } + } + #endif if self.persistentContainer.isMigrationRequired { @@ -354,11 +355,12 @@ private extension DatabaseManager let fileURL = installedApp.fileURL -// #if DEBUG -// let replaceCachedApp = true -// #else + // @mahee96: it shouldn't matter if it is debug/release, the file is expected to be in its place (except for simulator probably coz it doesn't suppor app installs anyway) + #if DEBUG && targetEnvironment(simulator) + let replaceCachedApp = true + #else let replaceCachedApp = !FileManager.default.fileExists(atPath: fileURL.path) || installedApp.version != localApp.version || installedApp.buildVersion != localApp.buildVersion -// #endif + #endif if replaceCachedApp {