<commit_before>//
//  AppDelegateExtensions.swift
//  MacMagazine
//
//  Created by <NAME> on 23/05/2019.
//  Copyright © 2019 MacMagazine. All rights reserved.
//

import CoreSpotlight
import StoreKit
import UIKit

// MARK: - Notification Definitions -

extension Notification.Name {
	static let shortcutActionLastPost = Notification.Name("shortcutActionLastPost")
	static let shortcutActionRecentPost = Notification.Name("shortcutActionRecentPost")
	static let reloadWeb = Notification.Name("reloadWeb")
	static let scrollToTop = Notification.Name("scrollToTop")
	static let favoriteUpdated = Notification.Name("favoriteUpdated")
	static let updateSelectedPost = Notification.Name("updateSelectedPost")
    static let refreshAfterBackground = Notification.Name("refreshAfterBackground")
    static let reloadData = Notification.Name("reloadData")
    static let updateCookie = Notification.Name("updateCookie")
}

// MARK: - Update content -

extension AppDelegate {
    func applicationWillEnterForeground(_ application: UIApplication) {
        NotificationCenter.default.post(name: .refreshAfterBackground, object: nil)
    }

    func applicationDidBecomeActive(_ application: UIApplication) {
        Settings().applyTheme()
	}
}

// MARK: - Setup -

extension AppDelegate {
	func setup(_ launchOptions: [UIApplication.LaunchOptionsKey: Any]?) {
        // Splitview settings
        guard let tabBarViewController = window?.rootViewController as? UITabBarController,
              let splitViewController = tabBarViewController.viewControllers?.first as? UISplitViewController else {
            return
        }
        splitViewController.delegate = self
        splitViewController.preferredDisplayMode = .allVisible
        splitViewController.preferredPrimaryColumnWidthFraction = 0.33

        // Apply custom thmee (Dark/Light)
		Settings().applyTheme()

		// Apple Watch Session
		WatchSessionManager.shared.startSession()

		// AppStore Review
		if Settings().shouldAskForReview {
			SKStoreReviewController.requestReview()
		}

		// Push Notification
		PushNotification().setup(options: launchOptions)
	}
}

// MARK: - Splitview Delegate -

extension AppDelegate: UISplitViewControllerDelegate {
	func splitViewController(_ splitViewController: UISplitViewController, collapseSecondary secondaryViewController: UIViewController, onto primaryViewController: UIViewController) -> Bool {
		guard let secondaryAsNavController = secondaryViewController as? UINavigationController,
			let topAsDetailController = secondaryAsNavController.topViewController as? PostsDetailViewController
			else {
				return false<commit_msg>Fix tap 2x on tabBar to scroll to top<commit_after>//
//  AppDelegateExtensions.swift
//  MacMagazine
//
//  Created by <NAME> on 23/05/2019.
//  Copyright © 2019 MacMagazine. All rights reserved.
//

import CoreSpotlight
import StoreKit
import UIKit

// MARK: - Notification Definitions -

extension Notification.Name {
	static let shortcutActionLastPost = Notification.Name("shortcutActionLastPost")
	static let shortcutActionRecentPost = Notification.Name("shortcutActionRecentPost")
	static let reloadWeb = Notification.Name("reloadWeb")
	static let scrollToTop = Notification.Name("scrollToTop")
	static let favoriteUpdated = Notification.Name("favoriteUpdated")
	static let updateSelectedPost = Notification.Name("updateSelectedPost")
    static let refreshAfterBackground = Notification.Name("refreshAfterBackground")
    static let reloadData = Notification.Name("reloadData")
    static let updateCookie = Notification.Name("updateCookie")
}

// MARK: - Update content -

extension AppDelegate {
    func applicationWillEnterForeground(_ application: UIApplication) {
        NotificationCenter.default.post(name: .refreshAfterBackground, object: nil)
    }

    func applicationDidBecomeActive(_ application: UIApplication) {
        Settings().applyTheme()
	}
}

// MARK: - Setup -

extension AppDelegate {
	func setup(_ launchOptions: [UIApplication.LaunchOptionsKey: Any]?) {
        // Splitview settings
        guard let tabBarViewController = window?.rootViewController as? UITabBarController,
              let splitViewController = tabBarViewController.viewControllers?.first as? UISplitViewController else {
            return
        }
        tabBarViewController.delegate = self

        splitViewController.delegate = self
        splitViewController.preferredDisplayMode = .allVisible
        splitViewController.preferredPrimaryColumnWidthFraction = 0.33

        // Apply custom thmee (Dark/Light)
		Settings().applyTheme()

		// Apple Watch Session
		WatchSessionManager.shared.startSession()

		// AppStore Review
		if Settings().shouldAskForReview {
			SKStoreReviewController.requestReview()
		}

		// Push Notification
		PushNotification().setup(options: launchOptions)
	}
}

// MARK: - Splitview Delegate -

extension AppDelegate: UISplitViewControllerDelegate {
	func splitViewController(_ splitViewController: UISplitViewController, collapseSecondary secondaryViewController: UIViewController, onto primaryViewController: UIViewController) -> Bool {
		guard let secondaryAsNavController = secondaryViewController as? UINavigationController,
			let topAsDetailController = secondaryAsNavController.topViewController as? PostsDetailViewController
			else {
				return false
{'fraction_non_alphanumeric': 0.08086858854361663, 'fraction_numerical': 0.005803070011231749, 'mean_word_length': 4.485626283367557, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '116438', 'n_tokens_mistral': 1453, 'n_tokens_neox': 1277, 'n_words': 327}