Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 40 additions & 43 deletions iOS/Delegates/AppDelegate+PhasedInitialization.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,53 +87,50 @@ extension AppDelegate {
func initializeComponentsWithCrashProtection() {
Debug.shared.log(message: "Initializing components with crash protection", type: .info)

// Use try-catch blocks to prevent crashes during initialization
do {
// Phase 1 - safe to run immediately
setupPhaseOne()
// Use structured error handling to prevent crashes during initialization
// Phase 1 - safe to run immediately
setupPhaseOne()

// Phase 2 - defer slightly
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) { [weak self] in
guard let self = self else { return }

// Phase 2 - defer slightly
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) { [weak self] in
guard let self = self else { return }

// Use try-catch to prevent crashes in Phase 2
do {
self.setupPhaseTwo()
} catch {
Debug.shared.log(message: "Error in Phase 2 initialization: \(error.localizedDescription)", type: .error)
}
}
// Execute Phase 2 setup
self.setupPhaseTwo()
}

// Phase 3 - defer significantly and only if memory allows
DispatchQueue.main.asyncAfter(deadline: .now() + 3.0) { [weak self] in
guard let self = self else { return }

// Phase 3 - defer significantly and only if memory allows
DispatchQueue.main.asyncAfter(deadline: .now() + 3.0) { [weak self] in
guard let self = self else { return }

// Check memory before heavy operations
if self.shouldProceedWithMemoryCheck() {
// Use try-catch to prevent crashes in Phase 3
do {
self.setupPhaseThree()
} catch {
Debug.shared.log(message: "Error in Phase 3 initialization: \(error.localizedDescription)", type: .error)
// Check memory before heavy operations
if self.shouldProceedWithMemoryCheck() {
// Execute Phase 3 setup
self.setupPhaseThree()
} else {
Debug.shared.log(message: "Skipping Phase 3 due to high memory usage", type: .warning)
}
}

// Post initialization complete notification after all phases
DispatchQueue.main.asyncAfter(deadline: .now() + 4.0) {
NotificationCenter.default.post(name: .appInitializationCompleted, object: nil)
Debug.shared.log(message: "App initialization complete", type: .success)
}

// Ensure UI is responsive regardless of initialization state
DispatchQueue.main.async {
// Use UIWindowScene.windows on iOS 15+ instead of deprecated UIApplication.shared.windows
if #available(iOS 15.0, *) {
if let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
let rootVC = windowScene.windows.first?.rootViewController {
rootVC.view.isUserInteractionEnabled = true
}
} else {
Debug.shared.log(message: "Skipping Phase 3 due to high memory usage", type: .warning)
}
}

// Post initialization complete notification after all phases
DispatchQueue.main.asyncAfter(deadline: .now() + 4.0) {
NotificationCenter.default.post(name: .appInitializationCompleted, object: nil)
Debug.shared.log(message: "App initialization complete", type: .success)
}
} catch {
// Log error but continue app launch with minimal functionality
Debug.shared.log(message: "Critical error during initialization: \(error.localizedDescription)", type: .error)

// Ensure UI is still responsive even if initialization fails
DispatchQueue.main.async {
if let rootVC = UIApplication.shared.windows.first?.rootViewController {
rootVC.view.isUserInteractionEnabled = true
// Fallback for older iOS versions
if let rootVC = UIApplication.shared.windows.first?.rootViewController {
rootVC.view.isUserInteractionEnabled = true
}
}
}
}
Expand Down
21 changes: 21 additions & 0 deletions iOS/Extensions/CALayer+Shadow.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import UIKit

extension CALayer {
/// Apply a blue tinted shadow effect to the layer
func applyBlueTintedShadow() {
masksToBounds = false
shadowColor = UIColor.systemBlue.cgColor
shadowOffset = CGSize(width: 0, height: 4)
shadowOpacity = 0.2
shadowRadius = 8
}

/// Apply a futuristic shadow effect to the layer
func applyFuturisticShadow() {
masksToBounds = false
shadowColor = UIColor(red: 0.1, green: 0.6, blue: 1.0, alpha: 1.0).cgColor
shadowOffset = CGSize(width: 0, height: 3)
shadowOpacity = 0.3
shadowRadius = 10
}
}
14 changes: 14 additions & 0 deletions iOS/Extensions/UITabBar+LED.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import UIKit

extension UITabBar {
/// Add LED effect to the tab bar with simplified parameters
@objc func addTabBarLEDEffect(color: UIColor) {
// Call the full implementation with default values
addFlowingLEDEffect(
color: color,
intensity: 0.3,
width: 2,
speed: 5.0
)
}
}
2 changes: 1 addition & 1 deletion iOS/Extensions/UIView+LED.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ extension UIView {
/// - intensity: Glow intensity (0.0-1.0, default: 0.8)
/// - width: Width of the flowing LED effect (default: 5)
/// - speed: Animation speed - lower is faster (default: 2.0)
func addFlowingLEDEffect(
@objc func addFlowingLEDEffect(
color: UIColor,
intensity: CGFloat = 0.8,
width: CGFloat = 5,
Expand Down
6 changes: 1 addition & 5 deletions iOS/Extensions/UIView+UIHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,7 @@ extension UIView {

/// Apply futuristic shadow effect to the view
func applyFuturisticShadow() {
layer.masksToBounds = false
layer.shadowColor = UIColor.systemBlue.cgColor
layer.shadowOffset = CGSize(width: 0, height: 4)
layer.shadowOpacity = 0.2
layer.shadowRadius = 8
layer.applyBlueTintedShadow()
}
}

Expand Down
8 changes: 6 additions & 2 deletions iOS/Operations/CoreML/CoreMLManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,9 @@ final class CoreMLManager {
let model = try MLModel(contentsOf: compiledModelURL)

// Remove observer as loading succeeded
NotificationCenter.default.removeObserver(memoryObserver)
if let observer = memoryObserver {
NotificationCenter.default.removeObserver(observer as Any)
}

// Dismiss loading alert
DispatchQueue.main.async {
Expand All @@ -497,7 +499,9 @@ final class CoreMLManager {
}
} catch {
// Remove observer on failure
NotificationCenter.default.removeObserver(memoryObserver)
if let observer = memoryObserver {
NotificationCenter.default.removeObserver(observer as Any)
}

// Dismiss loading alert
DispatchQueue.main.async {
Expand Down
56 changes: 21 additions & 35 deletions iOS/Views/TabbarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -249,41 +249,27 @@ struct TabbarView: View {
// Set up LED effects after a delay to ensure tab bar is ready
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
// Apply flowing LED effect to all tab bars - safely
do {
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
// Check if the method exists before calling it
if tabController.tabBar.responds(to: #selector(UITabBar.addFlowingLEDEffect)) {
tabController.tabBar.addFlowingLEDEffect(
color: UIColor(hex: "#FF6482"),
intensity: 0.3, // Reduced intensity
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
// Check if the method exists before calling it
if tabController.tabBar.responds(to: #selector(UITabBar.addFlowingLEDEffect)) {
tabController.tabBar.addFlowingLEDEffect(
color: UIColor(hex: "#FF6482"),
intensity: 0.3, // Reduced intensity
width: 2,
speed: 5.0
)
}
}
}
} catch {
Debug.shared.log(message: "Error applying LED effect: \(error.localizedDescription)", type: .error)
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
// Use the method directly since it's defined in our extension
tabController.tabBar.addTabBarLEDEffect(
color: UIColor(hex: "#FF6482")
)
}
} else {
// Use deprecated windows property on older iOS versions
UIApplication.shared.windows.compactMap { $0.rootViewController as? UITabBarController }
.forEach { tabController in
// Use the method directly since it's defined in our extension
tabController.tabBar.addTabBarLEDEffect(
color: UIColor(hex: "#FF6482")
)
}
}
}
}
Expand Down
Loading