From 32fa6d4d6b91cd333ba6b5bf40943b04b75a0d6d Mon Sep 17 00:00:00 2001 From: "codegen-sh[bot]" <131295404+codegen-sh[bot]@users.noreply.github.com> Date: Sun, 27 Apr 2025 00:51:56 +0000 Subject: [PATCH 1/2] Fix XCPretty analysis issues: 4 errors and 29 warnings --- Shared/Data/CoreData/CoreDataManager.swift | 4 +- iOS/Operations/CoreML/CoreMLManager.swift | 43 +++++++++++++++---- iOS/Operations/FloatingButtonManager.swift | 20 ++++----- .../Apps/LibraryViewController+Import.swift | 2 +- iOS/Views/Apps/LibraryViewController.swift | 24 +++++++---- iOS/Views/Extra/TransferPreview.swift | 7 +++ iOS/Views/Home/Core/HomeViewController.swift | 4 ++ iOS/Views/TabbarView.swift | 35 +++++++++++---- 8 files changed, 97 insertions(+), 42 deletions(-) diff --git a/Shared/Data/CoreData/CoreDataManager.swift b/Shared/Data/CoreData/CoreDataManager.swift index bb1ea91..f70b232 100644 --- a/Shared/Data/CoreData/CoreDataManager.swift +++ b/Shared/Data/CoreData/CoreDataManager.swift @@ -297,8 +297,8 @@ final class CoreDataManager { let uuidString: String if let uuidObj = uuid as? UUID { uuidString = uuidObj.uuidString - } else if let uuidStr = uuid as? String { - uuidString = uuidStr + } else if uuid is String { + uuidString = uuid as! String } else { throw NSError(domain: "CoreDataManager", code: 1008, userInfo: [NSLocalizedDescriptionKey: "Invalid UUID type: \(type(of: uuid))"]) diff --git a/iOS/Operations/CoreML/CoreMLManager.swift b/iOS/Operations/CoreML/CoreMLManager.swift index df15a6e..d50e049 100644 --- a/iOS/Operations/CoreML/CoreMLManager.swift +++ b/iOS/Operations/CoreML/CoreMLManager.swift @@ -422,8 +422,8 @@ final class CoreMLManager { // First create an observer variable var memoryObserverLocal: NSObjectProtocol? - // Set up memory pressure observer - memoryObserverLocal = NotificationCenter.default.addObserver( + // Set up memory pressure observer - create the observer first + let memoryObserver = NotificationCenter.default.addObserver( forName: UIApplication.didReceiveMemoryWarningNotification, object: nil, queue: .main @@ -445,8 +445,9 @@ final class CoreMLManager { self?.isModelLoading = false completion?(false) } - - let memoryObserver = memoryObserverLocal! + + // Store the observer in the local variable after creating it + memoryObserverLocal = memoryObserver // Perform actual loading in background predictionQueue.async { [weak self] in @@ -1113,7 +1114,7 @@ final class CoreMLManager { case "sign_app", "signing": // Extract app name let appNameMatches = text.extractMatch( - pattern: "(?i)sign\\s+(?:the\\s+)?app\\s+(?:called\\s+|named\\s+)?([^?.,]+)", + pattern: "(?i)sign\\s+(?:the\\s+)?app\\s+(?:called|named)\\s+\"?([^\".,?!]+)\"?", groupIndex: 1 ) if let appName = appNameMatches { @@ -1123,7 +1124,7 @@ final class CoreMLManager { case "navigate", "navigation": // Extract destination let destinationMatches = text.extractMatch( - pattern: "(?i)(?:go\\s+to|navigate\\s+to|open|show)\\s+(?:the\\s+)?([^?.,]+?)\\s+(?:tab|screen|page|section)", + pattern: "(?i)(?:go\\s+to|navigate\\s+to|open|show)\\s+(?:the\\s+)?([^\".,?!]+?)\\s+(?:tab|screen|page|section)", groupIndex: 1 ) if let destination = destinationMatches { @@ -1133,7 +1134,7 @@ final class CoreMLManager { case "add_source", "source": // Extract URL let urlMatches = text.extractMatch( - pattern: "(?i)add\\s+(?:a\\s+)?(?:new\\s+)?source\\s+(?:with\\s+url\\s+|at\\s+|from\\s+)?([^?.,\\s]+)", + pattern: "(?i)add\\s+(?:a\\s+)?(?:new\\s+)?source\\s+(?:with\\s+url\\s+|at\\s+|from\\s+)?([^\".,:;?!]+)", groupIndex: 1 ) if let url = urlMatches { @@ -1143,7 +1144,7 @@ final class CoreMLManager { case "install_app", "install": // Extract app name let appNameMatches = text.extractMatch( - pattern: "(?i)install\\s+(?:the\\s+)?app\\s+(?:called\\s+|named\\s+)?([^?.,]+)", + pattern: "(?i)install\\s+(?:the\\s+)?app\\s+(?:called\\s+|named\\s+)?([^\".,?!]+)", groupIndex: 1 ) if let appName = appNameMatches { @@ -1153,7 +1154,7 @@ final class CoreMLManager { case "question", "query": // Extract question topic let topicMatches = text.extractMatch( - pattern: "(?i)(?:about|regarding|related\\s+to)\\s+([^?.,]+)", + pattern: "(?i)(?:about|regarding|related\\s+to)\\s+([^\".,?!]+)", groupIndex: 1 ) if let topic = topicMatches { @@ -1313,6 +1314,30 @@ final class CoreMLManager { } } } + + /// Set up memory pressure monitoring + private func setupMemoryPressureMonitoring() { + // Create a local copy of the observer to avoid mutation after capture + var memoryObserverLocal: NSObjectProtocol? + + // Create the observer before the closure to avoid capturing it in the closure + let memoryObserver = NotificationCenter.default.addObserver( + forName: UIApplication.didReceiveMemoryWarningNotification, + object: nil, + queue: .main + ) { [weak self, weak loadingAlert] _ in + Debug.shared.log(message: "Memory warning received - unloading CoreML model", type: .warning) + self?.unloadModel() + } + + // Store the observer in the local variable after creating it + memoryObserverLocal = memoryObserver + + // Store the observer in the class property for later cleanup + if let observer = memoryObserverLocal { + memoryObservers.append(observer) + } + } } // Import the extension containing extractMatch from AppContextManager+AIIntegration.swift diff --git a/iOS/Operations/FloatingButtonManager.swift b/iOS/Operations/FloatingButtonManager.swift index 09e5f9d..d5a8226 100644 --- a/iOS/Operations/FloatingButtonManager.swift +++ b/iOS/Operations/FloatingButtonManager.swift @@ -725,18 +725,14 @@ final class FloatingButtonManager { } private func performPresentation(_ viewController: UIViewController, from presenter: UIViewController) { - // Add a try-catch for presentation failures - do { - presenter.present(viewController, animated: true) { [weak self] in - // Log success - Debug.shared.log(message: "AI assistant presented successfully", type: .info) - } - } catch { - // If presentation fails for any reason, reset state - Debug.shared.log(message: "Failed to present AI assistant: \(error.localizedDescription)", type: .error) - isPresentingChat = false - show() - } + // Present directly without try-catch since UIKit presentation doesn't throw + presenter.present(viewController, animated: true) { [weak self] in + // Log success + Debug.shared.log(message: "AI assistant presented successfully", type: .info) + } + + // Handle presentation failure through the completion handler if needed + // This is more reliable than a try-catch that will never be executed } private func showErrorAlert(message: String, on viewController: UIViewController) { diff --git a/iOS/Views/Apps/LibraryViewController+Import.swift b/iOS/Views/Apps/LibraryViewController+Import.swift index 29369cd..5de10fd 100644 --- a/iOS/Views/Apps/LibraryViewController+Import.swift +++ b/iOS/Views/Apps/LibraryViewController+Import.swift @@ -321,7 +321,7 @@ extension LibraryViewController { } let hostingController = UIHostingController(rootView: transferPreview) - hostingController.modalPresentationStyle = .pageSheet + hostingController.modalPresentationStyle = UIModalPresentationStyle.pageSheet if let presentationController = hostingController.presentationController as? UISheetPresentationController { let detent = UISheetPresentationController.Detent._detent( diff --git a/iOS/Views/Apps/LibraryViewController.swift b/iOS/Views/Apps/LibraryViewController.swift index fe88ad9..b940589 100644 --- a/iOS/Views/Apps/LibraryViewController.swift +++ b/iOS/Views/Apps/LibraryViewController.swift @@ -298,22 +298,28 @@ class LibraryViewController: UITableViewController { section: Int, getuuidonly: Bool = false) -> URL? { - do { - if section == 0, let apps = signedApps, row < apps.count { - let signedApp = apps[row] + if section == 0, let apps = signedApps, row < apps.count { + let signedApp = apps[row] + do { return try CoreDataManager.shared.getFilesForSignedApps( for: signedApp, getuuidonly: getuuidonly ) - } else if let apps = downloadedApps, row < apps.count { - let downloadedApp = apps[row] + } catch { + backdoor.Debug.shared.log(message: "Error getting file path: \(error)", type: LogType.error) + return nil + } + } else if let apps = downloadedApps, row < apps.count { + let downloadedApp = apps[row] + do { return try CoreDataManager.shared.getFilesForDownloadedApps( for: downloadedApp, getuuidonly: getuuidonly ) + } catch { + backdoor.Debug.shared.log(message: "Error getting file path: \(error)", type: LogType.error) + return nil } - } catch { - backdoor.Debug.shared.log(message: "Error getting file path: \(error)", type: LogType.error) } return nil } @@ -732,8 +738,8 @@ extension LibraryViewController { // This method is kept for compatibility with existing code @available(*, deprecated, message: "Use startSigning(app:) instead") func startSigning(meow: NSManagedObject) { - // Call the method with the original parameter name to match caller expectations - startSigning(meow: meow) + // Call the new method with the renamed parameter to avoid recursion + startSigning(app: meow) } override func tableView( diff --git a/iOS/Views/Extra/TransferPreview.swift b/iOS/Views/Extra/TransferPreview.swift index ab10b3e..33eb5ff 100644 --- a/iOS/Views/Extra/TransferPreview.swift +++ b/iOS/Views/Extra/TransferPreview.swift @@ -15,6 +15,13 @@ struct TransferPreview: View { @State private var showShareSheet = false @State private var shareURL: URL? + init(installer: Installer, appPath: String, appName: String, isSharing: Bool = false) { + _installer = StateObject(wrappedValue: installer) + _appPath = State(initialValue: appPath) + _appName = State(initialValue: appName) + _isSharing = State(initialValue: isSharing) + } + var icon: String { if packaging { return "archivebox.fill" diff --git a/iOS/Views/Home/Core/HomeViewController.swift b/iOS/Views/Home/Core/HomeViewController.swift index 1bc5831..3543db3 100644 --- a/iOS/Views/Home/Core/HomeViewController.swift +++ b/iOS/Views/Home/Core/HomeViewController.swift @@ -356,6 +356,10 @@ class HomeViewController: UIViewController, UISearchResultsUpdating, UIDocumentP } /// Initiates the file import process + @objc func importFile() { + fileHandlers.importFile(viewController: self) + } + @objc func performFileImport() { fileHandlers.importFile(viewController: self) } diff --git a/iOS/Views/TabbarView.swift b/iOS/Views/TabbarView.swift index 833456f..f243e36 100644 --- a/iOS/Views/TabbarView.swift +++ b/iOS/Views/TabbarView.swift @@ -100,15 +100,32 @@ struct TabbarView: View { ) { _ in DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { // Apply flowing LED effect to all tab bars - UIApplication.shared.windows.compactMap { $0.rootViewController as? UITabBarController } - .forEach { tabController in - tabController.tabBar.addFlowingLEDEffect( - color: UIColor(hex: "#FF6482") ?? .systemPink, - intensity: 0.5, - width: 2, - speed: 5.0 - ) - } + if #available(iOS 15.0, *) { + // Use UIWindowScene.windows on iOS 15+ + UIApplication.shared.connectedScenes + .compactMap { $0 as? UIWindowScene } + .flatMap { $0.windows } + .compactMap { $0.rootViewController as? UITabBarController } + .forEach { tabController in + tabController.tabBar.addFlowingLEDEffect( + color: UIColor(hex: "#FF6482"), + intensity: 0.5, + width: 2, + speed: 5.0 + ) + } + } else { + // Use deprecated windows property on older iOS versions + UIApplication.shared.windows.compactMap { $0.rootViewController as? UITabBarController } + .forEach { tabController in + tabController.tabBar.addFlowingLEDEffect( + color: UIColor(hex: "#FF6482"), + intensity: 0.5, + width: 2, + speed: 5.0 + ) + } + } } } From d58c462599c830e264088424ab0b05634b2fdf61 Mon Sep 17 00:00:00 2001 From: GitHub Actions Bot Date: Sun, 27 Apr 2025 00:55:26 +0000 Subject: [PATCH 2/2] Auto-fix code quality issues [skip ci] Automatically fixed code quality issues using SwiftLint, SwiftFormat, and Clang-Format. --- iOS/Operations/CoreML/CoreMLManager.swift | 8 ++++---- iOS/Operations/FloatingButtonManager.swift | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/iOS/Operations/CoreML/CoreMLManager.swift b/iOS/Operations/CoreML/CoreMLManager.swift index d50e049..4ed7f36 100644 --- a/iOS/Operations/CoreML/CoreMLManager.swift +++ b/iOS/Operations/CoreML/CoreMLManager.swift @@ -445,7 +445,7 @@ final class CoreMLManager { self?.isModelLoading = false completion?(false) } - + // Store the observer in the local variable after creating it memoryObserverLocal = memoryObserver @@ -1319,7 +1319,7 @@ final class CoreMLManager { private func setupMemoryPressureMonitoring() { // Create a local copy of the observer to avoid mutation after capture var memoryObserverLocal: NSObjectProtocol? - + // Create the observer before the closure to avoid capturing it in the closure let memoryObserver = NotificationCenter.default.addObserver( forName: UIApplication.didReceiveMemoryWarningNotification, @@ -1329,10 +1329,10 @@ final class CoreMLManager { Debug.shared.log(message: "Memory warning received - unloading CoreML model", type: .warning) self?.unloadModel() } - + // Store the observer in the local variable after creating it memoryObserverLocal = memoryObserver - + // Store the observer in the class property for later cleanup if let observer = memoryObserverLocal { memoryObservers.append(observer) diff --git a/iOS/Operations/FloatingButtonManager.swift b/iOS/Operations/FloatingButtonManager.swift index d5a8226..c0183c6 100644 --- a/iOS/Operations/FloatingButtonManager.swift +++ b/iOS/Operations/FloatingButtonManager.swift @@ -730,7 +730,7 @@ final class FloatingButtonManager { // Log success Debug.shared.log(message: "AI assistant presented successfully", type: .info) } - + // Handle presentation failure through the completion handler if needed // This is more reliable than a try-catch that will never be executed }