diff --git a/box/scripts/box.service b/box/scripts/box.service index 56f1868..4f54836 100755 --- a/box/scripts/box.service +++ b/box/scripts/box.service @@ -453,15 +453,8 @@ start_box() { detected_port still_alive display_bin_pid - # Open the yacd in browser - if [ "${bin_name}" = "clash" ] && [ "${display_yacd_on_start}" = "true" ]; then - sleep 0.5 - ip_port=$(busybox awk '/external-controller:/ {print $2}' "${clash_config}") - # permission denied if run through Magisk/KernelSu Manager - if [ -t 1 ]; then - am start -a android.intent.action.VIEW -d "http://${ip_port}/ui" - fi - fi + # open the yacd in browser + open_yacd } stop_box() { diff --git a/box/scripts/box.tool b/box/scripts/box.tool index d7931ed..086b5ca 100755 --- a/box/scripts/box.tool +++ b/box/scripts/box.tool @@ -84,7 +84,7 @@ update_yq() { "x86_64") arch="amd64"; platform="linux" ;; *) log warn "Unsupported architecture: $(uname -m)" >&2; exit 1 ;; esac - # if you use yq build linux it will error (cmd: mkdir /tmp permission denied), when using cron job + # If you use yq_linux, an error will occur (cmd: mkdir /tmp permission denied) when using a cron job. download_link="https://github.com/$(if [ "${flag}" = "true" ]; then echo "memcyo/yq/releases/download/yq/yq"; else echo "mikefarah/yq/releases/latest/download/yq_${platform}_${arch}"; fi)" log debug "Download ${download_link}" update_file "${data_dir}/bin/yq" "${download_link}" @@ -400,7 +400,7 @@ cgroup_limit() { # Check and update yacd update_dashboard() { # su -c /data/adb/box/scripts/box.tool upyacd - if [ "${bin_name}" = "sing-box" ] || [ "${bin_name}" = "clash" ]; then + if [ "${bin_name}" = "clash" -o "${bin_name}" = "sing-box" ]; then file_dashboard="${data_dir}/${bin_name}/dashboard.zip" rm -rf "${data_dir}/${bin_name}/dashboard" if [ ! -d "${data_dir}/${bin_name}/dashboard" ]; then @@ -413,19 +413,25 @@ update_dashboard() { fi dir_name="Yacd-meta-gh-pages" log debug "Download ${url}" - busybox wget --no-check-certificate "${url}" -O "${file_dashboard}" >&2 || { log error "Failed to download $url"; exit 1; } - unzip_command="$(command -v unzip >/dev/null 2>&1 ; echo $?)" - if [ $unzip_command -eq 0 ]; then - unzip_command="unzip" + if busybox wget --no-check-certificate "${url}" -O "${file_dashboard}" >&2; then + unzip_command="$(command -v unzip >/dev/null 2>&1 ; echo $?)" + if [ $unzip_command -eq 0 ]; then + unzip_command="unzip" + else + unzip_command="busybox unzip" + fi + $unzip_command -o "${file_dashboard}" "${dir_name}/*" -d "${data_dir}/${bin_name}/dashboard" >&2 + mv -f "${data_dir}/${bin_name}/dashboard/$dir_name"/* "${data_dir}/${bin_name}/dashboard/" + rm -f "${file_dashboard}" + rm -rf "${data_dir}/${bin_name}/dashboard/${dir_name}" else - unzip_command="busybox unzip" + log error "Failed to download $url" >&2 + return 1 fi - ${unzip_command} -o "${file_dashboard}" "${dir_name}/*" -d "${data_dir}/${bin_name}/dashboard" >&2 - mv -f "${data_dir}/${bin_name}/dashboard/$dir_name"/* "${data_dir}/${bin_name}/dashboard" - rm -f "${file_dashboard}" - rm -r "${data_dir}/${bin_name}/dashboard/${dir_name}" + return 0 else log debug "${bin_name} does not support dashboards" + return 1 fi } @@ -498,7 +504,10 @@ case "$1" in update_yq ;; upyacd) - update_dashboard + if update_dashboard; then + sleep 0.75 + (busybox pidof "${bin_name}" >/dev/null 2>&1) && open_yacd + fi ;; upcore) update_kernel @@ -517,6 +526,9 @@ case "$1" in if [ -f "${pid_file}" ] && [ "${flag}" = "true" ]; then restart_box fi + else + sleep 0.75 + (busybox pidof "${bin_name}" >/dev/null 2>&1) && open_yacd fi ;; subs) @@ -524,6 +536,9 @@ case "$1" in if [ -f "${pid_file}" ] && [ "${flag}" = "true" ]; then restart_box fi + else + sleep 0.75 + (busybox pidof "${bin_name}" >/dev/null 2>&1) && open_yacd fi ;; geosub) diff --git a/box/settings.ini b/box/settings.ini index 1a88573..96d2c59 100755 --- a/box/settings.ini +++ b/box/settings.ini @@ -38,7 +38,7 @@ proxy_mode="blacklist" packages_list=() # Display AP info by typing "ifconfig" in terminal -ap_list=( "wlan+" "rndis+" ) +ap_list=( "ap+" "wlan+" "rndis+" ) # Ignore AP in the out list ignore_out_list=() @@ -72,7 +72,6 @@ system_packages_file="/data/system/packages.list" uid_list=("/data/adb/box/run/appuid.list") # clash configuration -display_yacd_on_start="false" name_clash_config="config.yaml" clash_config="${data_dir}/clash/${name_clash_config}" # provide @@ -98,4 +97,18 @@ log() { # Print messages to a log file echo "${message}" >> ${logs_file} 2>&1 fi +} + +# open yacd on start +display_yacd_on_start="false" +open_yacd () { + if [ "${bin_name}" = "clash" -o "${bin_name}" = "sing-box" ] && [ "${display_yacd_on_start}" = "true" ]; then + sleep 0.5 + ip_port=$(busybox awk '/external-controller:/ {print $2}' "${clash_config}") + if [ -t 1 ]; then + # "cmd: Failure calling service activity: Failed transaction" if run through Magisk/KernelSu Manager, + # this is normal if run in terminal/termux + am start -a android.intent.action.VIEW -d "http://${ip_port}/ui" + fi + fi } \ No newline at end of file