<commit_before>//
//  File.swift
//  
//
//  Created by <NAME> on 2019-10-28.
//

#if os(iOS)
import UIKit

/// Subclassed by the `SceneDelegate` to pass lifecycle events to loaded plugins.
///
/// The scene plugins will be processed in sequence after calling `plugins() -> [ScenePlugin]`.
///
///     class SceneDelegate: ScenePluggableDelegate {
///
///         override func plugins() -> [ScenePlugin] {[
///             LoggerPlugin(),
///             NotificationPlugin()
///         ]}
///     }
///
/// Each scene plugin has access to the `SceneDelegate` lifecycle events:
///
///     final class LoggerPlugin: ScenePlugin {
///         private let log = Logger()
///
///         func sceneWillEnterForeground() {
///             log.info("Scene will enter foreground.")
///         }
///
///         func sceneDidEnterBackground() {
///             log.info("Scene did enter background.")
///         }
///     }
@available(iOS 13.0, *)
open class ScenePluggableDelegate: UIResponder, UIWindowSceneDelegate {
    public var window: UIWindow?
    
    /// List of scene plugins for binding to `SceneDelegate` events
    public private(set) lazy var pluginInstances: [ScenePlugin] = { plugins() }()
    
    public override init() {
        super.init()
        
        // Load lazy property early
        _ = pluginInstances
    }
    
    /// List of scene plugins for binding to `SceneDelegate` events
    open func plugins() -> [ScenePlugin] {[]} // Override
}

@available(iOS 13.0, *)
public extension ScenePluggableDelegate {
    
    func sceneWillEnterForeground(_ scene: UIScene) {
        pluginInstances.forEach { $0.sceneWillEnterForeground() }
    }
    
    func sceneDidEnterBackground(_ scene: UIScene) {
        pluginInstances.forEach { $0.sceneDidEnterBackground() }
    }
    
    func sceneDidBecomeActive(_ scene: UIScene) {
        pluginInstances.forEach { $0.sceneDidBecomeActive() }
    }
    
    func sceneWillResignActive(_ scene: UIScene) {
        pluginInstances.forEach { $0.sceneWillResignActive() }
    }
    
    func sceneDidDisconnect(_ scene: UIScene) {
        pluginInstances.forEach { $0.sceneDidDisconnect() }
    }
}

/// Conforming to an scene module and added to `SceneDelegate.plugins()` will trigger events.
public protocol ScenePlugin {
    func sceneWillEnterForeground()
    func sceneDidEnterBackground()
    func sceneDidBecomeActive()
    func sceneWillResignActive()
    func sceneDidDisconnect()
}

// MARK: - Optionals

public extension ScenePlugin {
    func sceneWillEnterForeground() {}
    func sceneDidEnterBackground() {}
    func sceneDidBecomeActive() {}
    func sceneWillResignActive() {}
    func sceneDidDisconnect() {}
}
#endif<commit_msg>Access control and comments on pluggable scene<commit_after>//
//  File.swift
//  
//
//  Created by <NAME> on 2019-10-28.
//

#if os(iOS)
import UIKit

/// Subclassed by the `SceneDelegate` to pass lifecycle events to loaded plugins.
///
/// The scene plugins will be processed in sequence after calling `plugins() -> [ScenePlugin]`.
///
///     class SceneDelegate: ScenePluggableDelegate {
///
///         override func plugins() -> [ScenePlugin] {[
///             LoggerPlugin(),
///             NotificationPlugin()
///         ]}
///     }
///
/// Each scene plugin has access to the `SceneDelegate` lifecycle events:
///
///     final class LoggerPlugin: ScenePlugin {
///         private let log = Logger()
///
///         func sceneWillEnterForeground() {
///             log.info("Scene will enter foreground.")
///         }
///
///         func sceneDidEnterBackground() {
///             log.info("Scene did enter background.")
///         }
///     }
@available(iOS 13.0, *)
open class ScenePluggableDelegate: UIResponder, UIWindowSceneDelegate {
    public var window: UIWindow?
    
    /// List of scene plugins for binding to `SceneDelegate` events
    public private(set) lazy var pluginInstances: [ScenePlugin] = { plugins() }()
    
    public override init() {
        super.init()
        
        // Load lazy property early
        _ = pluginInstances
    }
    
    /// List of scene plugins for binding to `SceneDelegate` events
    open func plugins() -> [ScenePlugin] {[]} // Override
}

@available(iOS 13.0, *)
extension ScenePluggableDelegate {
    
    open func sceneWillEnterForeground(_ scene: UIScene) {
        pluginInstances.forEach { $0.sceneWillEnterForeground() }
    }
    
    open func sceneDidEnterBackground(_ scene: UIScene) {
        pluginInstances.forEach { $0.sceneDidEnterBackground() }
    }
    
    open func sceneDidBecomeActive(_ scene: UIScene) {
        pluginInstances.forEach { $0.sceneDidBecomeActive() }
    }
    
    open func sceneWillResignActive(_ scene: UIScene) {
        pluginInstances.forEach { $0.sceneWillResignActive() }
    }
    
    open func sceneDidDisconnect(_ scene: UIScene) {
        pluginInstances.forEach { $0.sceneDidDisconnect() }
    }
}

/// Conforming to an scene module and added to `SceneDelegate.plugins()` will trigger events.
public protocol ScenePlugin {
    
    /// Tells the delegate that the scene is about to begin running in the foreground and become visible to the user.
    func sceneWillEnterForeground()
    
    /// Tells the delegate that the scene is running in the background and is no longer onscreen.
    func sceneDidEnterBackground()
    
    /// Tells the delegate that the scene became active and is now responding to user events.
    func sceneDidBecomeActive()
    
    /// Tells the delegate that the scene is about to resign the active state and stop responding to user events.
    func sceneWillResignActive()
    
    /// Tells the delegate that UIKit removed a scene from your app.
    func sceneDidDisconnect()
}

// MARK: - Optionals

public extension ScenePlugin {
    func sceneWillEnterForeground() {}
    func sceneDidEnterBackground() {}
    func sceneDidBecomeActive() {}
    func sceneWillResignActive() {}
    func sceneDidDisconnect() {}
}
#endif
{'fraction_non_alphanumeric': 0.11331444759206799, 'fraction_numerical': 0.006332277953674388, 'mean_word_length': 2.5099415204678364, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '1085296', 'n_tokens_mistral': 1698, 'n_tokens_neox': 1642, 'n_words': 488}