print_modname() {
  # 在这里设置你想要在模块安装过程中显示的信息
  ui_print "*******************************"
  ui_print "  本次模块适配MIUI深色模式  "
  ui_print "  且刷入模块后无需重启手机，修改即时生效  "
  ui_print "*******************************"
  ui_print "  你的设备: $var_device"
  ui_print "  系统版本: $var_version"
}

initmods()
{
  mod_name=""
  mod_install_info=""
  mod_select_yes_text=""
  mod_select_yes_desc=""
  mod_select_no_text=""
  mod_select_no_desc=""
  mod_require_device=""
  mod_require_version=""
  INSTALLED_FUNC="`trim $INSTALLED_FUNC`"
  MOD_SKIP_INSTALL=false
  cd $TMPDIR/mods
}

keytest() {
  ui_print "- 音量键测试 -"
  ui_print "   请按下 [音量+] 键："
  ui_print "   无反应或传统模式无法正确安装时，请触摸一下屏幕后继续"
  (/system/bin/getevent -lc 1 2>&1 | /system/bin/grep VOLUME | /system/bin/grep " DOWN" > $TMPDIR/events) || return 1
  return 0
}

chooseport() {
  #note from chainfire @xda-developers: getevent behaves weird when piped, and busybox grep likes that even less than toolbox/toybox grep
  while (true); do
    /system/bin/getevent -lc 1 2>&1 | /system/bin/grep VOLUME | /system/bin/grep " DOWN" > $TMPDIR/events
    if (`cat $TMPDIR/events 2>/dev/null | /system/bin/grep VOLUME >/dev/null`); then
      break
    fi
  done
  if (`cat $TMPDIR/events 2>/dev/null | /system/bin/grep VOLUMEUP >/dev/null`); then
    return 0
  else
    return 1
  fi
}

chooseportold() {
  # Calling it first time detects previous input. Calling it second time will do what we want
  $KEYCHECK
  $KEYCHECK
  SEL=$?
  $DEBUG_FLAG && ui_print "  DEBUG: chooseportold: $1,$SEL"
  if [ "$1" == "UP" ]; then
    UP=$SEL
  elif [ "$1" == "DOWN" ]; then
    DOWN=$SEL
  elif [ $SEL -eq $UP ]; then
    return 0
  elif [ $SEL -eq $DOWN ]; then
    return 1
  else
    abort "   未检测到音量键!"
  fi
}

testkey() {
  # Keycheck binary by someone755 @Github, idea for code below by Zappo @xda-developers
  KEYCHECK=$TMPDIR/keycheck
  chmod 755 $KEYCHECK
  zip=$TMPDIR/zip
  chmod 755 $zip
  # 测试音量键
  if keytest; then
    VOLKEY_FUNC=chooseport
    ui_print "*******************************"
  else
    VOLKEY_FUNC=chooseportold
    ui_print "*******************************"
    ui_print "- 检测到遗留设备！使用旧的 keycheck 方案 -"
    ui_print "- 进行音量键录入 -"
    ui_print "   录入：请按下 [音量+] 键："
    $VOLKEY_FUNC "UP"
    ui_print "   已录入 [音量+] 键。"
    ui_print "   录入：请按下 [音量-] 键："
    $VOLKEY_FUNC "DOWN"
    ui_print "   已录入 [音量-] 键。"
  ui_print "*******************************"
  fi
}

modinstall() {
  # 加载可用模块
  initmods
  for MOD in $(ls)
  do
    if [ -f $MOD/mod_info.sh ]; then
      source $MOD/mod_info.sh
      $DEBUG_FLAG && ui_print "  DEBUG: load $MOD"
      $DEBUG_FLAG && ui_print "  DEBUG: mod's name: $mod_name"
      if $MOD_SKIP_INSTALL ; then
        ui_print "  跳过[$mod_name]安装"
        initmods
        continue
      fi
        ui_print "  [$mod_name]安装"
        ui_print "  - 介绍: $mod_install_desc"
        ui_print "  - 请按音量键选择$mod_install_info -"
        ui_print "   [音量+]：$mod_select_yes_text"
        ui_print "   [音量-]：$mod_select_no_text"
        if $VOLKEY_FUNC; then
          ui_print "   已选择[$mod_select_yes_text]。"
          mod_install_yes
          run_result=$?
          if [ $run_result -eq 0 ]; then
            let record++
            MODS_SELECTED_YES="$MODS_SELECTED_YES ($MOD)"
            INSTALLED_FUNC="$mod_select_yes_desc $INSTALLED_FUNC"
          fi
        else
          ui_print "   已选择[$mod_select_no_text]。"
          mod_install_no
        fi
    else
      $DEBUG_FLAG && ui_print "  DEBUG: could not found $MOD's mod_info.sh"
    fi
    initmods
  done
}