<commit_before>//
//  ViewController.swift
//  MomentUS
//
//  Created by <NAME> on 1/14/17.
//  Copyright © 2017 <NAME>. All rights reserved.
//

import UIKit

let LockStateChangedNotification = Notification.Name(rawValue: "lock_state_changed")

class ActiveSessionViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {

    //MARK: Properties
    @IBOutlet weak var sessionNameTextField: UILabel!
    @IBOutlet weak var _beginButton: UIButton!
    @IBOutlet weak var friendsTableView: UITableView!
    var friends = [Friend]()
    var sessionName = "Session Name"
    
    private var isUnplugSessionInProgress = false
    private var lockStateOn = false
    private var phoneIsLocked: Bool {
        get{
            var isLocked: Bool!
            runOnSerialQueue {
                isLocked = self.lockStateOn
            }
            return isLocked
        }
        set{
            runOnSerialQueue {
                self.lockStateOn = newValue
            }
        }
    }

    //MARK: Controller state change handling logic
    override func viewDidLoad() {
        super.viewDidLoad()
        sessionNameTextField.text = sessionName

        // Handle the friend tableView through delegate callbacks
        friendsTableView.delegate = self
        friendsTableView.dataSource = self

        NotificationCenter.default.addObserver(
            self,
            selector: #selector(_onAppEnterBackground),
            name: NSNotification.Name.UIApplicationDidEnterBackground,
            object: nil
        )
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    private func _listenForDeviceActivity() {
        NotificationCenter.default.addObserver(
            self,
            selector: #selector(_updateLockScreenStatus),
            name: LockStateChangedNotification,
            object: nil
        )
        
        CFNotificationCenterAddObserver(
            CFNotificationCenterGetDarwinNotifyCenter(),
            nil,
            {
                (
                center: CFNotificationCenter?,
                observer: UnsafeMutableRawPointer?,
                name: CFNotificationName?,
                object: UnsafeRawPointer?,
                info: CFDictionary?) in
                    print("received notification: \(name!)")
                    NotificationCenter.default.post(
                        Notification(
                            name: LockStateChangedNotification
                        )
                    )
            },
            //"com.apple.iokit.hid.displayStatus" as CFString!,
            //"com.apple.springboard.lockcomplete" as CFString!,
            "com.apple.springboard.lockstate" as CFString!,
            //"com.apple.springboard.hasBlankedScreen" as CFString!,
            nil,
            CFNotificationSuspensionBehavior.deliverImmediately
        )
    }

    private func _stopListeningForDeviceActivity() {
        NotificationCenter.default.removeObserver(
            self,
            name: LockStateChangedNotification,
            object: nil)
    }

    @objc func _onAppEnterBackground() {
        print("Say... app entered background")
    }

    @objc func _updateLockScreenStatus() {
        self.phoneIsLocked = !self.phoneIsLocked
        if self.phoneIsLocked {
            print("Phone is now locked.")
        } else {
            print("Phone is now unlocked.")<commit_msg>Add print message, "You Lose!"<commit_after>//
//  ViewController.swift
//  MomentUS
//
//  Created by <NAME> on 1/14/17.
//  Copyright © 2017 <NAME>. All rights reserved.
//

import UIKit

let LockStateChangedNotification = Notification.Name(rawValue: "lock_state_changed")

class ActiveSessionViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {

    //MARK: Properties
    @IBOutlet weak var sessionNameTextField: UILabel!
    @IBOutlet weak var _beginButton: UIButton!
    @IBOutlet weak var friendsTableView: UITableView!
    var friends = [Friend]()
    var sessionName = "Session Name"
    
    private var isUnplugSessionInProgress = false
    private var lockStateOn = false
    private var phoneIsLocked: Bool {
        get{
            var isLocked: Bool!
            runOnSerialQueue {
                isLocked = self.lockStateOn
            }
            return isLocked
        }
        set{
            runOnSerialQueue {
                self.lockStateOn = newValue
            }
        }
    }

    //MARK: Controller state change handling logic
    override func viewDidLoad() {
        super.viewDidLoad()
        sessionNameTextField.text = sessionName

        // Handle the friend tableView through delegate callbacks
        friendsTableView.delegate = self
        friendsTableView.dataSource = self

        NotificationCenter.default.addObserver(
            self,
            selector: #selector(_onAppEnterBackground),
            name: NSNotification.Name.UIApplicationDidEnterBackground,
            object: nil
        )
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    private func _listenForDeviceActivity() {
        NotificationCenter.default.addObserver(
            self,
            selector: #selector(_updateLockScreenStatus),
            name: LockStateChangedNotification,
            object: nil
        )
        
        CFNotificationCenterAddObserver(
            CFNotificationCenterGetDarwinNotifyCenter(),
            nil,
            {
                (
                center: CFNotificationCenter?,
                observer: UnsafeMutableRawPointer?,
                name: CFNotificationName?,
                object: UnsafeRawPointer?,
                info: CFDictionary?) in
                    print("received notification: \(name!)")
                    NotificationCenter.default.post(
                        Notification(
                            name: LockStateChangedNotification
                        )
                    )
            },
            //"com.apple.iokit.hid.displayStatus" as CFString!,
            //"com.apple.springboard.lockcomplete" as CFString!,
            "com.apple.springboard.lockstate" as CFString!,
            //"com.apple.springboard.hasBlankedScreen" as CFString!,
            nil,
            CFNotificationSuspensionBehavior.deliverImmediately
        )
    }

    private func _stopListeningForDeviceActivity() {
        NotificationCenter.default.removeObserver(
            self,
            name: LockStateChangedNotification,
            object: nil)
    }

    @objc func _onAppEnterBackground() {
        print("Say... app entered background")
    }

    @objc func _updateLockScreenStatus() {
        self.phoneIsLocked = !self.phoneIsLocked
        if self.phoneIsLocked {
            print("Phone is now locked.")
        } else {
            print("Phone is now unlocked.")
            print("Congratulations! You Lose!")
{'fraction_non_alphanumeric': 0.07534923098631297, 'fraction_numerical': 0.0025398617186397627, 'mean_word_length': 1.8649959579628133, 'pattern_counts': {'":': 0, '<': 7, '<?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': '4147566', 'n_tokens_mistral': 1799, 'n_tokens_neox': 1692, 'n_words': 398}