From d00f4de002e33d5f43db5bf288def93e1ea6d044 Mon Sep 17 00:00:00 2001 From: Xing Date: Thu, 8 Feb 2024 21:22:26 +0800 Subject: [PATCH] Update settings.ini add notify function (#91) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Update settings.ini add notify function Add a function to show run information using system notifications or xposed edge app。 * Update box.service add notify show start/stop status --- box/scripts/box.service | 4 ++-- box/settings.ini | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/box/scripts/box.service b/box/scripts/box.service index c29a0f7..34e19c8 100755 --- a/box/scripts/box.service +++ b/box/scripts/box.service @@ -455,7 +455,7 @@ box_bin_status() { stack=$(if [ "${bin_name}" != "clash" ]; then find "/data/adb/box/sing-box" -type f -name "*.json" -exec busybox awk -F'"' '/"stack"/{print $4}' {} +; else busybox awk '!/^ *#/ && /stack: / { print $2;found=1; exit}' "${clash_config}"; fi) - log Info "${bin_name} service is running." + TOAST=1 log Info "${bin_name} service is running." log Info "proxy: ${proxy_mode} | $(if [ "${proxy_mode}" != "tun" ]; then echo network: ${network_mode}; fi) | $(if [[ "${proxy_mode}" == "tun" || ${network_mode} == "mixed" ]]; then echo stack: ${stack}; fi)" # Get the memory usage of the binary @@ -633,7 +633,7 @@ stop_box() { rm -f "${box_pid}" fi log Warning "${bin_name} shutting down, service is stopped." - log Warning "${bin_name} disconnected." + TOAST=1 log Warning "${bin_name} disconnected." [ -t 1 ] && echo -e "${white}--------------------------------------------${normal}" else log Warning "${bin_name} Not stopped; may still be shutting down or failed to shut down." diff --git a/box/settings.ini b/box/settings.ini index 6392b3b..497e9ea 100755 --- a/box/settings.ini +++ b/box/settings.ini @@ -117,6 +117,15 @@ green="\033[1;32m" yellow="\033[1;33m" blue="\033[1;34m" +# eg: notify $title $content +notify() { + # using Xposed edge app toast + am start -a android.intent.action.VIEW -n com.jozein.xedgepro/.ui.ActivityPerformAction --ei __0 111 --es __1 "$2" + + # using system notification + #su -lp "2000" -c "cmd notification post -S messaging --conversation '$1' --message '$1':'$2' 'Tag' '$(echo $RANDOM)' " >/dev/null 2>&1 +} + log() { # Selects the text color according to the parameters case $1 in @@ -134,4 +143,9 @@ log() { # Print messages to a log file echo "${message}" >> ${box_log} 2>&1 fi + + if [[ $TOAST ]]; then + notify "box_for_root" "${message}" + fi + }