refactor(config): 配置文件改为单文件 JSON

This commit is contained in:
YuleBest committed 2026-04-09 08:11:37 +08:00
1 parent 74f37460b4
commit 6a4db6d9c1
23 files changed
+782 -256

No files matched your search

+37 -3
View File
@@ -3,13 +3,47 @@
# LuminPro 手动提升/恢复亮度触发脚本
# 解析模块工作目录
MODDIR="$(dirname "$(readlink -f "$0")")"
CONFIG_DIR="$MODDIR/config"
PATH_CONFIG_DIR="$CONFIG_DIR/path"
CONFIG_FILE="$MODDIR/config/config.json"
JQ="$MODDIR/bin/jq"
PID_DIR="$MODDIR/pid"
BOOST_FLAG="$PID_DIR/boost.flag"
DEFAULT_NOW_BRI_FILE="/sys/class/backlight/panel0-backlight/brightness"
get_cfg() {
local key="$1" default="$2"
local val
if val=$("$JQ" -re ".${key}" "$CONFIG_FILE" 2>/dev/null); then
echo "$val"
else
echo "$default"
fi
}
now_bri_file="$(get_cfg now_bri_file "$DEFAULT_NOW_BRI_FILE")"
if [ ! -f "$now_bri_file" ]; then
exit 1
fi
if [ -f "$BOOST_FLAG" ]; then
restore_bri="$(cat "$BOOST_FLAG" 2>/dev/null | tr -d ' \n')"
[ -n "$restore_bri" ] && echo -n "$restore_bri" >"$now_bri_file" 2>/dev/null
rm -f "$BOOST_FLAG"
else
max_bri="$(get_cfg max_bri '')"
if [ -z "$max_bri" ] || [ "$max_bri" = "0" ]; then
exit 1
fi
now_bri="$(cat "$now_bri_file" 2>/dev/null | tr -d ' \n')"
mkdir -p "$PID_DIR"
echo -n "$now_bri" >"$BOOST_FLAG"
echo -n "$max_bri" >"$now_bri_file" 2>/dev/null
fi
exit 0
# 默认设备路径
DEFAULT_NOW_BRI_FILE="/sys/class/backlight/panel0-backlight/brightness"
-1
View File
@@ -1 +0,0 @@
1
View File
Whitespace-only changes.
+13
View File
@@ -0,0 +1,13 @@
{
"ui_max_bri": 0,
"max_bri": 0,
"steps_num": 50,
"log_max_size": 512,
"auto_bri_sleep": 1,
"display_hdr_sleep": 0,
"sleep_time": "",
"inotify_events": "c",
"now_bri_file": "/sys/class/backlight/panel0-backlight/brightness",
"max_bri_file": "/sys/class/backlight/panel0-backlight/max_brightness",
"blacklist_apps": []
}
-1
View File
@@ -1 +0,0 @@
1
-1
View File
@@ -1 +0,0 @@
512
View File
Whitespace-only changes.
-1
View File
@@ -1 +0,0 @@
/sys/class/backlight/panel0-backlight/max_brightness
-1
View File
@@ -1 +0,0 @@
/sys/class/backlight/panel0-backlight/brightness
View File
Whitespace-only changes.
-1
View File
@@ -1 +0,0 @@
50
View File
Whitespace-only changes.
+371 -3
View File
@@ -1,14 +1,382 @@
#!/system/bin/sh
#shellcheck shell=ash
# 默认设备路径(如果路径配置不存在)
# ==========================
# ARM64 架构检查
# ==========================
ARCH=$(getprop ro.product.cpu.abi)
if [ "$ARCH" != "arm64-v8a" ]; then
ui_print "********************************"
ui_print " 本模块仅支持 ARM64 设备!"
ui_print " 当前架构: $ARCH"
ui_print "********************************"
abort "不支持的架构: $ARCH"
fi
# 默认设备路径
DEFAULT_NOW_BRI_FILE="/sys/class/backlight/panel0-backlight/brightness"
DEFAULT_MAX_BRI_FILE="/sys/class/backlight/panel0-backlight/max_brightness"
mod_config="$MODPATH/config"
mod_path_config="$mod_config/path"
old_config="/data/adb/modules/LuminPro/config"
old_path_config="/data/adb/modules/LuminPro/config/path"
# jq 二进制(已随模块提取)
JQ="$MODPATH/bin/jq"
CONFIG_FILE="$mod_config/config.json"
mkdir -p "$mod_config"
chmod 755 "$JQ" 2>/dev/null
# ==========================
# 工具函数
# ==========================
# 从当前 config.json 读取字段值
cfg_get() {
local key="$1" default="$2"
local val
if val=$("$JQ" -re ".${key}" "$CONFIG_FILE" 2>/dev/null); then
echo "$val"
else
echo "$default"
fi
}
# 从旧 txt 文件读取值(迁移用)
read_old_txt() {
local file="$old_config/$1"
local default="$2"
if [ -f "$file" ]; then
local val
val="$(cat "$file" 2>/dev/null | tr -d ' \n')"
[ -n "$val" ] && echo "$val" || echo "$default"
else
echo "$default"
fi
}
# 用 cfg_* 变量写入 config.json
write_config_json() {
"$JQ" -n \
--arg ui_max_bri "${cfg_ui_max_bri:-0}" \
--arg max_bri "${cfg_max_bri:-0}" \
--arg steps_num "${cfg_steps_num:-50}" \
--arg log_max_size "${cfg_log_max_size:-512}" \
--arg auto_bri_sleep "${cfg_auto_bri_sleep:-1}" \
--arg display_hdr_sleep "${cfg_display_hdr_sleep:-0}" \
--arg sleep_time "${cfg_sleep_time:-}" \
--arg inotify_events "${cfg_inotify_events:-c}" \
--arg now_bri_file "${cfg_now_bri_file:-$DEFAULT_NOW_BRI_FILE}" \
--arg max_bri_file "${cfg_max_bri_file:-$DEFAULT_MAX_BRI_FILE}" \
--argjson blacklist_apps "${cfg_blacklist_apps:-[]}" \
'{
ui_max_bri: ($ui_max_bri | tonumber),
max_bri: ($max_bri | tonumber),
steps_num: ($steps_num | tonumber),
log_max_size: ($log_max_size | tonumber),
auto_bri_sleep: ($auto_bri_sleep | tonumber),
display_hdr_sleep: ($display_hdr_sleep | tonumber),
sleep_time: $sleep_time,
inotify_events: $inotify_events,
now_bri_file: $now_bri_file,
max_bri_file: $max_bri_file,
blacklist_apps: $blacklist_apps
}' >"$CONFIG_FILE"
}
# ==========================
# 安装流程函数
# ==========================
btn() {
while :; do
local c
c="$(getevent -qlc 1 | awk '{ print $3 }')"
case "$c" in
KEY_VOLUMEUP)
echo "0"
return
;;
KEY_VOLUMEDOWN)
echo "1"
return
;;
esac
done
}
SHOW_CHANGELOG() {
local f="$MODPATH/changelog.md"
[ -f "$f" ] || return
echo "========================================"
echo "[*] 本次更新日志:"
awk '/^## / { if (p) exit; p=1; print; next } p { print }' "$f"
echo "========================================"
}
NOTE() {
cat "$MODPATH/NOTE.txt"
echo ""
echo "[i] 按音量 + 进入下一步, 按音量 - 退出"
echo "[i] 继续则表明你已理解并接受所有风险"
[ "$(btn)" = "0" ] && echo "[OK] 已确认" || abort "[X] 已退出"
}
CHECK_FILES() {
sleep 1
now_bri_file="$(cfg_get now_bri_file "$DEFAULT_NOW_BRI_FILE")"
max_bri_file="$(cfg_get max_bri_file "$DEFAULT_MAX_BRI_FILE")"
echo ""
echo "[*] 正在验证设备亮度节点..."
echo "- 当前亮度节点: $now_bri_file"
echo "- 最大亮度节点: $max_bri_file"
echo ""
if [ -f "$now_bri_file" ] && [ -f "$max_bri_file" ]; then
echo "[OK] 找到亮度节点文件"
else
[ ! -f "$now_bri_file" ] && echo "[X] 当前亮度节点不存在: $now_bri_file"
[ ! -f "$max_bri_file" ] && echo "[X] 最大亮度节点不存在: $max_bri_file"
echo ""
echo "设备不支持默认路径,刷入后请通过 Web UI 手动配置亮度节点"
echo "查找路径: find /sys -name '*brightness*' 2>/dev/null"
abort "[X] 安装中止:无法找到设备亮度节点"
fi
echo "[OK] 当前亮度: $(cat "$now_bri_file")"
echo "[OK] 系统最大亮度: $(cat "$max_bri_file")"
}
TEST_UI_MAX_BRI() {
echo ""
echo "[*] 开始测试前台最大亮度"
echo ""
sleep 1
echo "======== 请关闭自动亮度 ========"
echo "[i] 按音量 + 进入下一步, 按音量 - 退出"
[ "$(btn)" = "0" ] && echo "[OK] 已确认" || abort "[X] 已退出"
local restore_bri
restore_bri="$(cat "$now_bri_file")"
echo ""
sleep 1
echo "======== 请将屏幕亮度调至最大 ========"
echo "[i] 按音量 + 进入下一步, 按音量 - 退出"
[ "$(btn)" = "0" ] && echo "[OK] 已确认" || abort "[X] 已退出"
local measured_ui measured_max
measured_ui="$(cat "$now_bri_file")"
measured_max="$(cat "$max_bri_file")"
echo "[OK] 前台最大亮度: [ $measured_ui ]"
echo "[i] 峰值最大亮度由节点文件获得: [ $measured_max ]"
echo "[i] 若不符合预期,请稍后到 Web UI 更改"
# 写入 JSON
"$JQ" ".ui_max_bri = ($measured_ui | tonumber) | .max_bri = ($measured_max | tonumber)" \
"$CONFIG_FILE" >"$CONFIG_FILE.tmp" && mv "$CONFIG_FILE.tmp" "$CONFIG_FILE"
echo ""
echo "[OK] 测试完成"
echo "[*] 正在恢复亮度..."
echo -n "$restore_bri" >"$now_bri_file"
}
# 导入旧配置(支持 JSON 格式和旧 txt 格式)
IMPORT_OLD_CONFIG() {
# 1. 已有 JSON 格式
if [ -f "$old_config/config.json" ]; then
local old_ui
old_ui=$("$JQ" -re '.ui_max_bri' "$old_config/config.json" 2>/dev/null || echo "0")
if [ "${old_ui:-0}" -gt 0 ] 2>/dev/null; then
echo ""
sleep 1
echo "[i] 检测到已有 JSON 配置:"
echo " - 前台最大亮度: $old_ui"
echo " - 峰值最大亮度: $("$JQ" -re '.max_bri' "$old_config/config.json" 2>/dev/null)"
local old_st
old_st=$("$JQ" -re '.sleep_time // empty' "$old_config/config.json" 2>/dev/null)
[ -n "$old_st" ] && echo " - 休眠时间: $old_st"
echo ""
echo "[?] 按音量 + 沿用旧配置, 按音量 - 重新测试"
if [ "$(btn)" = "0" ]; then
cp -f "$old_config/config.json" "$CONFIG_FILE"
echo "[OK] 已导入 JSON 配置"
return 0
else
echo "[*] 将重新测试"
return 1
fi
fi
return 1
fi
# 2. 旧 txt 格式迁移
if [ -d "$old_config" ] && [ -s "$old_config/ui_max_bri.txt" ] && [ -s "$old_config/max_bri.txt" ]; then
echo ""
sleep 1
echo "[i] 检测到旧格式配置,将迁移至 JSON:"
echo " - 前台最大亮度: $(cat "$old_config/ui_max_bri.txt")"
echo " - 峰值最大亮度: $(cat "$old_config/max_bri.txt")"
[ -s "$old_config/sleep_time.txt" ] && echo " - 休眠时间: $(cat "$old_config/sleep_time.txt")"
[ -s "$old_config/auto_bri_sleep.txt" ] && echo " - 自动亮度时休眠: $(cat "$old_config/auto_bri_sleep.txt" | sed 's/1/开启/;s/0/关闭/')"
[ -s "$old_config/steps_num.txt" ] && echo " - 亮度步数: $(cat "$old_config/steps_num.txt")"
[ -s "$old_config/log_max_size.txt" ] && echo " - 日志限制: $(cat "$old_config/log_max_size.txt") KB"
[ -s "$old_config/blacklist_apps.txt" ] && echo " - 黑名单: $(wc -l <"$old_config/blacklist_apps.txt" | tr -d ' ') 个"
echo ""
echo "[?] 按音量 + 沿用旧配置, 按音量 - 重新测试"
if [ "$(btn)" = "0" ]; then
cfg_ui_max_bri="$(read_old_txt ui_max_bri.txt '0')"
cfg_max_bri="$(read_old_txt max_bri.txt '0')"
cfg_steps_num="$(read_old_txt steps_num.txt '50')"
cfg_log_max_size="$(read_old_txt log_max_size.txt '512')"
cfg_auto_bri_sleep="$(read_old_txt auto_bri_sleep.txt '1')"
cfg_display_hdr_sleep="$(read_old_txt display_hdr_sleep.txt '0')"
cfg_sleep_time="$(read_old_txt sleep_time.txt '')"
cfg_inotify_events="$(read_old_txt inotify_events.txt 'c')"
cfg_now_bri_file="$(read_old_txt path/now_bri_file.txt "$DEFAULT_NOW_BRI_FILE")"
cfg_max_bri_file="$(read_old_txt path/max_bri_file.txt "$DEFAULT_MAX_BRI_FILE")"
# 黑名单转 JSON 数组
if [ -s "$old_config/blacklist_apps.txt" ]; then
cfg_blacklist_apps=$("$JQ" -Rs 'split("\n") | map(select(length > 0))' \
"$old_config/blacklist_apps.txt" 2>/dev/null || echo '[]')
else
cfg_blacklist_apps='[]'
fi
write_config_json
# 删除旧 txt 配置文件
rm -f "$old_config/"*.txt 2>/dev/null
rm -rf "$old_config/path" 2>/dev/null
echo "[OK] 配置已迁移至 JSON,旧文件已清理"
return 0
else
echo "[*] 将重新测试"
return 1
fi
fi
return 1
}
# 初始化默认配置
INIT_CONFIG() {
mkdir -p "$mod_config"
if [ ! -f "$CONFIG_FILE" ]; then
cfg_ui_max_bri=0
cfg_max_bri=0
cfg_steps_num=50
cfg_log_max_size=512
cfg_auto_bri_sleep=1
cfg_display_hdr_sleep=0
cfg_sleep_time=""
cfg_inotify_events="c"
cfg_now_bri_file="$DEFAULT_NOW_BRI_FILE"
cfg_max_bri_file="$DEFAULT_MAX_BRI_FILE"
cfg_blacklist_apps="[]"
write_config_json
fi
}
# 补全缺失字段
ENSURE_DEFAULTS() {
"$JQ" '
.steps_num = (.steps_num // 50) |
.log_max_size = (.log_max_size // 512) |
.auto_bri_sleep = (.auto_bri_sleep // 1) |
.display_hdr_sleep = (.display_hdr_sleep // 0) |
.sleep_time = (.sleep_time // "") |
.inotify_events = (.inotify_events // "c") |
.blacklist_apps = (.blacklist_apps // [])
' "$CONFIG_FILE" >"$CONFIG_FILE.tmp" && mv "$CONFIG_FILE.tmp" "$CONFIG_FILE"
}
# 机型兼容性校验
CHECK_DEVICE_COMPATIBILITY() {
local model prefix
model="$(getprop ro.product.model)"
prefix="$(echo "$model" | cut -c 1-9)"
if [ "$prefix" = "25128PNA1" ] || [ "$prefix" = "2512BPNDA" ]; then
echo ""
echo "[!] 您可能是 Xiaomi 17 Ultra 用户,建议使用 '0' 事件作为监测对象"
echo "[?] 是否将 inotifyd 监测事件修改为 '0'? (音量 + 确认,音量 - 跳过)"
if [ "$(btn)" = "0" ]; then
"$JQ" '.inotify_events = "0"' "$CONFIG_FILE" >"$CONFIG_FILE.tmp" && mv "$CONFIG_FILE.tmp" "$CONFIG_FILE"
echo "[OK] 已设置为 0 事件监测"
else
echo "[*] 已跳过"
fi
sleep 1
fi
}
# 创建备份(供 WebUI 恢复默认用)
CREATE_BACKUP() {
mkdir -p "$mod_config/.backup"
cp -f "$CONFIG_FILE" "$mod_config/.backup/config.json"
}
END() {
echo ""
sleep 1
# 确保 now_bri_file / max_bri_file 已设置(import 路径可能未调用 CHECK_FILES)
: "${now_bri_file:=$(cfg_get now_bri_file "$DEFAULT_NOW_BRI_FILE")}"
: "${max_bri_file:=$(cfg_get max_bri_file "$DEFAULT_MAX_BRI_FILE")}"
local final_ui final_max
final_ui=$("$JQ" -re 'if .ui_max_bri > 0 then .ui_max_bri else empty end' "$CONFIG_FILE" 2>/dev/null)
final_max=$("$JQ" -re 'if .max_bri > 0 then .max_bri else empty end' "$CONFIG_FILE" 2>/dev/null)
if [ -z "$final_max" ] || [ -z "$final_ui" ]; then
echo ""
echo "[!] ======== 配置不完整 ========"
[ -z "$final_max" ] && echo "[X] 峰值最大亮度: 未配置" || echo "[OK] 峰值最大亮度: $final_max"
[ -z "$final_ui" ] && echo "[X] 前台最大亮度: 未配置" || echo "[OK] 前台最大亮度: $final_ui"
echo ""
echo "[i] 配置缺失,请重启后通过 Web UI 手动配置"
echo "[i] 或按音量 + 现在进行测试, 按音量 - 跳过"
if [ "$(btn)" = "0" ]; then
TEST_UI_MAX_BRI
final_ui=$("$JQ" -re 'if .ui_max_bri > 0 then .ui_max_bri else empty end' "$CONFIG_FILE" 2>/dev/null)
final_max=$("$JQ" -re 'if .max_bri > 0 then .max_bri else empty end' "$CONFIG_FILE" 2>/dev/null)
fi
fi
echo ""
echo "======== 模块策略 ========"
echo "[*] 当亮度达到 [ $final_ui ] 时,自动提升至 [ $final_max ]"
echo "[i] 配置文件: /data/adb/modules/LuminPro/config/config.json"
echo "[i] 也可以使用 Web UI 进行配置"
echo ""
echo "[OK] 模块已刷入,请重启手机"
echo "[i] 感谢您的使用"
echo "[i] 作者: 酷安 @于乐yule"
echo ""
sleep 1
exit 0
}
MAIN() {
NOTE
SHOW_CHANGELOG
if ! IMPORT_OLD_CONFIG; then
INIT_CONFIG
CHECK_FILES
TEST_UI_MAX_BRI
fi
ENSURE_DEFAULTS
CHECK_DEVICE_COMPATIBILITY
CREATE_BACKUP
END
}
MAIN
# 创建配置目录
[ -d "$mod_config" ] || mkdir -p "$mod_config"
+12 -29
View File
@@ -2,57 +2,48 @@
#shellcheck shell=ash
# LuminPro 守护进程
# 使用 readlink 获取脚本真实绝对路径
REAL_PATH="$(readlink -f "$0")"
SCRIPT_DIR="$(dirname "$REAL_PATH")"
MODDIR="$(dirname "$SCRIPT_DIR")"
PID_DIR="$MODDIR/pid"
CONFIG_DIR="$MODDIR/config"
PATH_CONFIG_DIR="$CONFIG_DIR/path"
CONFIG_FILE="$MODDIR/config/config.json"
JQ="$MODDIR/bin/jq"
pid_file="$PID_DIR/inotifyd.pid"
stop_file="$PID_DIR/stop.flag"
pause_file="$PID_DIR/daemon.pause"
log_file="$MODDIR/service.log"
config_cache_file="$PID_DIR/.config_cache"
# 默认设备路径
DEFAULT_NOW_BRI_FILE="/sys/class/backlight/panel0-backlight/brightness"
# 读取配置函数
get_config() {
local config_file="$1"
local default_value="$2"
if [ -f "$config_file" ]; then
cat "$config_file"
get_cfg() {
local key="$1" default="$2"
local val
if val=$("$JQ" -re ".${key}" "$CONFIG_FILE" 2>/dev/null); then
echo "$val"
else
echo "$default_value"
echo "$default"
fi
}
# 获取当前配置的哈希值(用于检测配置变化)
get_config_hash() {
local now_file events
now_file="$(get_config "$PATH_CONFIG_DIR/now_bri_file.txt" "$DEFAULT_NOW_BRI_FILE")"
events="$(get_config "$CONFIG_DIR/inotify_events.txt" "c")"
now_file="$(get_cfg now_bri_file "$DEFAULT_NOW_BRI_FILE")"
events="$(get_cfg inotify_events "c")"
echo "${now_file}|${events}"
}
# 日志函数
_log() {
local level="${2:-INFO}"
printf '[%s] [%s] [%s] %s\n' "$(date '+%m-%d %H:%M:%S')" "daemon" "$level" "$1" >>"$log_file"
}
# 确保环境就绪
mkdir -p "$PID_DIR"
_log "守护进程已启动" "INFO"
while true; do
# 检查是否需要手动停止或暂时挂起
if [ -f "$stop_file" ]; then
# 全局停止,杀掉现有并等待
[ -f "$pid_file" ] && kill -9 "$(cat "$pid_file")" 2>/dev/null
rm -f "$pid_file"
_log "检测到停止信号,守护进程挂起" "WARN"
@@ -61,17 +52,14 @@ while true; do
fi
if [ -f "$pause_file" ]; then
# 暂时挂起(由 up.sh 处理中),杀掉现有并等待
[ -f "$pid_file" ] && kill -9 "$(cat "$pid_file")" 2>/dev/null
rm -f "$pid_file"
sleep 1
continue
fi
# 获取当前配置
current_config="$(get_config_hash)"
# 检查配置是否改变
if [ -f "$config_cache_file" ]; then
cached_config="$(cat "$config_cache_file")"
if [ "$current_config" != "$cached_config" ]; then
@@ -83,26 +71,21 @@ while true; do
continue
fi
else
# 第一次启动或缓存不存在,保存当前配置
echo "$current_config" >"$config_cache_file"
fi
# 正常启动并监听
_log "正在启动 inotifyd 监听" "INFO"
now_bri_file="${current_config%|*}"
inotify_events="${current_config#*|}"
# 更新缓存,让 up.sh 知道当前监听的是哪个文件
echo -n "$now_bri_file" >"$PATH_CONFIG_DIR/.cached_path"
# 缓存当前监听路径(供 up.sh 参考)
echo -n "$now_bri_file" >"$MODDIR/config/.cached_path"
# 启动并重定向 (不再使用子进程管道以保证 PID 抓取准确)
inotifyd "$MODDIR/script/up.sh" "$now_bri_file:$inotify_events" >>"$log_file" 2>&1 &
inotify_pid=$!
echo "$inotify_pid" >"$pid_file"
_log "inotifyd 已启动 (PID: $inotify_pid), 监听: $now_bri_file, 事件: $inotify_events" "SUCCESS"
# 3. 通过 wait 阻塞,实时感知进程死亡 (兼容所有 BusyBox 环境)
wait "$inotify_pid"
_log "监听进程 (PID: $inotify_pid) 已退出,即将重启" "WARN"
+202 -12
View File
@@ -3,30 +3,220 @@
# 亮度提升脚本
MODDIR="${0%/*/*}"
CONFIG_DIR="$MODDIR/config"
PATH_CONFIG_DIR="$CONFIG_DIR/path"
CONFIG_FILE="$MODDIR/config/config.json"
JQ="$MODDIR/bin/jq"
PID_DIR="$MODDIR/pid"
flag_file="$PID_DIR/up.flag"
stop_file="$PID_DIR/stop.flag"
log_file="$MODDIR/service.log"
pause_file="$PID_DIR/daemon.pause"
# 默认设备路径
DEFAULT_NOW_BRI_FILE="/sys/class/backlight/panel0-backlight/brightness"
# 读取配置函数
get_config() {
local config_file="$1"
local default_value="$2"
if [ -f "$config_file" ]; then
cat "$config_file"
get_cfg() {
local key="$1" default="$2"
local val
if val=$("$JQ" -re ".${key}" "$CONFIG_FILE" 2>/dev/null); then
echo "$val"
else
echo "$default_value"
echo "$default"
fi
}
# 获取亮度文件路径
now_bri_file="$(get_config "$PATH_CONFIG_DIR/now_bri_file.txt" "$DEFAULT_NOW_BRI_FILE")"
now_bri_file="$(get_cfg now_bri_file "$DEFAULT_NOW_BRI_FILE")"
_log() {
local level="${2:-INFO}"
case "$1" in
"日志超限"*) ;;
*) if [ -f "$stop_file" ]; then return; fi ;;
esac
local max_size
max_size="$(get_cfg log_max_size 500)"
if [ -f "$log_file" ]; then
local cur_size
cur_size=$(du -k "$log_file" | cut -f1)
if [ "$cur_size" -ge "$max_size" ]; then
printf '[%s] [%s] [%s] %s\n' "$(date '+%m-%d %H:%M:%S')" "up" "WARN" "日志超限 (${cur_size}KB / ${max_size}KB),已自动重置" >"$log_file"
fi
fi
printf '[%s] [%s] [%s] %s\n' "$(date '+%m-%d %H:%M:%S')" "up" "$level" "$1" >>"$log_file"
}
_log "收到 inotifyd 事件通知 (PID: $$)" "INFO"
_log "正在接管控制权,清理残余进程..." "INFO"
touch "$pause_file"
killall -9 inotifyd 2>/dev/null
for p in $(pgrep -f "up.sh"); do
[ "$p" != "$$" ] && kill -9 "$p" 2>/dev/null
done
if [ -f "$stop_file" ]; then
_log "服务已暂停,跳过本次处理" "WARN"
exit 0
fi
if [ -f "$flag_file" ]; then
_log "检测到并发执行,当前进程退出" "WARN"
exit 1
fi
touch "$flag_file"
# 读取配置
ui_max_bri="$(get_cfg ui_max_bri 0)"
max_bri="$(get_cfg max_bri 0)"
sleep_time="$(get_cfg sleep_time '')"
auto_bri_sleep="$(get_cfg auto_bri_sleep 1)"
display_hdr_sleep="$(get_cfg display_hdr_sleep 0)"
steps_num="$(get_cfg steps_num 50)"
# 解析休眠时间
sleep_start="${sleep_time%-*}"
sleep_end="${sleep_time#*-}"
IS_SLEEP_TIME() {
local now
now="$(date '+%H%M')"
[ -z "$sleep_start" ] || [ -z "$sleep_end" ] && return 1
[ "$sleep_start" = "$sleep_end" ] && return 1
if [ "$sleep_start" -gt "$sleep_end" ]; then
[ "$now" -ge "$sleep_start" ] || [ "$now" -lt "$sleep_end" ]
else
[ "$now" -ge "$sleep_start" ] && [ "$now" -lt "$sleep_end" ]
fi
}
target_bri="$max_bri"
update_all() {
local step
start_bri="$(cat "$now_bri_file")"
bri_diff="$((target_bri - start_bri))"
step_value="$((bri_diff / steps_num))"
if [ "$step_value" -eq 0 ]; then
_log "差値过小,直接设定亮度: $target_bri" "INFO"
echo -n "$target_bri" >"$now_bri_file" && return 0 || return 1
fi
_log "开始渐变调整: $start_bri → $target_bri ($steps_num 步)" "INFO"
for step in $(seq 1 "$steps_num"); do
echo -n $((start_bri + step * step_value)) >"$now_bri_file"
sleep 0.02
done
echo -n "$target_bri" >"$now_bri_file" && return 0 || return 1
}
CHECK_BRI() {
local cycle_num now_bri
# shellcheck disable=SC2034
for cycle_num in $(seq 1 10); do
now_bri="$(cat "$now_bri_file")"
if [ "$now_bri" -ge "$ui_max_bri" ] && [ "$now_bri" -lt "$target_bri" ]; then
_log "触发提升: 当前亮度 $now_bri ≥ 阈値 $ui_max_bri,目标 $target_bri" "INFO"
if update_all; then
_log "亮度提升完成 ($target_bri)" "SUCCESS"
return 0
else
_log "亮度提升失败: 无法写入亮度节点" "ERROR"
return 1
fi
fi
sleep 0.3
done
_log "检测超时: 亮度未持续达到提升阈値" "INFO"
return 1
}
MAIN() {
if IS_SLEEP_TIME; then
_log "处于休眠时段 ($sleep_start-$sleep_end),跳过提升" "INFO"
rm -f "$flag_file" "$pause_file"
return
fi
if [ "$auto_bri_sleep" = "1" ]; then
local mode
mode="$(settings get system screen_brightness_mode 2>/dev/null)"
if [ "$mode" = "1" ]; then
_log "自动亮度已启用,跳过提升" "INFO"
rm -f "$flag_file" "$pause_file"
return
fi
fi
# 黑名单检测(从 JSON 数组读取)
local blacklist_len
blacklist_len=$("$JQ" -r '.blacklist_apps | length' "$CONFIG_FILE" 2>/dev/null || echo "0")
if [ "${blacklist_len:-0}" -gt 0 ]; then
local current_focus current_app
current_focus="$(dumpsys window | grep mCurrentFocus | sed 's/.*u[0-9][0-9]* //' | sed 's/}.*//')"
current_app="${current_focus%%/*}"
if [ -n "$current_focus" ] &&
"$JQ" -re --arg f "$current_focus" --arg a "$current_app" \
'.blacklist_apps | map(. == $f or . == $a) | any' \
"$CONFIG_FILE" >/dev/null 2>&1; then
_log "当前前台 ($current_focus) 在黑名单中,跳过提升" "INFO"
rm -f "$flag_file" "$pause_file"
return
fi
fi
# 显示 HDR 内容时休眠
if [ "$display_hdr_sleep" = "1" ]; then
local hdr_flag_file="$PID_DIR/hdr.flag"
if [ -f "$hdr_flag_file" ]; then
local flag_time now
flag_time="$(cat "$hdr_flag_file")"
now="$(date +%s)"
if awk "BEGIN{exit !(($now - $flag_time) < 2)}" 2>/dev/null; then
_log "HDR 冷却期内,跳过提升" "INFO"
rm -f "$flag_file" "$pause_file"
return
else
rm -f "$hdr_flag_file"
fi
fi
local hdr_ratio
local hdr_cache_file="$PID_DIR/.hdr_ratio_cache"
hdr_ratio="$(dumpsys display 2>/dev/null | sed -n 's/.*hdrSdrRatio \([0-9.]*\).*/\1/p' | head -n 1)"
if echo "$hdr_ratio" | grep -qE '^[0-9]+\.[0-9]+$'; then
echo -n "$hdr_ratio" >"$hdr_cache_file"
elif [ -f "$hdr_cache_file" ]; then
hdr_ratio="$(cat "$hdr_cache_file")"
_log "HDR 比率读取为空,使用缓存值: $hdr_ratio" "INFO"
fi
if echo "$hdr_ratio" | grep -qE '^[0-9]+\.[0-9]+$'; then
local hdr_ratio_rounded
hdr_ratio_rounded="$(awk "BEGIN{printf \"%.2f\", $hdr_ratio}")"
if awk "BEGIN{exit !($hdr_ratio_rounded > 1.00)}" 2>/dev/null; then
_log "检测到 HDR 内容 (比率: $hdr_ratio_rounded),跳过提升" "INFO"
date +%s >"$hdr_flag_file"
rm -f "$flag_file" "$pause_file"
return
fi
fi
fi
_log "正在检测亮度变化..." "INFO"
CHECK_BRI
rm -f "$flag_file"
rm -f "$pause_file"
# 如果监听路径变更,重启 inotifyd
local current_now_bri cached_now_bri
current_now_bri="$(get_cfg now_bri_file "$DEFAULT_NOW_BRI_FILE")"
cached_now_bri="$(cat "$MODDIR/config/.cached_path" 2>/dev/null || echo "$DEFAULT_NOW_BRI_FILE")"
if [ "$current_now_bri" != "$cached_now_bri" ]; then
_log "检测到监听路径变更,重启 inotifyd" "INFO"
killall -9 inotifyd 2>/dev/null
fi
}
MAIN
exit 0
# 日志函数
_log() {
+13 -17
View File
@@ -2,22 +2,20 @@
#shellcheck shell=ash
MODDIR="${0%/*}"
CONFIG_DIR="$MODDIR/config"
PATH_CONFIG_DIR="$CONFIG_DIR/path"
CONFIG_FILE="$MODDIR/config/config.json"
JQ="$MODDIR/bin/jq"
log_file="$MODDIR/service.log"
# 默认设备路径
DEFAULT_NOW_BRI_FILE="/sys/class/backlight/panel0-backlight/brightness"
DEFAULT_MAX_BRI_FILE="/sys/class/backlight/panel0-backlight/max_brightness"
# 读取配置函数
get_config() {
local config_file="$1"
local default_value="$2"
if [ -f "$config_file" ]; then
cat "$config_file"
get_cfg() {
local key="$1" default="$2"
local val
if val=$("$JQ" -re ".${key}" "$CONFIG_FILE" 2>/dev/null); then
echo "$val"
else
echo "$default_value"
echo "$default"
fi
}
@@ -33,13 +31,12 @@ sleep 30
rm -f "$MODDIR/pid/"*.flag "$MODDIR/pid/"*.pause "$MODDIR/pid/.hdr_ratio_cache"
_log "LuminPro 服务启动" "INFO"
_log "前台最大亮度: $(cat "$CONFIG_DIR/ui_max_bri.txt")" "INFO"
_log "峰值最大亮度: $(cat "$CONFIG_DIR/max_bri.txt")" "INFO"
_log "休眠时段: $(cat "$CONFIG_DIR/sleep_time.txt")" "INFO"
_log "前台最大亮度: $(get_cfg ui_max_bri 0)" "INFO"
_log "峰值最大亮度: $(get_cfg max_bri 0)" "INFO"
_log "休眠时段: $(get_cfg sleep_time '')" "INFO"
# 读取设备路径配置
now_bri_file="$(get_config "$PATH_CONFIG_DIR/now_bri_file.txt" "$DEFAULT_NOW_BRI_FILE")"
max_bri_file="$(get_config "$PATH_CONFIG_DIR/max_bri_file.txt" "$DEFAULT_MAX_BRI_FILE")"
now_bri_file="$(get_cfg now_bri_file "$DEFAULT_NOW_BRI_FILE")"
max_bri_file="$(get_cfg max_bri_file "$DEFAULT_MAX_BRI_FILE")"
_log "当前亮度节点: $now_bri_file" "INFO"
_log "最大亮度节点: $max_bri_file" "INFO"
@@ -47,7 +44,6 @@ _log "正在启动守护进程" "INFO"
chmod 755 "$MODDIR/script/up.sh"
chmod 755 "$MODDIR/script/daemon.sh"
# 启动守护进程
sh "$MODDIR/script/daemon.sh" &
_log "守护进程已启动 (PID: $!)" "SUCCESS"
+2 -2
View File
@@ -6,8 +6,8 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no" />
<title>LuminPro</title>
<link rel="stylesheet" type="text/css" href="/internal/insets.css" />
<script type="module" crossorigin src="/assets/index-BShqMWYm.js"></script>
<link rel="stylesheet" crossorigin href="/assets/index-D3b5fUNT.css">
<script type="module" crossorigin src="/assets/index-MlKbWKln.js"></script>
<link rel="stylesheet" crossorigin href="/assets/index-DjaknYwM.css">
</head>
<body>
+6 -7
View File
@@ -2,7 +2,7 @@
import { listPackages, getPackagesInfo } from 'kernelsu';
import { createIcons, Eye, EyeOff } from 'lucide';
import PinyinMatch from 'pinyin-match';
import { CONFIG_DIR, showToast, runCmd, writeFile } from './utils.js';
import { CONFIG_DIR, showToast, runCmd, readConfig, updateConfig } from './utils.js';
let showingSystemApps = true;
let savedBlacklist = new Set();
@@ -93,9 +93,9 @@ export async function loadApps() {
container.innerHTML = '<div style="text-align:center;padding:20px;color:var(--md-sys-color-on-surface-variant);">加载中...</div>';
try {
// 读取已保存的黑名单(包名条目 + 活动条目分开存储)
const blRes = await runCmd(`cat "${CONFIG_DIR}/blacklist_apps.txt"`);
const allSaved = blRes.errno === 0 ? blRes.stdout.trim().split('\n').filter(Boolean) : [];
// 读取已保存的黑名单(从 JSON 配置读取)
const cfg = await readConfig();
const allSaved = Array.isArray(cfg.blacklist_apps) ? cfg.blacklist_apps : [];
savedBlacklist = new Set(allSaved);
const savedPkgEntries = new Set(allSaved.filter(e => !e.includes('/')));
activityEntries = new Set(allSaved.filter(e => e.includes('/')));
@@ -463,9 +463,8 @@ export function setupAppsEvents() {
const selectedPkgs = [];
document.querySelectorAll('.app-checkbox').forEach(cb => { if (cb.checked) selectedPkgs.push(cb.dataset.pkg); });
const allEntries = [...selectedPkgs, ...activityEntries];
const content = allEntries.join('\n');
const res = await writeFile(`${CONFIG_DIR}/blacklist_apps.txt`, content);
if (res.errno === 0 || res.stdout.includes('OK')) {
const res = await updateConfig({ blacklist_apps: allEntries });
if (res.errno === 0 || res.stdout?.includes('OK')) {
showToast('黑名单保存成功');
savedBlacklist = new Set(allEntries);
updateUnsavedStyling();
+64 -72
View File
@@ -1,7 +1,7 @@
import { ref } from 'vue';
import {
runCmd, writeFile,
CONFIG_DIR, PATH_CONFIG_DIR, BACKUP_DIR, PID_FILE, FLAG_FILE,
runCmd, readConfig, writeConfig, updateConfig,
CONFIG_FILE, BACKUP_CONFIG_FILE, PID_FILE, FLAG_FILE,
DEFAULT_NOW_BRI_FILE, DEFAULT_SYS_MAX_BRI_FILE,
} from '../utils.js';
@@ -37,42 +37,27 @@ export function useConfig() {
const themeMode = ref(localStorage.getItem('themeMode') || 'system');
async function load() {
const [pathNowRes, pathMaxRes, eventsRes] = await Promise.all([
runCmd(`cat "${PATH_CONFIG_DIR}/now_bri_file.txt"`),
runCmd(`cat "${PATH_CONFIG_DIR}/max_bri_file.txt"`),
runCmd(`cat "${CONFIG_DIR}/inotify_events.txt"`),
]);
if (pathNowRes.errno === 0 && pathNowRes.stdout.trim()) nowBriFile.value = pathNowRes.stdout.trim();
if (pathMaxRes.errno === 0 && pathMaxRes.stdout.trim()) sysMaxBriFile.value = pathMaxRes.stdout.trim();
inotifyEvents.value = (eventsRes.errno === 0 && eventsRes.stdout.trim()) ? eventsRes.stdout.trim() : 'c';
const cfg = await readConfig();
if (!cfg || Object.keys(cfg).length === 0) return;
const [uiRes, maxRes, sleepRes, autoRes, stepsRes, logSizeRes, hdrRes] = await Promise.all([
runCmd(`cat "${CONFIG_DIR}/ui_max_bri.txt"`),
runCmd(`cat "${CONFIG_DIR}/max_bri.txt"`),
runCmd(`cat "${CONFIG_DIR}/sleep_time.txt"`),
runCmd(`cat "${CONFIG_DIR}/auto_bri_sleep.txt"`),
runCmd(`cat "${CONFIG_DIR}/steps_num.txt"`),
runCmd(`cat "${CONFIG_DIR}/log_max_size.txt"`),
runCmd(`cat "${CONFIG_DIR}/display_hdr_sleep.txt"`),
]);
uiMaxBri.value = cfg.ui_max_bri != null ? String(cfg.ui_max_bri) : '';
maxBri.value = cfg.max_bri != null ? String(cfg.max_bri) : '';
stepsNum.value = cfg.steps_num != null ? String(cfg.steps_num) : '50';
logMaxSize.value = cfg.log_max_size != null ? String(cfg.log_max_size) : '500';
autoBriSleep.value = cfg.auto_bri_sleep === 1;
displayHdrSleep.value = cfg.display_hdr_sleep === 1;
nowBriFile.value = cfg.now_bri_file || DEFAULT_NOW_BRI_FILE;
sysMaxBriFile.value = cfg.max_bri_file || DEFAULT_SYS_MAX_BRI_FILE;
inotifyEvents.value = cfg.inotify_events || 'c';
if (uiRes.errno === 0) uiMaxBri.value = uiRes.stdout.trim();
if (maxRes.errno === 0) maxBri.value = maxRes.stdout.trim();
if (autoRes.errno === 0) autoBriSleep.value = autoRes.stdout.trim() === '1';
if (hdrRes.errno === 0) displayHdrSleep.value = hdrRes.stdout.trim() === '1';
stepsNum.value = (stepsRes.errno === 0 && stepsRes.stdout.trim()) ? stepsRes.stdout.trim() : '50';
logMaxSize.value = (logSizeRes.errno === 0 && logSizeRes.stdout.trim()) ? logSizeRes.stdout.trim() : '500';
if (sleepRes.errno === 0) {
const tv = sleepRes.stdout.trim();
if (tv && tv.includes('-')) {
sleepMode.value = true;
const [s, e] = tv.split('-');
if (s.length === 4) { sleepStartH.value = s.slice(0, 2); sleepStartM.value = s.slice(2); }
if (e.length === 4) { sleepEndH.value = e.slice(0, 2); sleepEndM.value = e.slice(2); }
} else {
sleepMode.value = false;
}
const st = cfg.sleep_time || '';
if (st && st.includes('-')) {
sleepMode.value = true;
const [s, e] = st.split('-');
if (s.length === 4) { sleepStartH.value = s.slice(0, 2); sleepStartM.value = s.slice(2); }
if (e.length === 4) { sleepEndH.value = e.slice(0, 2); sleepEndM.value = e.slice(2); }
} else {
sleepMode.value = false;
}
}
@@ -83,60 +68,66 @@ export function useConfig() {
}
async function save(toast) {
if (!uiMaxBri.value || !maxBri.value) { toast('亮度值不能为空'); return; }
if (!uiMaxBri.value || !maxBri.value) { toast('亮度値不能为空'); return; }
toast('保存中...');
await Promise.all([
writeFile(`${CONFIG_DIR}/ui_max_bri.txt`, uiMaxBri.value),
writeFile(`${CONFIG_DIR}/max_bri.txt`, maxBri.value),
writeFile(`${CONFIG_DIR}/sleep_time.txt`, getSleepTimeStr()),
writeFile(`${CONFIG_DIR}/auto_bri_sleep.txt`, autoBriSleep.value ? '1' : '0'),
writeFile(`${CONFIG_DIR}/display_hdr_sleep.txt`, displayHdrSleep.value ? '1' : '0'),
writeFile(`${CONFIG_DIR}/steps_num.txt`, stepsNum.value || '50'),
writeFile(`${CONFIG_DIR}/log_max_size.txt`, logMaxSize.value || '500'),
]);
// 读取当前配置(保留 blacklist_apps 等其他字段)
const current = await readConfig();
await writeConfig({
...current,
ui_max_bri: parseInt(uiMaxBri.value) || 0,
max_bri: parseInt(maxBri.value) || 0,
steps_num: parseInt(stepsNum.value) || 50,
log_max_size: parseInt(logMaxSize.value) || 500,
auto_bri_sleep: autoBriSleep.value ? 1 : 0,
display_hdr_sleep: displayHdrSleep.value ? 1 : 0,
sleep_time: getSleepTimeStr(),
});
await runCmd(`rm -f "${FLAG_FILE}"`);
const pidRes = await runCmd(`cat "${PID_FILE}"`);
toast(pidRes.errno === 0 && pidRes.stdout.trim() ? '配置已保存 (下次调整时生效)' : '配置已保存 (服务未运行)');
}
async function saveAdvanced(toast, onPathsChanged) {
const nowV = nowBriFile.value || DEFAULT_NOW_BRI_FILE;
const maxV = sysMaxBriFile.value || DEFAULT_SYS_MAX_BRI_FILE;
const evtV = inotifyEvents.value || 'c';
toast('保存中...');
await Promise.all([
writeFile(`${PATH_CONFIG_DIR}/now_bri_file.txt`, nowV),
writeFile(`${PATH_CONFIG_DIR}/max_bri_file.txt`, maxV),
writeFile(`${CONFIG_DIR}/inotify_events.txt`, evtV),
]);
await updateConfig({
now_bri_file: nowBriFile.value || DEFAULT_NOW_BRI_FILE,
max_bri_file: sysMaxBriFile.value || DEFAULT_SYS_MAX_BRI_FILE,
inotify_events: inotifyEvents.value || 'c',
});
onPathsChanged?.();
toast('高级设置已保存,需重启服务生效');
}
async function resetToDefaults(toast) {
toast('正在恢复默认配置...');
const [uiRes, maxRes, sleepRes, autoRes, stepsRes, logSizeRes] = await Promise.all([
runCmd(`cat "${BACKUP_DIR}/ui_max_bri.txt"`),
runCmd(`cat "${BACKUP_DIR}/max_bri.txt"`),
runCmd(`cat "${BACKUP_DIR}/sleep_time.txt"`),
runCmd(`cat "${BACKUP_DIR}/auto_bri_sleep.txt"`),
runCmd(`cat "${BACKUP_DIR}/steps_num.txt"`),
runCmd(`cat "${BACKUP_DIR}/log_max_size.txt"`),
]);
if (uiRes.errno === 0) uiMaxBri.value = uiRes.stdout.trim();
if (maxRes.errno === 0) maxBri.value = maxRes.stdout.trim();
autoBriSleep.value = autoRes.errno === 0 ? autoRes.stdout.trim() === '1' : true;
stepsNum.value = stepsRes.errno === 0 ? stepsRes.stdout.trim() : '50';
logMaxSize.value = logSizeRes.errno === 0 ? logSizeRes.stdout.trim() : '500';
if (sleepRes.errno === 0 && sleepRes.stdout.trim().includes('-')) {
const backupRes = await runCmd(`cat "${BACKUP_CONFIG_FILE}"`);
if (backupRes.errno !== 0 || !backupRes.stdout.trim()) {
toast('备份文件不存在,无法恢复');
return;
}
let backup;
try { backup = JSON.parse(backupRes.stdout); } catch { toast('备份文件损坏'); return; }
uiMaxBri.value = backup.ui_max_bri != null ? String(backup.ui_max_bri) : '';
maxBri.value = backup.max_bri != null ? String(backup.max_bri) : '';
autoBriSleep.value = backup.auto_bri_sleep === 1;
displayHdrSleep.value = backup.display_hdr_sleep === 1;
stepsNum.value = backup.steps_num != null ? String(backup.steps_num) : '50';
logMaxSize.value = backup.log_max_size != null ? String(backup.log_max_size) : '500';
nowBriFile.value = backup.now_bri_file || DEFAULT_NOW_BRI_FILE;
sysMaxBriFile.value = backup.max_bri_file || DEFAULT_SYS_MAX_BRI_FILE;
inotifyEvents.value = backup.inotify_events || 'c';
const st = backup.sleep_time || '';
if (st && st.includes('-')) {
sleepMode.value = true;
const [s, e] = sleepRes.stdout.trim().split('-');
const [s, e] = st.split('-');
if (s.length === 4) { sleepStartH.value = s.slice(0, 2); sleepStartM.value = s.slice(2); }
if (e.length === 4) { sleepEndH.value = e.slice(0, 2); sleepEndM.value = e.slice(2); }
if (e.length === 4) { sleepEndH.value = e.slice(0, 2); sleepEndM.value = e.slice(2); }
} else {
sleepMode.value = true;
sleepStartH.value = '19'; sleepStartM.value = '00';
sleepEndH.value = '06'; sleepEndM.value = '00';
sleepEndH.value = '06'; sleepEndM.value = '00';
}
await save(toast);
}
@@ -167,7 +158,6 @@ export function useConfig() {
html.classList.remove('light', 'dark');
if (mode === 'light') html.classList.add('light');
else if (mode === 'dark') html.classList.add('dark');
// 'system': no class, CSS @media handles it
}
return {
@@ -180,3 +170,5 @@ export function useConfig() {
saveWebUIConfig, applyZoom, applyTheme,
};
}
+9 -13
View File
@@ -1,8 +1,7 @@
import { ref, computed } from 'vue';
import {
runCmd,
CONFIG_DIR, PATH_CONFIG_DIR, PID_FILE,
STOP_FLAG_FILE,
runCmd, readConfig,
PID_FILE, STOP_FLAG_FILE,
DEFAULT_NOW_BRI_FILE, DEFAULT_SYS_MAX_BRI_FILE,
} from '../utils.js';
@@ -40,12 +39,9 @@ export function useStatus() {
async function _ensurePaths() {
if (_nowBriFile && _sysMaxBriFile) return;
const [r1, r2] = await Promise.all([
runCmd(`cat "${PATH_CONFIG_DIR}/now_bri_file.txt"`),
runCmd(`cat "${PATH_CONFIG_DIR}/max_bri_file.txt"`),
]);
_nowBriFile = (r1.errno === 0 && r1.stdout.trim()) ? r1.stdout.trim() : DEFAULT_NOW_BRI_FILE;
_sysMaxBriFile = (r2.errno === 0 && r2.stdout.trim()) ? r2.stdout.trim() : DEFAULT_SYS_MAX_BRI_FILE;
const cfg = await readConfig();
_nowBriFile = cfg.now_bri_file || DEFAULT_NOW_BRI_FILE;
_sysMaxBriFile = cfg.max_bri_file || DEFAULT_SYS_MAX_BRI_FILE;
}
function invalidatePaths() {
@@ -65,13 +61,14 @@ export function useStatus() {
sysMaxBri.value = sRes.errno === 0 ? sRes.stdout.trim() : '255';
}
const [pidRes, stopRes, autoBriRes, hdrRes, sleepRes] = await Promise.all([
const [pidRes, stopRes, autoBriRes, hdrRes] = await Promise.all([
runCmd(`cat "${PID_FILE}"`),
runCmd(`[ -f "${STOP_FLAG_FILE}" ] && echo "1" || echo "0"`),
runCmd(`settings get system screen_brightness_mode`),
runCmd(`dumpsys display 2>/dev/null | sed -n 's/.*hdrSdrRatio \\([0-9.]*\\).*/\\1/p' | head -n 1`),
runCmd(`cat "${CONFIG_DIR}/sleep_time.txt"`),
]);
const cfgForSleep = await readConfig();
const sleepTimeStr = cfgForSleep.sleep_time || '';
isPaused.value = stopRes.errno === 0 && stopRes.stdout.trim() === '1';
const pidStr = pidRes.errno === 0 ? pidRes.stdout.trim() : '';
@@ -92,8 +89,7 @@ export function useStatus() {
hdrRatio.value = (hdrRaw && /^\d+(\.\d+)?$/.test(hdrRaw)) ? parseFloat(hdrRaw).toFixed(2) : '-';
// 计算睡眠状态
const sleepTime = sleepRes.errno === 0 ? sleepRes.stdout.trim() : '';
sleepStatus.value = _calcSleep(sleepTime);
sleepStatus.value = _calcSleep(sleepTimeStr);
}
function _calcSleep(sleepTime) {
+2
View File
@@ -128,6 +128,8 @@
}
.header-status.status-running .status-dot {
background-color: #4caf50;
box-shadow: 0 0 8px rgba(76, 175, 80, 0.6);
animation: status-pulse-green 2s infinite;
}
+46 -22
View File
@@ -1,12 +1,13 @@
import { exec } from 'kernelsu';
export const CONFIG_DIR = '/data/adb/modules/LuminPro/config';
export const PATH_CONFIG_DIR = '/data/adb/modules/LuminPro/config/path';
export const BACKUP_DIR = '/data/adb/modules/LuminPro/config/.backup';
export const PID_FILE = '/data/adb/modules/LuminPro/pid/inotifyd.pid';
export const FLAG_FILE = '/data/adb/modules/LuminPro/pid/up.flag';
export const STOP_FLAG_FILE = '/data/adb/modules/LuminPro/pid/stop.flag';
export const LOG_FILE = '/data/adb/modules/LuminPro/service.log';
export const MODULE_DIR = '/data/adb/modules/LuminPro';
export const CONFIG_DIR = `${MODULE_DIR}/config`;
export const CONFIG_FILE = `${MODULE_DIR}/config/config.json`;
export const BACKUP_CONFIG_FILE = `${MODULE_DIR}/config/.backup/config.json`;
export const PID_FILE = `${MODULE_DIR}/pid/inotifyd.pid`;
export const FLAG_FILE = `${MODULE_DIR}/pid/up.flag`;
export const STOP_FLAG_FILE = `${MODULE_DIR}/pid/stop.flag`;
export const LOG_FILE = `${MODULE_DIR}/service.log`;
export const DEFAULT_NOW_BRI_FILE = '/sys/class/backlight/panel0-backlight/brightness';
export const DEFAULT_SYS_MAX_BRI_FILE = '/sys/class/backlight/panel0-backlight/max_brightness';
@@ -22,38 +23,61 @@ export async function runCmd(cmd) {
const res = await exec(cmd);
return res;
} catch (e) {
// 调试模式数据模拟
console.warn(`[DEBUG] 执行命令失败 (可能是非 KSU 环境): ${cmd}`);
// 基础配置模拟
if (cmd.includes('cat') && cmd.includes('ui_max_bri.txt')) return { errno: 0, stdout: '4095', stderr: '' };
if (cmd.includes('cat') && cmd.includes('max_bri.txt')) return { errno: 0, stdout: '3500', stderr: '' };
if (cmd.includes('cat') && (cmd.includes('now_bri_file.txt') || cmd.includes('max_bri_file.txt'))) return { errno: 0, stdout: '/sys/mock/brightness', stderr: '' };
if (cmd.includes('cat') && cmd.includes('inotify_events.txt')) return { errno: 0, stdout: 'c', stderr: '' };
if (cmd.includes('cat') && cmd.includes('log_max_size.txt')) return { errno: 0, stdout: '1024', stderr: '' };
if (cmd.includes('cat') && cmd.includes('steps_num.txt')) return { errno: 0, stdout: '100', stderr: '' };
// JSON 配置模拟
if (cmd.includes('cat') && cmd.includes('config.json')) {
return { errno: 0, stdout: JSON.stringify({
ui_max_bri: 4095, max_bri: 3500, steps_num: 100, log_max_size: 1024,
auto_bri_sleep: 1, display_hdr_sleep: 0, sleep_time: '1900-0600',
inotify_events: 'c',
now_bri_file: '/sys/mock/brightness',
max_bri_file: '/sys/mock/max_brightness',
blacklist_apps: ['com.example.app'],
}), stderr: '' };
}
// 状态模拟
if (cmd.includes('cat') && (cmd.includes('brightness') || cmd.includes('now_bri_file.txt'))) return { errno: 0, stdout: '1200', stderr: '' };
if (cmd.includes('cat') && (cmd.includes('max_brightness') || cmd.includes('max_bri_file.txt'))) return { errno: 0, stdout: '4095', stderr: '' };
if (cmd.includes('cat') && cmd.includes('inotifyd.pid')) return { errno: 0, stdout: '12345', stderr: '' };
if (cmd.includes('settings get system screen_brightness_mode')) return { errno: 0, stdout: '1', stderr: '' };
if (cmd.includes('[ -f') && cmd.includes('stop.flag')) return { errno: 0, stdout: '0', stderr: '' };
if (cmd.includes('cat') && (cmd.includes('brightness') || cmd.includes('now_bri'))) return { errno: 0, stdout: '1200', stderr: '' };
if (cmd.includes('cat') && (cmd.includes('max_brightness') || cmd.includes('max_bri'))) return { errno: 0, stdout: '4095', stderr: '' };
// 日志模拟
if (cmd.includes('tail') && cmd.includes('service.log')) {
return { errno: 0, stdout: '[2026-04-07 15:40:01] [INFO] 服务启动成功\n[2026-04-07 15:41:05] [DEBUG] 亮度调整: 1200 -> 1250\n[2026-04-07 15:42:10] [INFO] 切换至峰值亮度模式\n[2026-04-07 15:43:22] [WARN] 检测到极低亮度设定', stderr: '' };
return { errno: 0, stdout: '[04-07 15:40:01] [service] [INFO ] LuminPro 服务启动\n[04-07 15:41:05] [up] [INFO ] 触发提升: 当前亮度 1200 ≥ 阈値 1000\n[04-07 15:42:10] [up] [SUCCESS ] 亮度提升完成 (3500)', stderr: '' };
}
// 文档模拟
if (cmd.includes('cat') && cmd.includes('.md')) return { errno: 0, stdout: '# 调试模式说明\n\n当前处于 **Web 调试模式**,显示的是模拟出的测试数据。\n\n- 状态卡片:全部固定为运行中。\n- 应用列表:预设了 150 个常用模拟应用。\n- 按钮:所有变更仅在当前页面生效,不会写入手机文件系统。', stderr: '' };
if (cmd.includes('cat') && cmd.includes('.txt')) return { errno: 0, stdout: '这是 NOTE.txt 的模拟内容,用于测试纯文本渲染。', stderr: '' };
if (cmd.includes('cat') && cmd.includes('.md')) return { errno: 0, stdout: '# 调试模式\n\n当前处于 **Web 调试模式**,显示的是模拟测试数据。', stderr: '' };
if (cmd.includes('cat') && cmd.includes('.txt')) return { errno: 0, stdout: '这是 NOTE.txt 的模拟内容。', stderr: '' };
return { errno: -1, stdout: '', stderr: String(e) };
}
}
// 读取完整 JSON 配置
export async function readConfig() {
const res = await runCmd(`cat "${CONFIG_FILE}"`);
if (res.errno !== 0 || !res.stdout.trim()) return {};
try { return JSON.parse(res.stdout); } catch { return {}; }
}
// 写入完整 JSON 配置
export async function writeConfig(obj) {
const content = JSON.stringify(obj).replace(/'/g, "'\\''" );
return runCmd(`printf '%s' '${content}' > "${CONFIG_FILE}"`);
}
// 合并更新 JSON 配置(保留其他字段)
export async function updateConfig(updates) {
const current = await readConfig();
return writeConfig({ ...current, ...updates });
}
// 将文件内容写入指定路径
export async function writeFile(path, content) {
const safeContent = String(content).replace(/'/g, "'\\''");
return runCmd(`echo -n '${safeContent}' > "${path}"`);
const safeContent = String(content).replace(/'/g, "'\\''" );
return runCmd(`printf '%s' '${safeContent}' > "${path}"`);
}
+5 -70
View File
@@ -1,28 +1,16 @@
<script setup>
import { ref, onMounted } from "vue";
import { ref } from "vue";
import Button from "@/components/ui/Button.vue";
import { ExternalLink, FileText, BookOpen, ScrollText, StickyNote, X, Github } from "lucide-vue-next";
import { moduleInfo } from "kernelsu";
import { BookOpen, ScrollText, StickyNote, X, Github } from "lucide-vue-next";
import { runCmd } from "../utils.js";
const MODULE_DIR = '/data/adb/modules/LuminPro';
const moduleVersion = ref("");
const sheetOpen = ref(false);
const sheetTitle = ref("");
const sheetContent = ref("");
const sheetLoading = ref(false);
onMounted(() => {
try {
const info = JSON.parse(moduleInfo());
moduleVersion.value = info.version || '';
} catch {
moduleVersion.value = '[debug]';
}
});
// 通过 KernelSU runCmd 读取模块本地文件
const moduleDocs = [
{ title: "README", file: `${MODULE_DIR}/README.md`, icon: BookOpen, md: true },
{ title: "README (EN)", file: `${MODULE_DIR}/README_en.md`, icon: BookOpen, md: true },
@@ -30,12 +18,6 @@ const moduleDocs = [
{ title: "NOTE", file: `${MODULE_DIR}/NOTE.txt`, icon: StickyNote, md: false },
];
// 通过 fetch 读取 webroot/docs/
const webDocs = [
{ title: "Web UI 使用文档", path: "/docs/webui.md", icon: FileText },
{ title: "Web UI API 文档", path: "/docs/webui-api.md", icon: FileText },
];
function mdToHtml(text) {
return text
.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;")
@@ -63,22 +45,6 @@ async function openModuleDoc(doc) {
}
}
async function openWebDoc(doc) {
sheetTitle.value = doc.title;
sheetContent.value = "";
sheetLoading.value = true;
sheetOpen.value = true;
try {
const res = await fetch(doc.path);
if (!res.ok) throw new Error(`HTTP ${res.status}`);
sheetContent.value = mdToHtml(await res.text());
} catch (e) {
sheetContent.value = `加载失败: ${e.message}`;
} finally {
sheetLoading.value = false;
}
}
function closeSheet() {
sheetOpen.value = false;
}
@@ -87,18 +53,6 @@ function closeSheet() {
<template>
<div style="display:contents">
<section class="card" id="about-section">
<!-- 项目信息 -->
<div class="about-hero">
<div class="about-logo">
<svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
<circle cx="12" cy="12" r="4"/><path d="M12 2v2"/><path d="M12 20v2"/><path d="m4.93 4.93 1.41 1.41"/><path d="m17.66 17.66 1.41 1.41"/><path d="M2 12h2"/><path d="M20 12h2"/><path d="m6.34 17.66-1.41 1.41"/><path d="m19.07 4.93-1.41 1.41"/>
</svg>
</div>
<h2 class="about-name">LuminPro</h2>
<p class="about-desc">日用屏幕亮度强化</p>
<span class="about-version-badge">{{ moduleVersion ? `v${moduleVersion}` : "V2.2" }}</span>
</div>
<!-- 模块文档 -->
<div class="about-section-title">模块文档</div>
<div class="about-list">
@@ -110,38 +64,19 @@ function closeSheet() {
>
<component :is="doc.icon" :size="18" class="about-list-icon" />
<span>{{ doc.title }}</span>
<ExternalLink :size="14" class="about-list-chevron" />
</button>
</div>
<!-- Web UI 文档 -->
<div class="about-section-title">Web UI 文档</div>
<div class="about-list">
<button
v-for="doc in webDocs"
:key="doc.path"
class="about-list-item"
@click="openWebDoc(doc)"
>
<component :is="doc.icon" :size="18" class="about-list-icon" />
<span>{{ doc.title }}</span>
<ExternalLink :size="14" class="about-list-chevron" />
</button>
</div>
<!-- 链接列表 -->
<div class="about-section-title">链接</div>
<div class="about-list">
<a
<button
class="about-list-item"
href="https://github.com/YuleBest/LuminPro"
target="_blank"
rel="noopener"
@click="runCmd('am start -a android.intent.action.VIEW -d \'https://github.com/YuleBest/LuminPro\'')"
>
<Github :size="18" class="about-list-icon" />
<span>GitHub 项目主页</span>
<ExternalLink :size="14" class="about-list-chevron" />
</a>
</button>
</div>
<p class="about-footer">Made with ❤ by Yule</p>