mirror of
https://github.com/YuleBest/LuminPro.git
synced 2026-12-04 00:54:42 +08:00
perf(log): 优化日志消息
This commit is contained in:
1 parent
60aca52cf6
commit
21f6cb2744
6 files changed
+49
-43
No files matched your search
@@ -275,6 +275,9 @@ IMPORT_OLD_CONFIG() {
|
||||
if [ -s "$old_config/log_max_size.txt" ]; then
|
||||
echo " - 日志大小限制: $(cat "$old_config/log_max_size.txt") KB"
|
||||
fi
|
||||
if [ -s "$old_config/blacklist_apps.txt" ]; then
|
||||
echo " - 黑名单应用: $(wc -l <"$old_config/blacklist_apps.txt" | tr -d ' ') 个"
|
||||
fi
|
||||
echo ""
|
||||
echo "[?] 按音量 + 沿用旧配置, 按音量 - 重新测试"
|
||||
|
||||
@@ -290,6 +293,7 @@ IMPORT_OLD_CONFIG() {
|
||||
[ -s "$old_config/auto_bri_sleep.txt" ] && cp -f "$old_config/auto_bri_sleep.txt" "$mod_config/"
|
||||
[ -s "$old_config/steps_num.txt" ] && cp -f "$old_config/steps_num.txt" "$mod_config/"
|
||||
[ -s "$old_config/log_max_size.txt" ] && cp -f "$old_config/log_max_size.txt" "$mod_config/"
|
||||
[ -s "$old_config/blacklist_apps.txt" ] && cp -f "$old_config/blacklist_apps.txt" "$mod_config/"
|
||||
|
||||
# 迁移旧的路径配置(如果存在)
|
||||
mkdir -p "$mod_path_config"
|
||||
@@ -335,6 +339,7 @@ INIT_CONFIG() {
|
||||
[ ! -f "$mod_config/auto_bri_sleep.txt" ] && touch "$mod_config/auto_bri_sleep.txt"
|
||||
[ ! -f "$mod_config/steps_num.txt" ] && touch "$mod_config/steps_num.txt"
|
||||
[ ! -f "$mod_config/log_max_size.txt" ] && touch "$mod_config/log_max_size.txt"
|
||||
[ ! -f "$mod_config/blacklist_apps.txt" ] && touch "$mod_config/blacklist_apps.txt"
|
||||
|
||||
# 初始化设备路径配置 (仅在文件不存在时使用默认值,保留用户自定义配置)
|
||||
[ ! -f "$mod_path_config/now_bri_file.txt" ] && echo -n "$DEFAULT_NOW_BRI_FILE" >"$mod_path_config/now_bri_file.txt"
|
||||
@@ -378,6 +383,7 @@ CREATE_BACKUP() {
|
||||
cp -f "$mod_config/auto_bri_sleep.txt" "$mod_config/.backup/"
|
||||
cp -f "$mod_config/steps_num.txt" "$mod_config/.backup/"
|
||||
cp -f "$mod_config/log_max_size.txt" "$mod_config/.backup/"
|
||||
cp -f "$mod_config/blacklist_apps.txt" "$mod_config/.backup/"
|
||||
}
|
||||
|
||||
# 主函数
|
||||
|
||||
+6
-7
@@ -47,7 +47,7 @@ _log() {
|
||||
# 确保环境就绪
|
||||
mkdir -p "$PID_DIR"
|
||||
|
||||
_log "守护进程启动,开始监控配置文件..." "INFO"
|
||||
_log "守护进程已启动" "INFO"
|
||||
|
||||
while true; do
|
||||
# 检查是否需要手动停止或暂时挂起
|
||||
@@ -55,7 +55,7 @@ while true; do
|
||||
# 全局停止,杀掉现有并等待
|
||||
[ -f "$pid_file" ] && kill -9 "$(cat "$pid_file")" 2>/dev/null
|
||||
rm -f "$pid_file"
|
||||
_log "检测到停止信号,已暂停" "WARN"
|
||||
_log "检测到停止信号,守护进程挂起" "WARN"
|
||||
sleep 5
|
||||
continue
|
||||
fi
|
||||
@@ -75,7 +75,7 @@ while true; do
|
||||
if [ -f "$config_cache_file" ]; then
|
||||
cached_config="$(cat "$config_cache_file")"
|
||||
if [ "$current_config" != "$cached_config" ]; then
|
||||
_log "✓ 配置文件已更新,重启监听进程..." "WARN"
|
||||
_log "检测到配置变更,重启监听进程" "INFO"
|
||||
[ -f "$pid_file" ] && kill -9 "$(cat "$pid_file")" 2>/dev/null
|
||||
rm -f "$pid_file"
|
||||
echo "$current_config" >"$config_cache_file"
|
||||
@@ -88,7 +88,7 @@ while true; do
|
||||
fi
|
||||
|
||||
# 正常启动并监听
|
||||
_log "→ 启动 inotifyd 监听..." "INFO"
|
||||
_log "正在启动 inotifyd 监听" "INFO"
|
||||
now_bri_file="${current_config%|*}"
|
||||
inotify_events="${current_config#*|}"
|
||||
|
||||
@@ -100,12 +100,11 @@ while true; do
|
||||
|
||||
inotify_pid=$!
|
||||
echo "$inotify_pid" >"$pid_file"
|
||||
_log "✓ inotifyd 已启动 (PID: $inotify_pid)" "SUCCESS"
|
||||
_log " 监听文件: $now_bri_file, 事件: $inotify_events" "INFO"
|
||||
_log "inotifyd 已启动 (PID: $inotify_pid), 监听: $now_bri_file, 事件: $inotify_events" "SUCCESS"
|
||||
|
||||
# 3. 通过 wait 阻塞,实时感知进程死亡 (兼容所有 BusyBox 环境)
|
||||
wait "$inotify_pid"
|
||||
_log "[-] 监听进程 ($inotify_pid) 已退出,将在 1 秒后重启..." "WARN"
|
||||
_log "监听进程 (PID: $inotify_pid) 已退出,即将重启" "WARN"
|
||||
|
||||
sleep 0.5
|
||||
done
|
||||
+4
-4
@@ -11,12 +11,12 @@ _log() {
|
||||
printf '[%s] [restart] %s\n' "$(date '+%d %H:%M:%S.%3N')" "$1" >>"$log_file"
|
||||
}
|
||||
|
||||
_log "正在手动重启服务..."
|
||||
_log "收到手动重启请求"
|
||||
|
||||
pause_file="$PID_DIR/daemon.pause"
|
||||
|
||||
# 1. 强制通知守护进程并执行清理
|
||||
_log "通知守护进程执行全局重置..."
|
||||
_log "通知守护进程挂起,清理残余进程"
|
||||
touch "$pause_file"
|
||||
killall -9 inotifyd 2>/dev/null
|
||||
for p in $(pgrep -f "up.sh"); do
|
||||
@@ -26,10 +26,10 @@ done
|
||||
# 2. 清理遗留标记
|
||||
rm -f "$pid_file"
|
||||
rm -f "$flag_file"
|
||||
_log "已清理 pid 和 flag 锁文件"
|
||||
_log "已清理锁文件"
|
||||
|
||||
# 3. 恢复守护进程 (它会自动拉起新 inotifyd)
|
||||
rm -f "$pause_file"
|
||||
_log "服务正在由守护进程重新拉起..."
|
||||
_log "守护进程已恢复,等待自动拉起监听"
|
||||
|
||||
exit 0
|
||||
+28
-20
@@ -33,7 +33,7 @@ _log() {
|
||||
local level="${2:-INFO}"
|
||||
|
||||
case "$1" in
|
||||
"日志过大"*) ;;
|
||||
"日志超限"*) ;;
|
||||
*) if [ -f "$stop_file" ]; then return; fi ;;
|
||||
esac
|
||||
|
||||
@@ -46,15 +46,15 @@ _log() {
|
||||
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), 自动重置" >"$log_file"
|
||||
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 "[!] 正在抢占:清理其他 inotifyd 进程..." "WAIT"
|
||||
_log "收到 inotifyd 事件通知 (PID: $$)" "INFO"
|
||||
_log "正在接管控制权,清理残余进程..." "INFO"
|
||||
touch "$pause_file"
|
||||
killall -9 inotifyd 2>/dev/null
|
||||
for p in $(pgrep -f "up.sh"); do
|
||||
@@ -62,12 +62,12 @@ for p in $(pgrep -f "up.sh"); do
|
||||
done
|
||||
|
||||
if [ -f "$stop_file" ]; then
|
||||
_log "[X] 服务已处于手动暂停状态,本次操作被取消" "WARN"
|
||||
_log "服务已暂停,跳过本次处理" "WARN"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ -f "$flag_file" ]; then
|
||||
_log "[X] 另一个 up.sh 进程正在运行,本进程退出" "WARN"
|
||||
_log "检测到并发执行,当前进程退出" "WARN"
|
||||
exit 1
|
||||
fi
|
||||
touch "$flag_file"
|
||||
@@ -117,11 +117,11 @@ update_all() {
|
||||
|
||||
# 如果步长为 0 (差值太小), 直接设置目标亮度
|
||||
if [ "$step_value" -eq 0 ]; then
|
||||
_log "[OK] 直接设定亮度为: $target_bri" "INFO"
|
||||
_log "差值过小,直接设定亮度: $target_bri" "INFO"
|
||||
echo -n "$target_bri" >"$now_bri_file" && return 0 || return 1
|
||||
fi
|
||||
|
||||
_log "[*] 开始调整亮度: $start_bri -> $target_bri (共 $steps_num 步)" "INFO"
|
||||
_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
|
||||
@@ -141,29 +141,26 @@ CHECK_BRI() {
|
||||
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" "SUCCESS"
|
||||
_log "触发提升: 当前亮度 $now_bri ≥ 阈值 $ui_max_bri,目标 $target_bri" "INFO"
|
||||
|
||||
if update_all; then
|
||||
_log "[OK] 亮度提升已完成 (当前: $target_bri)" "SUCCESS"
|
||||
_log "================================================" "INFO"
|
||||
_log "亮度提升完成 ($target_bri)" "SUCCESS"
|
||||
return 0
|
||||
else
|
||||
_log "[X] 亮度提升失败:无法写入节点文件" "ERROR"
|
||||
_log "================================================" "ERROR"
|
||||
_log "亮度提升失败: 无法写入亮度节点" "ERROR"
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
sleep 0.3
|
||||
done
|
||||
_log "[-] 检测超时:未持续触发有效提升阈值" "WARN"
|
||||
_log "检测超时: 亮度未持续达到提升阈值" "INFO"
|
||||
return 1
|
||||
}
|
||||
|
||||
MAIN() {
|
||||
# 解析并判断休眠
|
||||
if IS_SLEEP_TIME; then
|
||||
_log "[||] 休眠时段 ($sleep_start-$sleep_end),本次调整已跳过" "INFO"
|
||||
_log "================================================" "INFO"
|
||||
_log "处于休眠时段 ($sleep_start-$sleep_end),跳过提升" "INFO"
|
||||
rm -f "$flag_file"
|
||||
return
|
||||
fi
|
||||
@@ -171,14 +168,25 @@ MAIN() {
|
||||
if [ "$auto_bri_sleep" = "1" ]; then
|
||||
mode="$(settings get system screen_brightness_mode 2>/dev/null)"
|
||||
if [ "$mode" = "1" ]; then
|
||||
_log "[<>] 自动亮度模式已启用,本次调整已跳过" "INFO"
|
||||
_log "================================================" "INFO"
|
||||
_log "自动亮度已启用,跳过提升" "INFO"
|
||||
rm -f "$flag_file"
|
||||
return
|
||||
fi
|
||||
fi
|
||||
|
||||
_log "[*] 检测亮度变化..." "INFO"
|
||||
# 黑名单应用检测
|
||||
local blacklist_file="$CONFIG_DIR/blacklist_apps.txt"
|
||||
if [ -f "$blacklist_file" ] && [ -s "$blacklist_file" ]; then
|
||||
local current_app
|
||||
current_app="$(dumpsys window | grep mCurrentFocus | sed 's/.*u0 \(.*\)\/.*/\1/')"
|
||||
if [ -n "$current_app" ] && grep -qxF "$current_app" "$blacklist_file"; then
|
||||
_log "当前前台应用 ($current_app) 在黑名单中,跳过提升" "INFO"
|
||||
rm -f "$flag_file"
|
||||
return
|
||||
fi
|
||||
fi
|
||||
|
||||
_log "正在检测亮度变化..." "INFO"
|
||||
# sleep 0.5
|
||||
CHECK_BRI
|
||||
rm -f "$flag_file" # 删除成果锁
|
||||
@@ -190,7 +198,7 @@ MAIN() {
|
||||
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..." "WARN"
|
||||
_log "检测到监听路径变更,重启 inotifyd" "INFO"
|
||||
killall -9 inotifyd 2>/dev/null
|
||||
fi
|
||||
}
|
||||
|
||||
+3
-5
@@ -29,11 +29,10 @@ _log() {
|
||||
# 等待系统就绪
|
||||
sleep 30
|
||||
|
||||
_log "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" "START"
|
||||
_log "LuminPro 模块已启动" "SUCCESS"
|
||||
_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 "休眠时段: $(cat "$CONFIG_DIR/sleep_time.txt")" "INFO"
|
||||
|
||||
# 读取设备路径配置
|
||||
now_bri_file="$(get_config "$PATH_CONFIG_DIR/now_bri_file.txt" "$DEFAULT_NOW_BRI_FILE")"
|
||||
@@ -41,13 +40,12 @@ max_bri_file="$(get_config "$PATH_CONFIG_DIR/max_bri_file.txt" "$DEFAULT_MAX_BRI
|
||||
_log "当前亮度节点: $now_bri_file" "INFO"
|
||||
_log "最大亮度节点: $max_bri_file" "INFO"
|
||||
|
||||
_log "启动守护监控进程..." "WAIT"
|
||||
_log "正在启动守护进程" "INFO"
|
||||
chmod 755 "$MODDIR/script/up.sh"
|
||||
chmod 755 "$MODDIR/script/daemon.sh"
|
||||
|
||||
# 启动守护进程
|
||||
sh "$MODDIR/script/daemon.sh" &
|
||||
_log "守护进程已启动 (PID: $!)" "SUCCESS"
|
||||
_log "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" "DONE"
|
||||
|
||||
exit 0
|
||||
+2
-7
@@ -610,16 +610,11 @@ input:checked + .slider:before {
|
||||
.brightness-slider::-webkit-slider-thumb {
|
||||
-webkit-appearance: none;
|
||||
appearance: none;
|
||||
width: 24px; /* 仍然保持一个可抓取的宽度,但不着色 */
|
||||
height: 24px;
|
||||
width: 0;
|
||||
height: 0;
|
||||
background: transparent;
|
||||
cursor: grab;
|
||||
border: none;
|
||||
border-radius: 0;
|
||||
}
|
||||
|
||||
.brightness-slider:hover::-webkit-slider-thumb {
|
||||
height: 28px;
|
||||
}
|
||||
|
||||
.brightness-slider::-webkit-slider-thumb:active {
|
||||
|
||||
Reference in new issue
Block a user