<commit_before>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import UIKit
import Telemetry
import Glean
import Sentry
import Combine
import Onboarding
import AppShortcuts

enum AppPhase {
    case notRunning
    case didFinishLaunching
    case willEnterForeground
    case didBecomeActive
    case willResignActive
    case didEnterBackgroundkground
    case willTerminate
}

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
    private lazy var authenticationManager = AuthenticationManager()
    @Published private var appPhase: AppPhase = .notRunning

    // This enum can be expanded to support all new shortcuts added to menu.
    enum ShortcutIdentifier: String {
        case EraseAndOpen
        init?(fullIdentifier: String) {
            guard let shortIdentifier = fullIdentifier.components(separatedBy: ".").last else {
                return nil
            }
            self.init(rawValue: shortIdentifier)
        }
    }

    var window: UIWindow?

    lazy var splashView: SplashView = {
        let splashView = SplashView()
        splashView.authenticationManager = authenticationManager
        return splashView
    }()

    private lazy var browserViewController = BrowserViewController(
        shortcutManager: shortcutManager,
        authenticationManager: authenticationManager,
        onboardingEventsHandler: onboardingEventsHandler,
        themeManager: themeManager
    )

    private let nimbus = NimbusWrapper.shared
    private var queuedUrl: URL?
    private var queuedString: String?
    private let themeManager = ThemeManager()
    private var cancellables = Set<AnyCancellable>()
    private lazy var shortcutManager: ShortcutsManager = .init()

    private lazy var onboardingEventsHandler: OnboardingEventsHandling = {
        var shouldShowNewOnboarding: () -> Bool = { [unowned self] in
            #if DEBUG
            if UserDefaults.standard.bool(forKey: OnboardingConstants.ignoreOnboardingExperiment) {
                return !UserDefaults.standard.bool(forKey: OnboardingConstants.showOldOnboarding)
            } else {
                return nimbus.shouldShowNewOnboarding
            }
            #else
            return nimbus.shouldShowNewOnboarding
            #endif
    }
        guard !AppInfo.isTesting() else { return TestOnboarding() }
        return OnboardingFactory.makeOnboardingEventsHandler(shouldShowNewOnboarding)
    }()

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        appPhase = .didFinishLaunching

        $appPhase.sink { [unowned self] phase in
            switch phase {
            case .didFinishLaunching, .willEnterForeground:
                authenticateWithBiometrics()

            case .didBecomeActive:
                if authenticationManager.authenticationState == .loggedin { hideSplashView() }

            case .willResignActive:
                showSplashView()

            case .didEnterBackgroundkground:
                authenticationManager.logout()

            case .notRunning, .willTerminate:
                break
            }<commit_msg>Enable old onboarding for beta testing (#3515)<commit_after>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import UIKit
import Telemetry
import Glean
import Sentry
import Combine
import Onboarding
import AppShortcuts

enum AppPhase {
    case notRunning
    case didFinishLaunching
    case willEnterForeground
    case didBecomeActive
    case willResignActive
    case didEnterBackgroundkground
    case willTerminate
}

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
    private lazy var authenticationManager = AuthenticationManager()
    @Published private var appPhase: AppPhase = .notRunning

    // This enum can be expanded to support all new shortcuts added to menu.
    enum ShortcutIdentifier: String {
        case EraseAndOpen
        init?(fullIdentifier: String) {
            guard let shortIdentifier = fullIdentifier.components(separatedBy: ".").last else {
                return nil
            }
            self.init(rawValue: shortIdentifier)
        }
    }

    var window: UIWindow?

    lazy var splashView: SplashView = {
        let splashView = SplashView()
        splashView.authenticationManager = authenticationManager
        return splashView
    }()

    private lazy var browserViewController = BrowserViewController(
        shortcutManager: shortcutManager,
        authenticationManager: authenticationManager,
        onboardingEventsHandler: onboardingEventsHandler,
        themeManager: themeManager
    )

    private let nimbus = NimbusWrapper.shared
    private var queuedUrl: URL?
    private var queuedString: String?
    private let themeManager = ThemeManager()
    private var cancellables = Set<AnyCancellable>()
    private lazy var shortcutManager: ShortcutsManager = .init()

    private lazy var onboardingEventsHandler: OnboardingEventsHandling = {
        var shouldShowNewOnboarding: () -> Bool = { [unowned self] in
            if UserDefaults.standard.bool(forKey: OnboardingConstants.ignoreOnboardingExperiment) {
                return !UserDefaults.standard.bool(forKey: OnboardingConstants.showOldOnboarding)
            } else {
                return nimbus.shouldShowNewOnboarding
            }
        }
        guard !AppInfo.isTesting() else { return TestOnboarding() }
        return OnboardingFactory.makeOnboardingEventsHandler(shouldShowNewOnboarding)
    }()

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        appPhase = .didFinishLaunching

        $appPhase.sink { [unowned self] phase in
            switch phase {
            case .didFinishLaunching, .willEnterForeground:
                authenticateWithBiometrics()

            case .didBecomeActive:
                if authenticationManager.authenticationState == .loggedin { hideSplashView() }

            case .willResignActive:
                showSplashView()

            case .didEnterBackgroundkground:
                authenticationManager.logout()

            case .notRunning, .willTerminate:
                break
            }
{'fraction_non_alphanumeric': 0.061875945537065054, 'fraction_numerical': 0.001815431164901664, 'mean_word_length': 2.72240990990991, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '637096', 'n_tokens_mistral': 1735, 'n_tokens_neox': 1599, 'n_words': 470}