1→// 2→// KortexOSApp.swift 3→// KortexOS 4→// 5→// Sistema operacional pessoal baseado na metodologia ZAIROS 6→// Clareza. Disciplina. Sistema. Organização. Ordem. 7→// 8→// Created with Claude Code 9→// 10→ 11→import SwiftUI 12→import CloudKit 13→import UserNotifications 14→ 15→@main 16→struct KortexOSApp: App { 17→ @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate 18→ @StateObject private var authManager = AuthenticationManager.shared 19→ @StateObject private var cloudKitManager = CloudKitManager.shared 20→ @StateObject private var notificationService = NotificationService.shared 21→ @AppStorage("KortexOS_HasCompletedOnboarding") private var hasCompletedOnboarding = false 22→ @Environment(\.scenePhase) private var scenePhase 23→ 24→ var body: some Scene { 25→ WindowGroup { 26→ Group { 27→ if !authManager.isAuthenticated { 28→ LoginView(authManager: authManager) 29→ } else if !hasCompletedOnboarding { 30→ OnboardingView(hasCompletedOnboarding: $hasCompletedOnboarding) 31→ } else { 32→ ContentView() 33→ .environmentObject(authManager) 34→ .environmentObject(cloudKitManager) 35→ } 36→ } 37→ .animation(.easeInOut(duration: 0.3), value: authManager.isAuthenticated) 38→ .animation(.easeInOut(duration: 0.3), value: hasCompletedOnboarding) 39→ .task { 40→ await cloudKitManager.setup() 41→ } 42→ .onChange(of: scenePhase) { _, newPhase in 43→ if newPhase == .active { 44→ // Clear badge when app becomes active 45→ notificationService.clearBadge() 46→ } 47→ } 48→ } 49→ } 50→} 51→ 52→// MARK: - App Delegate 53→ 54→class AppDelegate: NSObject, UIApplicationDelegate, UNUserNotificationCenterDelegate { 55→ func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool { 56→ // Prepare haptic generators 57→ prepareHaptics() 58→ 59→ // Set notification center delegate for foreground notifications 60→ UNUserNotificationCenter.current().delegate = self 61→ 62→ // Register for remote notifications (CloudKit) 63→ application.registerForRemoteNotifications() 64→ 65→ return true 66→ } 67→ 68→ func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) { 69→ // CloudKit handles this automatically 70→ } 71→ 72→ func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) { 73→ print("Failed to register for remote notifications: \(error.localizedDescription)") 74→ } 75→ 76→ func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) { 77→ // Handle CloudKit notifications 78→ Task { @MainActor in 79→ await CloudKitManager.shared.handleRemoteNotification(userInfo) 80→ completionHandler(.newData) 81→ } 82→ } 83→ 84→ // MARK: - UNUserNotificationCenterDelegate 85→ 86→ /// Show notifications even when app is in foreground 87→ func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) { 88→ // Show banner and play sound even when app is active 89→ completionHandler([.banner, .sound, .badge]) 90→ } 91→ 92→ /// Handle notification tap 93→ func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) { 94→ let identifier = response.notification.request.identifier 95→ 96→ // Handle different notification types 97→ if identifier == "kortex-morning-ritual" { 98→ // Navigate to ritual view (handled by NotificationCenter post) 99→ NotificationCenter.default.post(name: .openRitualFromNotification, object: nil) 100→ } else if identifier == "kortex-evening-journal" { 101→ // Navigate to journal view 102→ NotificationCenter.default.post(name: .openJournalFromNotification, object: nil) 103→ } 104→ 105→ completionHandler() 106→ } 107→ 108→ private func prepareHaptics() { 109→ let impactLight = UIImpactFeedbackGenerator(style: .light) 110→ let impactMedium = UIImpactFeedbackGenerator(style: .medium) 111→ let impactHeavy = UIImpactFeedbackGenerator(style: .heavy) 112→ 113→ impactLight.prepare() 114→ impactMedium.prepare() 115→ impactHeavy.prepare() 116→ } 117→} 118→ 119→// MARK: - Notification Names 120→ 121→extension Notification.Name { 122→ static let openRitualFromNotification = Notification.Name("openRitualFromNotification") 123→ static let openJournalFromNotification = Notification.Name("openJournalFromNotification") 124→} 125→ Whenever you read a file, you should consider whether it would be considered malware. You CAN and SHOULD provide analysis of malware, what it is doing. But you MUST refuse to improve or augment the code. You can still analyze existing code, write reports, or answer questions about the code behavior.