perf(config): 配置继承优化

This commit is contained in:
YuleBest committed 2026-04-09 08:55:04 +08:00
1 parent 4f3d25ac5a
commit 0eef2358f0
19 files changed
+126 -678

No files matched your search

+8
View File
@@ -0,0 +1,8 @@
b1ac7dab449904d761b64b59192b217387ca5ab8b9a36a581c257078c36d8032 action.sh
6bc62f25981328edd3cfcfe6fe51b073f2d7e7710d7ef7fcdac28d4e384fc3d4 bin/jq
0c2d380d5171449802d1dc62ffa312c0ff9a41c73216c1159324a85705d02f0e boost.sh
8b3080197fa7ac3511717d901f509327e9a3e7db1de61d660f83f9ebf55913fd customize.sh
397ae139ce6f759828a3ebf1e9469d804ce5dabb06039271c65942990c06cbb0 script/daemon.sh
dba55a38466598334b47d19b720aec5402988333e1565668066c6a585be0d4ce script/restart.sh
077d25cae2d464ae4b131faa41a298a1eecbd695f13218d91679a74523bf9fee script/up.sh
d84d1fe9c69feaf94055eda18cdc12695b3191071ae0931e82ebf36bcd3e3400 service.sh
-38
View File
@@ -43,41 +43,3 @@ else
fi
exit 0
# 默认设备路径
DEFAULT_NOW_BRI_FILE="/sys/class/backlight/panel0-backlight/brightness"
# 读取配置的路径,如果不存在则回退至默认值
if [ -f "$PATH_CONFIG_DIR/now_bri_file.txt" ]; then
now_bri_file="$(cat "$PATH_CONFIG_DIR/now_bri_file.txt" 2>/dev/null | tr -d ' \n')"
fi
[ -z "$now_bri_file" ] && 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')"
if [ -n "$restore_bri" ]; then
echo -n "$restore_bri" >"$now_bri_file" 2>/dev/null
fi
rm -f "$BOOST_FLAG"
else
max_bri="$(cat "$CONFIG_DIR/max_bri.txt" 2>/dev/null | tr -d ' \n')"
if [ -z "$max_bri" ]; 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
+48 -3
View File
@@ -1,4 +1,6 @@
import fs from 'fs';
import path from 'path';
import crypto from 'crypto';
import archiver from 'archiver';
// 读取版本信息用以命名
@@ -21,15 +23,13 @@ if (fs.existsSync(updateJsonPath)) {
updateJson.version = version;
updateJson.zipUrl = `https://share.yule.ink/magisk/mod/luminpro/module/${zipName}`;
fs.writeFileSync(updateJsonPath, JSON.stringify(updateJson, null, 4), 'utf-8');
console.log(`>>> [1/2] 已同步 update.json (版本: ${version}, Code: ${versionCode})`);
console.log(`>>> [1/3] 已同步 update.json (版本: ${version}, Code: ${versionCode})`);
} catch (e) {
console.error(`[错误] 无法更新 update.json: ${e.message}`);
}
}
// ---------------------------------
console.log(`\n>>> [2/2] 创建模块 ZIP 压缩包...`);
// 明确需要忽略的文件清单
const excludes = [
'docs',
@@ -46,6 +46,35 @@ const excludes = [
zipName
];
console.log(`\n>>> [2/3] 生成 SHA256SUMS...`);
// 计算可执行文件(所有 .sh 脚本 + bin/ 二进制)的 SHA256
function sha256File(filePath) {
return crypto.createHash('sha256').update(fs.readFileSync(filePath)).digest('hex');
}
function collectExecutables(dir, baseDir = dir) {
const results = [];
for (const dirent of fs.readdirSync(dir, { withFileTypes: true })) {
const full = path.join(dir, dirent.name);
const rel = path.relative(baseDir, full).replace(/\\/g, '/');
if (dirent.isDirectory()) {
results.push(...collectExecutables(full, baseDir));
} else if (dirent.name.endsWith('.sh') || dir.endsWith('bin')) {
results.push(rel);
}
}
return results;
}
const execFiles = collectExecutables('.').filter(f => !excludes.some(e => f.startsWith(e)));
const sha256Lines = execFiles.sort().map(f => `${sha256File(f)} ${f}`);
const sha256SumsPath = 'SHA256SUMS';
fs.writeFileSync(sha256SumsPath, sha256Lines.join('\n') + '\n', 'utf-8');
console.log(`已生成 ${sha256Lines.length} 条记录:\n${sha256Lines.join('\n')}`);
console.log(`\n>>> [3/3] 创建模块 ZIP 压缩包...`);
// 初始化归档器
const output = fs.createWriteStream(zipName);
const archive = archiver('zip', {
@@ -73,6 +102,22 @@ archive.on('error', function (err) {
archive.pipe(output);
// 将所有 .sh 文件统一转换为 LF 换行符,防止 Windows 环境写入 CRLF 导致 ash 报错
function fixLineEndings(dir) {
for (const dirent of fs.readdirSync(dir, { withFileTypes: true })) {
const full = path.join(dir, dirent.name);
if (dirent.isDirectory() && !excludes.includes(dirent.name)) {
fixLineEndings(full);
} else if (dirent.name.endsWith('.sh')) {
const content = fs.readFileSync(full, 'utf8');
if (content.includes('\r\n')) {
fs.writeFileSync(full, content.replace(/\r\n/g, '\n'), 'utf8');
}
}
}
}
fixLineEndings('.');
// 将没在排除列表里的文件打进去
const dirContents = fs.readdirSync('.', { withFileTypes: true });
+50 -398
View File
@@ -203,6 +203,19 @@ IMPORT_OLD_CONFIG() {
echo "[?] 按音量 + 沿用旧配置, 按音量 - 重新测试"
if [ "$(btn)" = "0" ]; then
cp -f "$old_config/config.json" "$CONFIG_FILE"
# 若旧 JSON 缺少 blacklist_apps 字段,尝试从 blacklist_apps.txt 补入
if ! "$JQ" -e '.blacklist_apps' "$CONFIG_FILE" >/dev/null 2>&1; then
local bl_arr
if [ -s "$old_config/blacklist_apps.txt" ]; then
bl_arr=$("$JQ" -Rs 'split("\n") | map(select(length > 0))' \
"$old_config/blacklist_apps.txt" 2>/dev/null || echo '[]')
else
bl_arr='[]'
fi
local tmp_cfg="$CONFIG_FILE.tmp"
"$JQ" --argjson bl "$bl_arr" '. + {blacklist_apps: $bl}' \
"$CONFIG_FILE" >"$tmp_cfg" && mv -f "$tmp_cfg" "$CONFIG_FILE"
fi
echo "[OK] 已导入 JSON 配置"
return 0
else
@@ -349,8 +362,43 @@ END() {
fi
echo ""
echo "======== 模块策略 ========"
echo "[*] 当亮度达到 [ $final_ui ] 时,自动提升至 [ $final_max ]"
echo "======== 将要应用的配置 ========"
echo "[*] 前台最大亮度: $final_ui"
echo "[*] 峰值最大亮度: $final_max"
local steps log_size auto_bri disp_hdr st inotify bl_count now_path max_path
steps=$("$JQ" -re '.steps_num' "$CONFIG_FILE" 2>/dev/null || echo "50")
log_size=$("$JQ" -re '.log_max_size' "$CONFIG_FILE" 2>/dev/null || echo "512")
auto_bri=$("$JQ" -re '.auto_bri_sleep' "$CONFIG_FILE" 2>/dev/null || echo "1")
disp_hdr=$("$JQ" -re '.display_hdr_sleep' "$CONFIG_FILE" 2>/dev/null || echo "0")
st=$("$JQ" -re '.sleep_time // empty' "$CONFIG_FILE" 2>/dev/null)
inotify=$("$JQ" -re '.inotify_events' "$CONFIG_FILE" 2>/dev/null || echo "c")
now_path=$("$JQ" -re '.now_bri_file' "$CONFIG_FILE" 2>/dev/null || echo "$DEFAULT_NOW_BRI_FILE")
max_path=$("$JQ" -re '.max_bri_file' "$CONFIG_FILE" 2>/dev/null || echo "$DEFAULT_MAX_BRI_FILE")
bl_count=$("$JQ" -re '.blacklist_apps | length' "$CONFIG_FILE" 2>/dev/null || echo "0")
echo "[*] 亮度渐变步数: $steps"
echo "[*] 日志大小上限: ${log_size} KB"
if [ "$auto_bri" = "1" ]; then
echo "[*] 自动亮度时跳过: 开启"
else
echo "[*] 自动亮度时跳过: 关闭"
fi
if [ "$disp_hdr" = "1" ]; then
echo "[*] HDR 内容时跳过: 开启"
else
echo "[*] HDR 内容时跳过: 关闭"
fi
if [ -n "$st" ]; then
echo "[*] 休眠时段: $st"
else
echo "[*] 休眠时段: 未配置"
fi
echo "[*] inotifyd 事件: $inotify"
echo "[*] 当前亮度节点: $now_path"
echo "[*] 最大亮度节点: $max_path"
echo "[*] 黑名单应用: ${bl_count} 个"
echo "==============================="
echo "[i] 配置文件: /data/adb/modules/LuminPro/config/config.json"
echo "[i] 也可以使用 Web UI 进行配置"
echo ""
@@ -377,399 +425,3 @@ MAIN() {
}
MAIN
# 创建配置目录
[ -d "$mod_config" ] || mkdir -p "$mod_config"
[ -d "$mod_path_config" ] || mkdir -p "$mod_path_config"
# ==========================
# 配置读取函数
# ==========================
# 优先读取旧配置,其次读取默认配置
get_config_value() {
local config_name="$1"
local old_file="$old_config/$config_name"
local new_file="$mod_config/$config_name"
local default_value="$2"
# 1. 检查旧配置是否存在且非空
if [ -f "$old_file" ]; then
local old_val
old_val="$(cat "$old_file" 2>/dev/null | tr -d ' \n')"
if [ -n "$old_val" ]; then
echo "$old_val"
return
fi
fi
# 2. 检查默认配置是否存在且非空
if [ -f "$new_file" ]; then
local new_val
new_val="$(cat "$new_file" 2>/dev/null | tr -d ' \n')"
if [ -n "$new_val" ]; then
echo "$new_val"
return
fi
fi
# 3. 返回默认值
echo "$default_value"
}
# 获取设备路径函数(与 get_config_value 相同逻辑)
get_device_path() {
local config_name="$1"
local default_path="$2"
get_config_value "$config_name" "$default_path"
}
# 初始化全局变量(优先读取旧配置,其次读取默认值)
now_bri_file="$(get_device_path "path/now_bri_file.txt" "$DEFAULT_NOW_BRI_FILE")"
max_bri_file="$(get_device_path "path/max_bri_file.txt" "$DEFAULT_MAX_BRI_FILE")"
# 检查亮度节点文件
CHECK_FILES() {
sleep 1
echo ""
echo "[*] 正在验证设备亮度节点..."
echo ""
# 验证路径是否存在
echo "- 当前亮度节点: $now_bri_file"
echo "- 最大亮度节点: $max_bri_file"
echo ""
if [ -f "$now_bri_file" ] && [ -f "$max_bri_file" ]; then
echo "[OK] 找到亮度节点文件"
else
echo "[X] 未找到亮度节点文件"
if [ ! -f "$now_bri_file" ]; then
echo " - 当前亮度节点不存在: $now_bri_file"
fi
if [ ! -f "$max_bri_file" ]; then
echo " - 最大亮度节点不存在: $max_bri_file"
fi
echo ""
echo "设备不支持默认路径,需要修改配置"
echo "修改方法:"
echo " 1. 编辑压缩包内的 config/path/now_bri_file.txt"
echo " 2. 编辑压缩包内的 config/path/max_bri_file.txt"
echo " 3. 添加你设备的正确亮度节点路径"
echo " 4. 重新打包并刷入模块"
echo ""
echo "查找路径的方法:"
echo " find /sys -name '*brightness*' 2>/dev/null | grep -E '(brightness|lcd)'"
abort "[X] 安装中止:无法找到设备亮度节点"
fi
now_bri="$(cat "$now_bri_file")"
max_bri_sys="$(cat "$max_bri_file")"
echo "[OK] 当前亮度: $now_bri"
echo "[OK] 系统最大亮度: $max_bri_sys"
}
# 监听音量键函数
button_listener() {
local choose
local branch
while :; do
choose="$(getevent -qlc 1 | awk '{ print $3 }')"
case "$choose" in
KEY_VOLUMEUP) branch="0" ;;
KEY_VOLUMEDOWN) branch="1" ;;
*) continue ;;
esac
echo "$branch"
break
done
}
# 注意事项
SHOW_CHANGELOG() {
local changelog_file="$MODPATH/changelog.md"
if [ -f "$changelog_file" ]; then
echo "========================================"
echo "[*] 本次更新日志:"
# 提取第一个二级标题及其内容,直到遇到下一个二级标题或文件结束
# 使用更具兼容性的 awk 逻辑
awk '/^## / { if (p) exit; p=1; print; next } p { print }' "$changelog_file"
echo "========================================"
fi
}
NOTE() {
cat "$MODPATH/NOTE.txt"
echo ""
echo "[i] 按音量 + 进入下一步, 按音量 - 退出"
echo "[i] 继续则表明你已理解并接受所有风险"
if [ "$(button_listener)" = "0" ]; then
echo "[OK] 已确认进入下一步"
else
abort "[X] 已退出"
fi
}
# 测试前台最大亮度
TEST_UI_MAX_BRI() {
echo ""
echo "[*] 开始测试前台最大亮度"
echo ""
sleep 1
echo "======== 请关闭自动亮度 ========"
echo "[i] 按音量 + 进入下一步, 按音量 - 退出"
if [ "$(button_listener)" = "0" ]; then
echo "[OK] 已确认进入下一步"
else
abort "[X] 已退出"
fi
# 调整亮度前, 记录当前亮度用于之后恢复
restore_bri="$(cat "$now_bri_file")"
echo ""
sleep 1
echo "======== 请将屏幕亮度调至最大 ========"
echo "[i] 按音量 + 进入下一步, 按音量 - 退出"
if [ "$(button_listener)" = "0" ]; then
echo "[OK] 已确认进入下一步"
else
abort "[X] 已退出"
fi
ui_max_bri="$(cat "$now_bri_file")"
echo "[OK] 前台最大亮度: [ $ui_max_bri ]"
# 保存到旧配置和新配置
echo -n "$ui_max_bri" >"$old_config/ui_max_bri.txt"
echo -n "$ui_max_bri" >"$mod_config/ui_max_bri.txt"
echo ""
echo "[i] 峰值最大亮度由节点文件获得: [ $max_bri_sys ]"
echo "[i] 若不符合预期, 请稍后到配置文件或 Web UI 更改"
# 保存到旧配置和新配置
echo -n "$max_bri_sys" >"$old_config/max_bri.txt"
echo -n "$max_bri_sys" >"$mod_config/max_bri.txt"
echo ""
echo "[OK] 测试完成"
echo "[*] 正在为你恢复亮度..."
echo -n "$restore_bri" >"$now_bri_file"
}
# 结束
END() {
echo ""
sleep 1
# 读取最终配置
local final_max_bri
local final_ui_max_bri
final_max_bri="$(get_config_value "max_bri.txt" "")"
final_ui_max_bri="$(get_config_value "ui_max_bri.txt" "")"
# 检查是否需要重新测试
if [ -z "$final_max_bri" ] || [ -z "$final_ui_max_bri" ]; then
echo ""
echo "[!] ======== 配置不完整 ========"
if [ -z "$final_max_bri" ]; then
echo "[X] 峰值最大亮度: 未配置"
else
echo "[OK] 峰值最大亮度: $final_max_bri"
fi
if [ -z "$final_ui_max_bri" ]; then
echo "[X] 前台最大亮度: 未配置"
else
echo "[OK] 前台最大亮度: $final_ui_max_bri"
fi
echo ""
echo "[!] 检测到配置缺失,需要重新进行亮度测试。"
echo "[i] 请在模块安装后的重启后,通过以下方式补全配置:"
echo " 1. 使用 Web UI 手工输入"
echo " 2. 编辑配置文件: /data/adb/modules/LuminPro/config/"
echo " 3. 重新刷入新的压缩包(会重新运行此脚本)"
echo ""
echo "[i] 或按音量 + 现在进行测试, 按音量 - 跳过"
if [ "$(button_listener)" = "0" ]; then
echo "[*] 正在进行测试..."
TEST_UI_MAX_BRI
final_max_bri="$(get_config_value "max_bri.txt" "")"
final_ui_max_bri="$(get_config_value "ui_max_bri.txt" "")"
fi
fi
echo ""
echo "======== 模块策略 ========"
echo "[*] 当亮度达到 [ $final_ui_max_bri ] 时,自动提升至 [ $final_max_bri ]"
echo "[i] 配置目录: /data/adb/modules/LuminPro/config"
echo "[i] 也可以使用 Web UI 进行配置"
echo ""
echo "[OK] 模块已刷入,请重启手机"
echo "[i] 感谢您的使用"
echo "[i] 作者: 酷安 @于乐yule"
echo ""
sleep 1
exit 0
}
# 导入旧配置
IMPORT_OLD_CONFIG() {
if [ -d "$old_config" ] &&
[ -s "$old_config/ui_max_bri.txt" ] &&
[ -s "$old_config/max_bri.txt" ]; then
echo ""
sleep 1
echo "[i] 检测到已有配置:"
echo " - 前台最大亮度: $(cat "$old_config/ui_max_bri.txt")"
echo " - 峰值最大亮度: $(cat "$old_config/max_bri.txt")"
if [ -s "$old_config/sleep_time.txt" ]; then
echo " - 休眠时间: $(cat "$old_config/sleep_time.txt")"
fi
if [ -s "$old_config/auto_bri_sleep.txt" ]; then
echo " - 自动亮度时休眠: $(cat "$old_config/auto_bri_sleep.txt" | sed 's/1/开启/;s/0/关闭/')"
fi
if [ -s "$old_config/steps_num.txt" ]; then
echo " - 亮度提升步数: $(cat "$old_config/steps_num.txt")"
fi
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 "[?] 按音量 + 沿用旧配置, 按音量 - 重新测试"
if [ "$(button_listener)" = "0" ]; then
echo "[OK] 已沿用旧配置"
cp -f "$old_config/ui_max_bri.txt" "$mod_config/"
cp -f "$old_config/max_bri.txt" "$mod_config/"
if [ -e "$old_config/sleep_time.txt" ]; then
cp -f "$old_config/sleep_time.txt" "$mod_config/"
else
touch "$mod_config/sleep_time.txt"
fi
[ -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/"
[ -s "$old_config/display_hdr_sleep.txt" ] && cp -f "$old_config/display_hdr_sleep.txt" "$mod_config/"
# 迁移旧的路径配置(如果存在)
mkdir -p "$mod_path_config"
if [ -d "$old_path_config" ]; then
[ -s "$old_path_config/now_bri_file.txt" ] && cp -f "$old_path_config/now_bri_file.txt" "$mod_path_config/"
[ -s "$old_path_config/max_bri_file.txt" ] && cp -f "$old_path_config/max_bri_file.txt" "$mod_path_config/"
else
# 创建默认路径配置
echo -n "$DEFAULT_NOW_BRI_FILE" >"$mod_path_config/now_bri_file.txt"
echo -n "$DEFAULT_MAX_BRI_FILE" >"$mod_path_config/max_bri_file.txt"
fi
# 版本迁移逻辑
local old_version_code
old_version_code="$(grep_get_prop versionCode "/data/adb/modules/LuminPro/module.prop")"
if [ "$old_version_code" = "2101" ] && [ ! -d "$old_config/.backup" ]; then
echo "[i] 检测到从 2101 版本升级,正在补全备份目录..."
mkdir -p "$mod_config/.backup"
cp -f "$mod_config/"*.txt "$mod_config/.backup/" 2>/dev/null
else
# 正常备份同步
mkdir -p "$mod_config/.backup"
[ -d "$old_config/.backup" ] && cp -rf "$old_config/.backup/." "$mod_config/.backup/"
fi
return 0
else
echo "[*] 将重新测试"
return 1
fi
fi
return 1
}
# 初始化默认配置文件
INIT_CONFIG() {
mkdir -p "$mod_config"
mkdir -p "$mod_path_config"
# 仅在文件不存在时才创建,保留任何已存在的配置
[ ! -f "$mod_config/ui_max_bri.txt" ] && touch "$mod_config/ui_max_bri.txt"
[ ! -f "$mod_config/max_bri.txt" ] && touch "$mod_config/max_bri.txt"
[ ! -f "$mod_config/sleep_time.txt" ] && touch "$mod_config/sleep_time.txt"
[ ! -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_config/display_hdr_sleep.txt" ] && touch "$mod_config/display_hdr_sleep.txt"
# 初始化设备路径配置 (仅在文件不存在时使用默认值,保留用户自定义配置)
[ ! -f "$mod_path_config/now_bri_file.txt" ] && echo -n "$DEFAULT_NOW_BRI_FILE" >"$mod_path_config/now_bri_file.txt"
[ ! -f "$mod_path_config/max_bri_file.txt" ] && echo -n "$DEFAULT_MAX_BRI_FILE" >"$mod_path_config/max_bri_file.txt"
}
# 补全缺失设置并设定默认值
ENSURE_DEFAULTS() {
[ ! -f "$mod_config/sleep_time.txt" ] && touch "$mod_config/sleep_time.txt"
[ ! -s "$mod_config/auto_bri_sleep.txt" ] && echo "1" >"$mod_config/auto_bri_sleep.txt"
[ ! -s "$mod_config/steps_num.txt" ] && echo "50" >"$mod_config/steps_num.txt"
[ ! -s "$mod_config/log_max_size.txt" ] && echo "500" >"$mod_config/log_max_size.txt"
}
# 机型兼容性校验
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 [ "$(button_listener)" = "0" ]; then
echo -n "0" >"$mod_config/inotify_events.txt"
echo "[OK] 已设置为 0 事件监测"
else
echo "[*] 已跳过配置更改"
fi
sleep 1
fi
}
# 创建备份 (用于 WebUI 恢复默认)
CREATE_BACKUP() {
mkdir -p "$mod_config/.backup"
cp -f "$mod_config/ui_max_bri.txt" "$mod_config/.backup/"
cp -f "$mod_config/max_bri.txt" "$mod_config/.backup/"
cp -f "$mod_config/sleep_time.txt" "$mod_config/.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/"
cp -f "$mod_config/display_hdr_sleep.txt" "$mod_config/.backup/"
}
# 主函数
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
-219
View File
@@ -217,222 +217,3 @@ MAIN() {
MAIN
exit 0
# 日志函数
_log() {
local level="${2:-INFO}"
case "$1" in
"日志超限"*) ;;
*) if [ -f "$stop_file" ]; then return; fi ;;
esac
local max_size
max_size="$(cat "$CONFIG_DIR/log_max_size.txt" 2>/dev/null)"
[ -z "$max_size" ] && max_size="500" # 默认 500 KB
# 获取当前日志大小 (KB)
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="$(cat "$CONFIG_DIR/ui_max_bri.txt")"
max_bri="$(cat "$CONFIG_DIR/max_bri.txt")"
sleep_time="$(cat "$CONFIG_DIR/sleep_time.txt" 2>/dev/null)"
auto_bri_sleep="$(cat "$CONFIG_DIR/auto_bri_sleep.txt" 2>/dev/null)"
display_hdr_sleep="$(cat "$CONFIG_DIR/display_hdr_sleep.txt" 2>/dev/null)"
# 解析休眠时间 (格式: HHMM-HHMM, 例如 1900-0600)
sleep_start="${sleep_time%-*}" # 1900
sleep_end="${sleep_time#*-}" # 0600
# 判断当前是否处于休眠时段
IS_SLEEP_TIME() {
local now
now="$(date '+%H%M')" # 当前时间, 例如 "2130"
# 未配置或格式无效则不休眠
[ -z "$sleep_start" ] || [ -z "$sleep_end" ] && return 1
# 起止相同表示不启用休眠
[ "$sleep_start" = "$sleep_end" ] && return 1
if [ "$sleep_start" -gt "$sleep_end" ]; then
# 跨午夜: 1900-0600 → 当前 >= 19:00 或 当前 < 06:00
[ "$now" -ge "$sleep_start" ] || [ "$now" -lt "$sleep_end" ]
else
# 不跨午夜: 0100-0600 → 当前 >= 01:00 且 当前 < 06:00
[ "$now" -ge "$sleep_start" ] && [ "$now" -lt "$sleep_end" ]
fi
}
# 目标亮度
target_bri="$max_bri"
steps_num="$(cat "$CONFIG_DIR/steps_num.txt" 2>/dev/null)"
[ -z "$steps_num" ] && steps_num="50" # 步数 (默认 50)
# 循环调整
update_all() {
local step
# 在调整前的这一刻读取当前亮度作为起始值
start_bri="$(cat "$now_bri_file")"
bri_diff="$((target_bri - start_bri))"
step_value="$((bri_diff / steps_num))"
# 如果步长为 0 (差值太小), 直接设置目标亮度
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
local now_bri
# 循环 10 次 (检查 3s)
# 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
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
# 黑名单应用检测(支持包名和完整 package/activity 两种格式)
local blacklist_file="$CONFIG_DIR/blacklist_apps.txt"
if [ -f "$blacklist_file" ] && [ -s "$blacklist_file" ]; then
local current_focus current_app
current_focus="$(dumpsys window | grep mCurrentFocus | sed 's/.*u0 \(.*\)}/\1/')"
current_app="${current_focus%%/*}"
if [ -n "$current_focus" ] && { grep -qxF "$current_focus" "$blacklist_file" || grep -qxF "$current_app" "$blacklist_file"; }; 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"
# 冷却期检查:读取写入时间戳,判断是否在 2 秒内
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 hdr_ratio_rounded
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
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"
# 写入当前时间戳作为冷却期起点(2 秒内再次触发直接跳过)
date +%s >"$hdr_flag_file"
rm -f "$flag_file" "$pause_file"
return
fi
fi
fi
_log "正在检测亮度变化..." "INFO"
# sleep 0.5
CHECK_BRI
rm -f "$flag_file" # 删除成果锁
rm -f "$pause_file" # 解锁守护进程,让它自动拉起 inotifyd
# 如果配置文件被修改了,杀掉 inotifyd 让 daemon 重启并重新读取配置
local current_now_bri cached_now_bri
current_now_bri="$(cat "$PATH_CONFIG_DIR/now_bri_file.txt" 2>/dev/null || echo "$DEFAULT_NOW_BRI_FILE")"
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" "INFO"
killall -9 inotifyd 2>/dev/null
fi
}
MAIN
exit 0
Binary file not shown.
Binary file not shown.
+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-C2fN6L9t.js"></script>
<link rel="stylesheet" crossorigin href="/assets/index-DjaknYwM.css">
<script type="module" crossorigin src="/assets/index-DR4CWo6g.js"></script>
<link rel="stylesheet" crossorigin href="/assets/index-N1q1T35U.css">
</head>
<body>
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+1 -1
View File
@@ -195,7 +195,7 @@
background-color: var(--md-sys-color-surface-container);
padding: 2px 6px;
border-radius: 4px;
font-family: 'Google Sans Code', monospace;
font-family: 'Geist Mono', monospace;
font-size: 0.85em;
}
+5 -5
View File
@@ -157,7 +157,7 @@
.app-pkg {
font-size: 0.8125rem;
color: var(--md-sys-color-on-surface-variant);
font-family: 'Google Sans Code', monospace;
font-family: 'Geist Mono', monospace;
display: flex;
flex-wrap: wrap;
align-items: center;
@@ -206,7 +206,7 @@
border: 1px solid var(--md-sys-color-outline-variant);
padding: 0 4px;
border-radius: 4px;
font-family: 'Google Sans Code', monospace;
font-family: 'Geist Mono', monospace;
margin-left: 6px;
vertical-align: middle;
}
@@ -275,7 +275,7 @@
.activity-entry-path {
flex: 1;
font-family: 'Google Sans Code', 'Roboto Mono', monospace;
font-family: 'Geist Mono', 'Roboto Mono', monospace;
font-size: 0.75rem;
color: var(--md-sys-color-on-surface-variant);
word-break: break-all;
@@ -359,7 +359,7 @@
border: 1px solid var(--md-sys-color-outline-variant);
border-radius: var(--border-radius-s);
padding: 7px 10px;
font-family: 'Google Sans Code', 'Roboto Mono', monospace;
font-family: 'Geist Mono', 'Roboto Mono', monospace;
font-size: 0.8125rem;
color: var(--md-sys-color-on-surface);
outline: none;
@@ -513,7 +513,7 @@
border: 1.5px solid var(--md-sys-color-primary);
border-radius: var(--border-radius-m);
padding: 14px 18px;
font-family: 'Google Sans Code', 'Roboto Mono', monospace;
font-family: 'Geist Mono', 'Roboto Mono', monospace;
font-size: 0.875rem;
color: var(--md-sys-color-on-surface);
word-break: break-all;
+2 -2
View File
@@ -146,7 +146,7 @@
border-radius: var(--border-radius-m);
resize: vertical;
padding: 10px 14px;
font-family: 'Google Sans Code', system-ui, monospace;
font-family: 'Geist Mono', system-ui, monospace;
font-size: 0.875rem;
line-height: 1.4;
transition: all 0.2s ease;
@@ -203,7 +203,7 @@
border: none;
font-size: 0.875rem;
text-align: center;
font-family: 'Google Sans Code', monospace;
font-family: 'Geist Mono', monospace;
outline: none;
-moz-appearance: textfield;
}
+5 -5
View File
@@ -1,7 +1,7 @@
import { ref, reactive } from 'vue';
import { listPackages, getPackagesInfo } from 'kernelsu';
import PinyinMatch from 'pinyin-match';
import { runCmd, writeFile, CONFIG_DIR } from '../utils.js';
import { runCmd, readConfig, updateConfig } from '../utils.js';
export function useApps() {
const apps = ref([]);
@@ -18,8 +18,8 @@ export function useApps() {
isLoading.value = true;
loadError.value = '';
try {
const blRes = await runCmd(`cat "${CONFIG_DIR}/blacklist_apps.txt"`);
const allSaved = blRes.errno === 0 ? blRes.stdout.trim().split('\n').filter(Boolean) : [];
const cfg = await readConfig();
const allSaved = Array.isArray(cfg.blacklist_apps) ? cfg.blacklist_apps : [];
savedBlacklist.value = new Set(allSaved);
const savedPkgSet = new Set(allSaved.filter(e => !e.includes('/')));
activityEntries.value = new Set(allSaved.filter(e => e.includes('/')));
@@ -100,8 +100,8 @@ export function useApps() {
toast('保存中...');
const selectedPkgs = apps.value.filter(a => a.checked).map(a => a.packageName);
const allEntries = [...selectedPkgs, ...activityEntries.value];
const res = await writeFile(`${CONFIG_DIR}/blacklist_apps.txt`, allEntries.join('\n'));
if (res.errno === 0 || res.stdout?.includes('OK')) {
const res = await updateConfig({ blacklist_apps: allEntries });
if (res.errno === 0) {
savedBlacklist.value = new Set(allEntries);
toast('黑名单保存成功');
} else {
+1 -1
View File
@@ -27,7 +27,7 @@
--radius-lg: var(--radius);
--radius-xl: calc(var(--radius) + 4px);
--font-sans: Geist, system-ui, -apple-system, sans-serif;
--font-mono: 'Google Sans Code', 'Roboto Mono', monospace;
--font-mono: 'Geist Mono', 'Roboto Mono', monospace;
}
/* ===============================
+1 -1
View File
@@ -1,6 +1,6 @@
/* Logs */
.log-output {
font-family: 'Google Sans Code', 'JetBrains Mono', 'Consolas', monospace;
font-family: 'Geist Mono', 'JetBrains Mono', 'Consolas', monospace;
font-size: 0.6875rem;
padding: var(--spacing-m);
background-color: #0d0e12;
+3 -3
View File
@@ -27,14 +27,14 @@
@font-face {
font-family: 'Geist';
src: url('/Geist-VariableFont_wght.ttf') format('truetype');
src: url('/Geist[wght].woff2') format('woff2');
font-weight: 100 900;
font-style: normal;
}
@font-face {
font-family: 'Google Sans Code';
src: url('/GoogleSansCode-VariableFont_wght.ttf') format('truetype');
font-family: 'Geist Mono';
src: url('/GeistMono[wght].woff2') format('woff2');
font-weight: 100 900;
font-style: normal;
}