Update settings.ini add notify function (#91)

* 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
This commit is contained in:
Xing
2024-02-08 21:22:26 +08:00
committed by GitHub
parent c6c305445d
commit d00f4de002
2 changed files with 16 additions and 2 deletions

View File

@@ -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."

View File

@@ -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
}