mirror of
https://github.com/YuleBest/LuminPro.git
synced 2026-12-04 00:54:42 +08:00
chore: 支持自定义文件设备路径
This commit is contained in:
1 parent
1e860b8a56
commit
a6bfba9647
13 files changed
+375
-82
No files matched your search
+47
-1
@@ -7,11 +7,33 @@ SCRIPT_DIR="$(dirname "$REAL_PATH")"
|
||||
MODDIR="$(dirname "$SCRIPT_DIR")"
|
||||
|
||||
PID_DIR="$MODDIR/pid"
|
||||
CONFIG_DIR="$MODDIR/config"
|
||||
PATH_CONFIG_DIR="$CONFIG_DIR/path"
|
||||
pid_file="$PID_DIR/inotifyd.pid"
|
||||
stop_file="$PID_DIR/stop.flag"
|
||||
pause_file="$PID_DIR/daemon.pause"
|
||||
log_file="$MODDIR/service.log"
|
||||
now_bri_file="/sys/class/backlight/panel0-backlight/brightness"
|
||||
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"
|
||||
else
|
||||
echo "$default_value"
|
||||
fi
|
||||
}
|
||||
|
||||
# 获取当前配置的哈希值(用于检测配置变化)
|
||||
get_config_hash() {
|
||||
local now_file="$(get_config "$PATH_CONFIG_DIR/now_bri_file.txt" "$DEFAULT_NOW_BRI_FILE")"
|
||||
echo "$now_file"
|
||||
}
|
||||
|
||||
# 日志函数
|
||||
_log() {
|
||||
@@ -39,14 +61,38 @@ while true; do
|
||||
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
|
||||
_log "检测到配置文件改变,将重启 inotifyd..."
|
||||
[ -f "$pid_file" ] && kill -9 "$(cat "$pid_file")" 2>/dev/null
|
||||
rm -f "$pid_file"
|
||||
echo "$current_config" >"$config_cache_file"
|
||||
sleep 1
|
||||
continue
|
||||
fi
|
||||
else
|
||||
# 第一次启动或缓存不存在,保存当前配置
|
||||
echo "$current_config" >"$config_cache_file"
|
||||
fi
|
||||
|
||||
# 正常启动并监听
|
||||
_log "启动 inotifyd 监听任务..."
|
||||
now_bri_file="$current_config"
|
||||
|
||||
# 更新缓存,让 up.sh 知道当前监听的是哪个文件
|
||||
echo -n "$now_bri_file" >"$PATH_CONFIG_DIR/.cached_path"
|
||||
|
||||
# 启动并重定向 (不再使用子进程管道以保证 PID 抓取准确)
|
||||
inotifyd "$MODDIR/script/up.sh" "$now_bri_file:c" >>"$log_file" 2>&1 &
|
||||
|
||||
inotify_pid=$!
|
||||
echo "$inotify_pid" >"$pid_file"
|
||||
_log "inotifyd 启动,PID: $inotify_pid,监听文件: $now_bri_file"
|
||||
|
||||
# 3. 通过 wait 阻塞,实时感知进程死亡 (兼容所有 BusyBox 环境)
|
||||
wait "$inotify_pid"
|
||||
|
||||
+29
-4
@@ -4,12 +4,31 @@
|
||||
|
||||
MODDIR="${0%/*/*}"
|
||||
CONFIG_DIR="$MODDIR/config"
|
||||
PATH_CONFIG_DIR="$CONFIG_DIR/path"
|
||||
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"
|
||||
now_bri_file="/sys/class/backlight/panel0-backlight/brightness"
|
||||
|
||||
# 默认设备路径
|
||||
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"
|
||||
else
|
||||
echo "$default_value"
|
||||
fi
|
||||
}
|
||||
|
||||
# 获取亮度文件路径
|
||||
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")"
|
||||
|
||||
# 日志函数
|
||||
_log() {
|
||||
@@ -47,9 +66,6 @@ if [ -f "$flag_file" ]; then
|
||||
fi
|
||||
touch "$flag_file"
|
||||
|
||||
# 节点文件
|
||||
now_bri_file="/sys/class/backlight/panel0-backlight/brightness"
|
||||
|
||||
# 读取配置 (均为数值)
|
||||
ui_max_bri="$(cat "$CONFIG_DIR/ui_max_bri.txt")"
|
||||
max_bri="$(cat "$CONFIG_DIR/max_bri.txt")"
|
||||
@@ -171,6 +187,15 @@ MAIN() {
|
||||
CHECK_BRI
|
||||
rm -f "$flag_file" # 删除成果锁
|
||||
rm -f "$pause_file" # 解锁守护进程,让它自动拉起 inotifyd
|
||||
|
||||
# 如果配置文件被修改了,杀掉 inotifyd 让 daemon 重启并重新读取配置
|
||||
local current_now_bri="$(cat "$PATH_CONFIG_DIR/now_bri_file.txt" 2>/dev/null || echo "$DEFAULT_NOW_BRI_FILE")"
|
||||
local cached_now_bri="$(cat "$PATH_CONFIG_DIR/.cached_path" 2>/dev/null || echo "$DEFAULT_NOW_BRI_FILE")"
|
||||
|
||||
if [ "$current_now_bri" != "$cached_now_bri" ]; then
|
||||
_log "[$$] 检测到设备路径配置已改变,重启 inotifyd..."
|
||||
killall -9 inotifyd 2>/dev/null
|
||||
fi
|
||||
}
|
||||
|
||||
MAIN
|
||||
|
||||
Reference in new issue
Block a user