Skip to content

Commit

Permalink
Update settings.ini add notify function (#91)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
cxyzzz committed Feb 8, 2024
1 parent c6c3054 commit d00f4de
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions box/scripts/box.service
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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."
Expand Down
14 changes: 14 additions & 0 deletions box/settings.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

}

0 comments on commit d00f4de

Please sign in to comment.