From e7dfd8996419b5d41969c27a9d34d8b3ed77f0c5 Mon Sep 17 00:00:00 2001 From: Zkitefly <2573874409@qq.com> Date: Mon, 26 Aug 2024 16:24:51 +0800 Subject: [PATCH 1/2] Update HMCLauncher.sh --- HMCL/src/main/resources/assets/HMCLauncher.sh | 34 ++++++++++--------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/HMCL/src/main/resources/assets/HMCLauncher.sh b/HMCL/src/main/resources/assets/HMCLauncher.sh index 824c0aa552..a42a2cc258 100644 --- a/HMCL/src/main/resources/assets/HMCLauncher.sh +++ b/HMCL/src/main/resources/assets/HMCLauncher.sh @@ -2,6 +2,18 @@ set -e +# Function to show GUI message +show_message() { + local title="$1" + local message="$2" + echo -e "$title: ""$message" + if command -v zenity > /dev/null; then + zenisty --info --title="$title" --text="$message" --width=400 --height=200 + elif command -v kdialog > /dev/null; then + kdialog --title "$title" --msgbox "$message" + fi +} + # Switch message language if [ -z "${LANG##zh_*}" ]; then _HMCL_USE_CHINESE=true @@ -62,11 +74,9 @@ if [ -n "${HMCL_JAVA_HOME+x}" ]; then exec "$HMCL_JAVA_HOME/bin/$_HMCL_JAVA_EXE_NAME" $_HMCL_VM_OPTIONS -jar "$_HMCL_PATH" else if [ "$_HMCL_USE_CHINESE" == true ]; then - echo "环境变量 HMCL_JAVA_HOME 的值无效,请设置为合法的 Java 路径。" 1>&2 - echo "你可以访问 https://docs.hmcl.net/help.html 页面寻求帮助。" 1>&2 + show_message "错误" "环境变量 HMCL_JAVA_HOME 的值无效,请设置为合法的 Java 路径。\n你可以访问 https://docs.hmcl.net/help.html 页面寻求帮助。" else - echo "The value of the environment variable HMCL_JAVA_HOME is invalid, please set it to a valid Java path." 1>&2 - echo "You can visit the https://docs.hmcl.net/help.html page for help." 1>&2 + show_message "Error" "The value of the environment variable HMCL_JAVA_HOME is invalid, please set it to a valid Java path.\nYou can visit the https://docs.hmcl.net/help.html page for help." fi exit 1 fi @@ -125,24 +135,16 @@ fi case "$_HMCL_OS-$_HMCL_ARCH" in windows-x86|windows-x86_64|windows-arm64|linux-x86|linux-x86_64|linux-arm32|linux-arm64|linux-loongarch64|macos-x86_64|macos-arm64) if [ "$_HMCL_USE_CHINESE" == true ]; then - echo "运行 HMCL 需要 Java 运行时环境,请安装 Java 并设置环境变量后重试。" 1>&2 - echo "https://docs.hmcl.net/downloads/$_HMCL_DOWNLOAD_PAGE_OS/$_HMCL_HMCL_ARCH.html" 1>&2 - echo "你可以访问 https://docs.hmcl.net/help.html 页面寻求帮助。" 1>&2 + show_message "错误" "运行 HMCL 需要 Java 运行时环境,请安装 Java 并设置环境变量后重试。\n\nhttps://docs.hmcl.net/downloads/$_HMCL_DOWNLOAD_PAGE_OS/$_HMCL_ARCH.html\n\n你可以访问 https://docs.hmcl.net/help.html 页面寻求帮助。" else - echo "The Java runtime environment is required to run HMCL. " 1>&2 - echo "Please install Java and set the environment variables and try again." 1>&2 - echo "https://docs.hmcl.net/downloads/$_HMCL_DOWNLOAD_PAGE_OS/$_HMCL_HMCL_ARCH.html" 1>&2 - echo "You can visit the https://docs.hmcl.net/help.html page for help." 1>&2 + show_message "Error" "The Java runtime environment is required to run HMCL.\nPlease install Java and set the environment variables and try again.\nhttps://docs.hmcl.net/downloads/$_HMCL_DOWNLOAD_PAGE_OS/$_HMCL_ARCH.html\nYou can visit the https://docs.hmcl.net/help.html page for help." fi ;; *) if [ "$_HMCL_USE_CHINESE" == true ]; then - echo "运行 HMCL 需要 Java 运行时环境,请安装 Java 并设置环境变量后重试。" 1>&2 - echo "你可以访问 https://docs.hmcl.net/help.html 页面寻求帮助。" 1>&2 + show_message "错误" "运行 HMCL 需要 Java 运行时环境,请安装 Java 并设置环境变量后重试。\n你可以访问 https://docs.hmcl.net/help.html 页面寻求帮助。" else - echo "The Java runtime environment is required to run HMCL. " 1>&2 - echo "Please install Java and set the environment variables and try again." 1>&2 - echo "You can visit the https://docs.hmcl.net/help.html page for help." 1>&2 + show_message "Error" "The Java runtime environment is required to run HMCL.\nPlease install Java and set the environment variables and try again.\nYou can visit the https://docs.hmcl.net/help.html page for help." fi ;; esac From e3dbf1c389b3793f82e0daa2698827d434cb22fc Mon Sep 17 00:00:00 2001 From: Glavo Date: Sun, 6 Oct 2024 23:13:49 +0800 Subject: [PATCH 2/2] update --- HMCL/src/main/resources/assets/HMCLauncher.sh | 59 +++++++++++-------- 1 file changed, 35 insertions(+), 24 deletions(-) diff --git a/HMCL/src/main/resources/assets/HMCLauncher.sh b/HMCL/src/main/resources/assets/HMCLauncher.sh index a42a2cc258..df62bd25d2 100644 --- a/HMCL/src/main/resources/assets/HMCLauncher.sh +++ b/HMCL/src/main/resources/assets/HMCLauncher.sh @@ -2,18 +2,6 @@ set -e -# Function to show GUI message -show_message() { - local title="$1" - local message="$2" - echo -e "$title: ""$message" - if command -v zenity > /dev/null; then - zenisty --info --title="$title" --text="$message" --width=400 --height=200 - elif command -v kdialog > /dev/null; then - kdialog --title "$title" --msgbox "$message" - fi -} - # Switch message language if [ -z "${LANG##zh_*}" ]; then _HMCL_USE_CHINESE=true @@ -134,19 +122,42 @@ fi case "$_HMCL_OS-$_HMCL_ARCH" in windows-x86|windows-x86_64|windows-arm64|linux-x86|linux-x86_64|linux-arm32|linux-arm64|linux-loongarch64|macos-x86_64|macos-arm64) - if [ "$_HMCL_USE_CHINESE" == true ]; then - show_message "错误" "运行 HMCL 需要 Java 运行时环境,请安装 Java 并设置环境变量后重试。\n\nhttps://docs.hmcl.net/downloads/$_HMCL_DOWNLOAD_PAGE_OS/$_HMCL_ARCH.html\n\n你可以访问 https://docs.hmcl.net/help.html 页面寻求帮助。" - else - show_message "Error" "The Java runtime environment is required to run HMCL.\nPlease install Java and set the environment variables and try again.\nhttps://docs.hmcl.net/downloads/$_HMCL_DOWNLOAD_PAGE_OS/$_HMCL_ARCH.html\nYou can visit the https://docs.hmcl.net/help.html page for help." - fi - ;; - *) - if [ "$_HMCL_USE_CHINESE" == true ]; then - show_message "错误" "运行 HMCL 需要 Java 运行时环境,请安装 Java 并设置环境变量后重试。\n你可以访问 https://docs.hmcl.net/help.html 页面寻求帮助。" - else - show_message "Error" "The Java runtime environment is required to run HMCL.\nPlease install Java and set the environment variables and try again.\nYou can visit the https://docs.hmcl.net/help.html page for help." - fi + _HMCL_JAVA_DOWNLOAD_PAGE="https://docs.hmcl.net/downloads/$_HMCL_DOWNLOAD_PAGE_OS/$_HMCL_ARCH.html" ;; esac +if [ "$_HMCL_USE_CHINESE" == true ]; then + _HMCL_WARNING_TITLE="错误" + _HMCL_WARNING_MESSAGE_BASE="运行 HMCL 需要 Java 运行时环境,请安装 Java 并设置环境变量后重试。" + _HMCL_WARNING_MESSAGE1="$_HMCL_WARNING_MESSAGE_BASE\n你可以前往此处下载:\n$_HMCL_JAVA_DOWNLOAD_PAGE" + _HMCL_WARNING_MESSAGE2="$_HMCL_WARNING_MESSAGE_BASE\n\n是否要前往 Java 下载页面?" + _HMCL_WARNING_MESSAGE3="$_HMCL_WARNING_MESSAGE_BASE\n你可以访问 https://docs.hmcl.net/help.html 页面寻求帮助。" +else + _HMCL_WARNING_TITLE="Error" + _HMCL_WARNING_MESSAGE_BASE="The Java runtime environment is required to run HMCL.\nPlease install Java and set the environment variables and try again." + _HMCL_WARNING_MESSAGE1="$_HMCL_WARNING_MESSAGE_BASE\nYou can download it from here:\n$_HMCL_JAVA_DOWNLOAD_PAGE" + _HMCL_WARNING_MESSAGE2="$_HMCL_WARNING_MESSAGE_BASE\n\nDo you want to go to the Java download page?" + _HMCL_WARNING_MESSAGE3="$_HMCL_WARNING_MESSAGE_BASE\nYou can visit the https://docs.hmcl.net/help.html page for help." +fi + +if [ -n "$_HMCL_JAVA_DOWNLOAD_PAGE" ]; then + echo -e "$_HMCL_WARNING_TITLE: $_HMCL_WARNING_MESSAGE1" + + if [ -n "$(command -v xdg-open)" ]; then + if [ -n "$(command -v zenity)" ]; then + zenity --question --title="$_HMCL_WARNING_TITLE" --text="$_HMCL_WARNING_MESSAGE2" + elif [ -n "$(command -v kdialog)" ]; then + kdialog --title "$_HMCL_WARNING_TITLE" --warningyesno "$_HMCL_WARNING_MESSAGE2" + fi + xdg-open "$_HMCL_JAVA_DOWNLOAD_PAGE" + fi +else + echo -e "$_HMCL_WARNING_TITLE: $_HMCL_WARNING_MESSAGE3" + if [ -n "$(command -v zenity)" ]; then + zenity --info --title="$_HMCL_WARNING_TITLE" --text="$_HMCL_WARNING_MESSAGE3" + elif [ -n "$(command -v kdialog)" ]; then + kdialog --title "$_HMCL_WARNING_TITLE" --msgbox "$_HMCL_WARNING_MESSAGE3" + fi +fi + exit 1