Skip to content

Commit 51d17f1

Browse files
committed
refactor(scripts): 优化模块脚本并补全标准注释
性能与健壮性: - config.sh: strip_quotes 改纯参数展开,read_conf 减少子进程调用 - config.sh: set_conf 改为 awk 原子写入,规避 sed 元字符注入 - nodes.sh: detect_outbound_tag 合并为单次 sed 调用 - runtime.sh: 修正 $'\t'/$'\n' 写法,移除 ls|wc 计数 - service.sh: 启动前增加 require_cmds 依赖检查 - subscription.sh/cli: 临时文件加 PID 后缀并注册 trap 清理,避免并发冲突 bug 修复: - customize.sh: 修正先读后解压导致首次安装版本号显示"未知" 可读性: - customize.sh: 抽取 wait_volume_key 复用音量键轮询逻辑 - 为全部脚本补全文件头/函数/逻辑块/全局变量标准注释
1 parent 81c6c40 commit 51d17f1

16 files changed

Lines changed: 1150 additions & 312 deletions

File tree

src/module/action.sh

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,37 @@
11
#!/system/bin/sh
2-
# NetProxy 模块操作脚本
3-
# 用于模块管理器中的操作按钮
2+
#######################################
3+
# 文件: action.sh
4+
# 功能: 模块管理器中的操作按钮入口,根据 sing-box 当前运行状态
5+
# 一键切换:运行中则停止,未运行则启动。
6+
# 用法: 由 Magisk/KernelSU/APatch 管理器点击模块操作按钮时调用。
7+
# 依赖: common.sh、scripts/core/service.sh。
8+
#######################################
49

5-
readonly MODDIR="${0%/*}"
6-
readonly SERVICE_SCRIPT="$MODDIR/scripts/core/service.sh"
7-
readonly LOG_FILE="$MODDIR/logs/service.log"
8-
readonly SING_BOX_BIN="$MODDIR/bin/sing-box"
10+
# 模块根目录与关键路径
11+
readonly MODDIR="${0%/*}" # 模块根目录 (脚本所在目录)
12+
readonly SERVICE_SCRIPT="$MODDIR/scripts/core/service.sh" # 服务管理脚本
13+
readonly LOG_FILE="$MODDIR/logs/service.log" # 服务日志
14+
readonly SING_BOX_BIN="$MODDIR/bin/sing-box" # sing-box 二进制
915

1016
. "$MODDIR/scripts/utils/common.sh"
1117

1218
#######################################
13-
# 检查 sing-box 是否运行
19+
# 检查 sing-box 是否正在运行
20+
# 参数: 无
21+
# 返回: 0=运行中,非 0=未运行
1422
#######################################
1523
is_sing_box_running() {
1624
pidof -s "$SING_BOX_BIN" > /dev/null 2>&1
1725
}
1826

19-
# 将输出交给模块管理器显示
27+
# 将 stderr 合并到 stdout,使日志在管理器界面中可见
2028
exec 2>&1
2129

2230
echo "==================================="
2331
echo " NetProxy 模块操作 "
2432
echo "==================================="
2533

26-
# 根据当前状态执行启动或停止
34+
# 运行中则停止,未运行则启动
2735
if is_sing_box_running; then
2836
log "INFO" "检测到 sing-box 正在运行,准备执行停止操作..."
2937
sh "$SERVICE_SCRIPT" stop
@@ -38,5 +46,5 @@ else
3846
echo "==================================="
3947
fi
4048

41-
# 短暂休眠以确保日志显示完整再退出
49+
# 短暂停留,确保日志完整显示后再退出
4250
sleep 1

0 commit comments

Comments
 (0)