<commit_before>//
//  SystemInfo.swift
//  PurchasesCoreSwift
//
//  Created by <NAME> on 6/29/21.
//  Copyright © 2021 Purchases. All rights reserved.
//

import Foundation

#if os(iOS) || os(tvOS) || targetEnvironment(macCatalyst)
import UIKit
#elseif os(watchOS)
import UIKit
import WatchKit
#elseif os(macOS)
import AppKit
#endif

@objc(RCSystemInfo) open class SystemInfo: NSObject {

    #if targetEnvironment(macCatalyst)
    static let platformHeaderConstant = "uikitformac"
    #elseif os(iOS)
    static let platformHeaderConstant = "iOS"
    #elseif os(watchOS)
    static let platformHeaderConstant = "watchOS"
    #elseif os(tvOS)
    static let platformHeaderConstant = "tvOS"
    #elseif os(macOS)
    static let platformHeaderConstant = "macOS"
    #endif

    public enum SystemInfoError: Error {
        case invalidInitializationData
    }

    private static let defaultServerHostName = "https://api.revenuecat.com"

    @objc public var finishTransactions: Bool
    @objc public let platformFlavor: String
    @objc public let platformFlavorVersion: String?
    @objc public static var forceUniversalAppStore: Bool = false
    @objc public static var isSandbox: Bool {
        let url = Bundle.main.appStoreReceiptURL
        guard let url = url else {
            return false
        }

        let receiptURLString = url.path
        return receiptURLString.contains("sandboxReceipt")
    }

    @objc public static var frameworkVersion: String { // TODO: automate the setting of this, if it hasn't been.
        return "3.12.0-SNAPSHOT"
    }

    @objc public static var systemVersion: String {
        return ProcessInfo().operatingSystemVersionString
    }

    @objc public static var appVersion: String {
        return Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? ""
    }

    @objc public static var buildVersion: String {
        return Bundle.main.infoDictionary?["CFBundleVersion"] as? String ?? ""
    }

    @objc public static var platformHeader: String {
        return Self.forceUniversalAppStore ? "iOS" : platformHeaderConstant
    }

    @objc public static var identifierForVendor: String? {
        #if os(iOS) || os(tvOS) || targetEnvironment(macCatalyst)
            return UIDevice.current.identifierForVendor?.uuidString
        #elseif os(watchOS)
            return WKInterfaceDevice.current().identifierForVendor?.uuidString
        #else
            return nil
        #endif
    }

    private static var defaultServerHostURL: URL {
        return URL(string: defaultServerHostName)!
    }

    @objc public static var serverHostURL: URL {
        return Self.proxyURL ?? Self.defaultServerHostURL
    }

    private static var privateProxyURL: URL?
    @objc public static var proxyURL: URL? {
        get {
            return privateProxyURL
        }
        set {
            privateProxyURL = newValue
            if let privateProxyURLString = newValue?.absoluteString {
                Logger.info(Strings.configure.configuring_purchases_proxy_url_set
                                .replacingOccurrences(of: "%@", with: privateProxyURLString))
            }
        }
    }

    @objc required public init(platformFlavor: String?, platformFlavorVersion: String?, finishTransactions: Bool) throws {
        self.platformFlavor = platformFlavor ?? "native"
        self.platformFlavorVersion = platformFlavorVersion

        if (platformFlavor == nil && platformFlavorVersion != nil) ||
            (platformFlavor != nil && platformFlavorVersion == nil) {
            Logger.error("RCSystemInfo initialized with non-matching platform flavor and platform flavor versions!")
            throw SystemInfoError.invalidInitializationData
        }

        self.finishTransactions = finishTransactions
    }

    @objc open func isApplicationBackgrounded(completion: @escaping (Bool) -> Void) {<commit_msg>Address comments (#620)<commit_after>//
//  SystemInfo.swift
//  PurchasesCoreSwift
//
//  Created by <NAME> on 6/29/21.
//  Copyright © 2021 Purchases. All rights reserved.
//

import Foundation

#if os(iOS) || os(tvOS) || targetEnvironment(macCatalyst)
import UIKit
#elseif os(watchOS)
import UIKit
import WatchKit
#elseif os(macOS)
import AppKit
#endif

@objc(RCSystemInfo) open class SystemInfo: NSObject {

    #if targetEnvironment(macCatalyst)
    static let platformHeaderConstant = "uikitformac"
    #elseif os(iOS)
    static let platformHeaderConstant = "iOS"
    #elseif os(watchOS)
    static let platformHeaderConstant = "watchOS"
    #elseif os(tvOS)
    static let platformHeaderConstant = "tvOS"
    #elseif os(macOS)
    static let platformHeaderConstant = "macOS"
    #endif

    public enum SystemInfoError: Error {
        case invalidInitializationData
    }

    private static let defaultServerHostName = "https://api.revenuecat.com"

    @objc public var finishTransactions: Bool
    @objc public let platformFlavor: String
    @objc public let platformFlavorVersion: String?
    @objc public static var forceUniversalAppStore: Bool = false
    @objc public static var isSandbox: Bool {
        let url = Bundle.main.appStoreReceiptURL
        guard let url = url else {
            return false
        }

        let receiptURLString = url.path
        return receiptURLString.contains("sandboxReceipt")
    }

    @objc public static var frameworkVersion: String { // TODO: automate the setting of this, if it hasn't been.
        return "3.12.0-SNAPSHOT"
    }

    @objc public static var systemVersion: String {
        return ProcessInfo().operatingSystemVersionString
    }

    @objc public static var appVersion: String {
        return Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? ""
    }

    @objc public static var buildVersion: String {
        return Bundle.main.infoDictionary?["CFBundleVersion"] as? String ?? ""
    }

    @objc public static var platformHeader: String {
        return Self.forceUniversalAppStore ? "iOS" : platformHeaderConstant
    }

    @objc public static var identifierForVendor: String? {
        #if os(iOS) || os(tvOS) || targetEnvironment(macCatalyst)
            return UIDevice.current.identifierForVendor?.uuidString
        #elseif os(watchOS)
            return WKInterfaceDevice.current().identifierForVendor?.uuidString
        #else
            return nil
        #endif
    }

    private static var defaultServerHostURL: URL {
        return URL(string: defaultServerHostName)!
    }

    @objc public static var serverHostURL: URL {
        return Self.proxyURL ?? Self.defaultServerHostURL
    }

    @objc public static var proxyURL: URL? {
        didSet {
            if let privateProxyURLString = proxyURL?.absoluteString {
                Logger.info(Strings.configure.configuring_purchases_proxy_url_set
                                .replacingOccurrences(of: "%@", with: privateProxyURLString))
            }
        }
    }

    @objc required public init(platformFlavor: String?, platformFlavorVersion: String?, finishTransactions: Bool) throws {
        self.platformFlavor = platformFlavor ?? "native"
        self.platformFlavorVersion = platformFlavorVersion

        if (platformFlavor == nil && platformFlavorVersion != nil) ||
            (platformFlavor != nil && platformFlavorVersion == nil) {
            Logger.error("RCSystemInfo initialized with non-matching platform flavor and platform flavor versions!")
            throw SystemInfoError.invalidInitializationData
        }

        self.finishTransactions = finishTransactions
    }

    @objc open func isApplicationBackgrounded(completion: @escaping (Bool) -> Void) {
{'fraction_non_alphanumeric': 0.08311552535284893, 'fraction_numerical': 0.003789858860428646, 'mean_word_length': 2.9085801838610825, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 2, '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': '3299144', 'n_tokens_mistral': 2167, 'n_tokens_neox': 2060, 'n_words': 566}