<commit_before>module DeployGateIOS
  def user_id=(id)
    @user_id = id
  end

  def api_key=(key)
    @api_key = key
  end

  def user_infomation=(bool)
    @user_infomation = bool
  end
  alias :user_information= :user_infomation=

  def url_scheme=(scheme)
    @config.info_plist['CFBundleURLTypes'] = [
      {
        'CFBundleURLName'    => @config.identifier,
        'CFBundleURLSchemes' => [scheme]
      }
    ]
  end

  def sdk=(sdk)
    @sdk = sdk
    @config.vendor_project(
      sdk,
      :static,
      :products => ['DeployGateSDK'],
      :headers_dir => 'Headers'
    )
    @config.frameworks << 'SystemConfiguration'
    create_launcher
    apply_patch
  end

  private

  def create_launcher
    return unless @user_id && @api_key

    launcher_code = <<EOF
# This file is automatically generated. Do not edit.

if Object.const_defined?('DeployGateSDK') and !UIDevice.currentDevice.model.include?('Simulator')
  NSNotificationCenter.defaultCenter.addObserverForName(UIApplicationDidFinishLaunchingNotification, object:nil, queue:nil, usingBlock:lambda do |notification|
    DeployGateSDK.sharedInstance.launchApplicationWithAuthor('#{@user_id}', key:'#{@api_key}', userInfomationEnabled:#{@user_infomation})
  end)

  class #{@config.delegate_class}
    unless #{@config.delegate_class}.method_defined?("application:openURL:sourceApplication:annotation:")
      def application(application, openURL:url, sourceApplication:sourceApplication, annotation:annotation)
        return DeployGateSDK.sharedInstance.handleOpenUrl(url, sourceApplication:sourceApplication, annotation:annotation)
      end
    end
  end

end
EOF
    launcher_file = './app/deploygate_launcher.rb'
    if !File.exist?(launcher_file) or File.read(launcher_file) != launcher_code
      File.open(launcher_file, 'w') { |io| io.write(launcher_code) }
    end
    @config.files.unshift(launcher_file)
  end

  def apply_patch
    Dir.glob(File.join(@sdk, "Headers") + "/*.h") do |file|
      file = File.expand_path(file)
      data = File.read(file)
      new_data = []
      data.each_line do |line|
        # replace "typedef enum" declaration to avoid http://hipbyte.myjetbrains.com/youtrack/issue/RM-479
        if line.strip == "typedef enum DeployGateSDKOption : NSUInteger {"
          new_data << "typedef enum DeployGateSDKOption {\n"
        else
          new_data << line
        end
      end

      new_data = new_data.join
      if data != new_data
        File.open(file, "w") do |io|
          io.write new_data
        end
      end
    end
  end

end<commit_msg>no longer need a patch for enum with RubyMotion 3.14<commit_after>module DeployGateIOS
  def user_id=(id)
    @user_id = id
  end

  def api_key=(key)
    @api_key = key
  end

  def user_infomation=(bool)
    @user_infomation = bool
  end
  alias :user_information= :user_infomation=

  def url_scheme=(scheme)
    @config.info_plist['CFBundleURLTypes'] = [
      {
        'CFBundleURLName'    => @config.identifier,
        'CFBundleURLSchemes' => [scheme]
      }
    ]
  end

  def sdk=(sdk)
    @sdk = sdk
    @config.vendor_project(
      sdk,
      :static,
      :products => ['DeployGateSDK'],
      :headers_dir => 'Headers'
    )
    @config.frameworks << 'SystemConfiguration'
    create_launcher
  end

  private

  def create_launcher
    return unless @user_id && @api_key

    launcher_code = <<EOF
# This file is automatically generated. Do not edit.

if Object.const_defined?('DeployGateSDK') and !UIDevice.currentDevice.model.include?('Simulator')
  NSNotificationCenter.defaultCenter.addObserverForName(UIApplicationDidFinishLaunchingNotification, object:nil, queue:nil, usingBlock:lambda do |notification|
    DeployGateSDK.sharedInstance.launchApplicationWithAuthor('#{@user_id}', key:'#{@api_key}', userInfomationEnabled:#{@user_infomation})
  end)

  class #{@config.delegate_class}
    unless #{@config.delegate_class}.method_defined?("application:openURL:sourceApplication:annotation:")
      def application(application, openURL:url, sourceApplication:sourceApplication, annotation:annotation)
        return DeployGateSDK.sharedInstance.handleOpenUrl(url, sourceApplication:sourceApplication, annotation:annotation)
      end
    end
  end

end
EOF
    launcher_file = './app/deploygate_launcher.rb'
    if !File.exist?(launcher_file) or File.read(launcher_file) != launcher_code
      File.open(launcher_file, 'w') { |io| io.write(launcher_code) }
    end
    @config.files.unshift(launcher_file)
  end

end
{'fraction_non_alphanumeric': 0.11019955654101996, 'fraction_numerical': 0.0013303769401330377, 'mean_word_length': 3.679460580912863, 'pattern_counts': {'":': 0, '<': 15, '<?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': '6554894', 'n_tokens_mistral': 1489, 'n_tokens_neox': 1426, 'n_words': 276}