From d18393f7d7a626ce08fe02ec5cb860a8d23daf2c Mon Sep 17 00:00:00 2001 From: Yule Date: Tue, 2 Jun 2026 03:49:19 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E5=85=BC=E5=AE=B9?= =?UTF-8?q?=E5=85=9C=E5=BA=95=E7=9A=84=E8=BD=AE=E8=AF=A2=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- customize.sh | 10 ++++++ script/daemon.sh | 53 +++++++++++++++++++++--------- webui/src/composables/useConfig.js | 8 ++++- webui/src/views/ConfigView.vue | 11 +++++++ 4 files changed, 65 insertions(+), 17 deletions(-) diff --git a/customize.sh b/customize.sh index cf3a6a5..9718cb2 100755 --- a/customize.sh +++ b/customize.sh @@ -64,6 +64,7 @@ write_config_json() { --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 compatibility_mode "${cfg_compatibility_mode:-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}" \ @@ -77,6 +78,7 @@ write_config_json() { log_max_size: ($log_max_size | tonumber), auto_bri_sleep: ($auto_bri_sleep | tonumber), display_hdr_sleep: ($display_hdr_sleep | tonumber), + compatibility_mode:($compatibility_mode | tonumber), sleep_time: $sleep_time, inotify_events: $inotify_events, now_bri_file: $now_bri_file, @@ -249,6 +251,7 @@ IMPORT_OLD_CONFIG() { 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_compatibility_mode="$(read_old_txt compatibility_mode.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")" @@ -288,6 +291,7 @@ INIT_CONFIG() { cfg_log_max_size=512 cfg_auto_bri_sleep=1 cfg_display_hdr_sleep=0 + cfg_compatibility_mode=0 cfg_sleep_time="" cfg_inotify_events="c" cfg_now_bri_file="$DEFAULT_NOW_BRI_FILE" @@ -305,6 +309,7 @@ ENSURE_DEFAULTS() { .log_max_size = (.log_max_size // 512) | .auto_bri_sleep = (.auto_bri_sleep // 1) | .display_hdr_sleep = (.display_hdr_sleep // 0) | + .compatibility_mode= (.compatibility_mode // 0) | .sleep_time = (.sleep_time // "") | .inotify_events = (.inotify_events // "c") | .log_level = (.log_level // "info") | @@ -393,6 +398,11 @@ END() { else echo " - HDR 内容时跳过: 关闭" fi + if [ "$("$JQ" -re '.compatibility_mode' "$CONFIG_FILE" 2>/dev/null || echo "0")" = "1" ]; then + echo " - 兼容模式 (轮询): 开启" + else + echo " - 兼容模式 (轮询): 关闭" + fi if [ -n "$st" ]; then echo " - 休眠时段: $st" else diff --git a/script/daemon.sh b/script/daemon.sh index 528890b..0cdeeed 100644 --- a/script/daemon.sh +++ b/script/daemon.sh @@ -81,25 +81,46 @@ while true; do echo "$current_config" >"$config_cache_file" fi - _log "正在启动 lumipro 监听" "INFO" - now_bri_file="${current_config%|*}" - inotify_events="${current_config#*|}" - debug_mode="$(get_cfg debug_mode "0")" + compatibility_mode="$(get_cfg compatibility_mode "0")" - # 缓存当前监听路径(供参考) - echo -n "$now_bri_file" >"$MODDIR/config/.cached_path" - - if [ "$debug_mode" = "1" ]; then - "$MODDIR/bin/lumipro" --debug "$MODDIR/script/up.sh" "$now_bri_file:$inotify_events" >>"$log_file" 2>&1 & + if [ "$compatibility_mode" = "1" ]; then + _log "兼容模式已开启 (轮询驱动)" "WARN" + # 写入一个特殊的 PID 标识轮询模式 + echo "polling" >"$pid_file" + while true; do + if [ -f "$stop_file" ] || [ -f "$pause_file" ]; then + break + fi + # 检查配置哈希是否变化 + new_config="$(get_config_hash)" + if [ "$new_config" != "$current_config" ]; then + break + fi + sh "$MODDIR/script/up.sh" & + sleep 2 + done + _log "轮询模式已退出" "INFO" else - "$MODDIR/bin/lumipro" "$MODDIR/script/up.sh" "$now_bri_file:$inotify_events" >>"$log_file" 2>&1 & - fi - inotify_pid=$! - echo "$inotify_pid" >"$pid_file" - _log "lumipro 已启动 (PID: $inotify_pid), 监听: $now_bri_file, 事件: $inotify_events" "SUCCESS" + _log "正在启动 lumipro 监听" "INFO" + now_bri_file="${current_config%|*}" + inotify_events="${current_config#*|}" + debug_mode="$(get_cfg debug_mode "0")" - wait "$inotify_pid" - _log "lumipro 进程 (PID: $inotify_pid) 已退出,即将重启" "WARN" + # 缓存当前监听路径(供参考) + echo -n "$now_bri_file" >"$MODDIR/config/.cached_path" + + if [ "$debug_mode" = "1" ]; then + "$MODDIR/bin/lumipro" --debug "$MODDIR/script/up.sh" "$now_bri_file:$inotify_events" >>"$log_file" 2>&1 & + else + "$MODDIR/bin/lumipro" "$MODDIR/script/up.sh" "$now_bri_file:$inotify_events" >>"$log_file" 2>&1 & + fi + inotify_pid=$! + echo "$inotify_pid" >"$pid_file" + _log "lumipro 已启动 (PID: $inotify_pid), 监听: $now_bri_file, 事件: $inotify_events" "SUCCESS" + + wait "$inotify_pid" + _log "lumipro 进程 (PID: $inotify_pid) 已退出,即将重启" "WARN" + fi sleep 0.5 done diff --git a/webui/src/composables/useConfig.js b/webui/src/composables/useConfig.js index 4eac497..71b5eb7 100644 --- a/webui/src/composables/useConfig.js +++ b/webui/src/composables/useConfig.js @@ -21,6 +21,7 @@ export function useConfig() { // 执行策略 const autoBriSleep = ref(false) const displayHdrSleep = ref(false) + const compatibilityMode = ref(false) const sleepMode = ref(false) const sleepStartH = ref('19') const sleepStartM = ref('00') @@ -58,6 +59,7 @@ export function useConfig() { logMaxSize, autoBriSleep, displayHdrSleep, + compatibilityMode, sleepMode, sleepStartH, sleepStartM, @@ -88,6 +90,7 @@ export function useConfig() { 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 + compatibilityMode.value = cfg.compatibility_mode === 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' @@ -136,6 +139,7 @@ export function useConfig() { log_max_size: parseInt(logMaxSize.value) || 500, auto_bri_sleep: autoBriSleep.value ? 1 : 0, display_hdr_sleep: displayHdrSleep.value ? 1 : 0, + compatibility_mode: compatibilityMode.value ? 1 : 0, sleep_time: getSleepTimeStr(), log_level: logLevel.value, }) @@ -143,7 +147,7 @@ export function useConfig() { const pidRes = await runCmd(`cat "${PID_FILE}"`) toast( pidRes.errno === 0 && pidRes.stdout.trim() - ? '配置已保存 (下次调整时生效)' + ? '配置已保存 (下次重启或触发时生效)' : '配置已保存 (服务未运行)', ) dirty.value = false @@ -181,6 +185,7 @@ export function useConfig() { maxBri.value = backup.max_bri != null ? String(backup.max_bri) : '' autoBriSleep.value = backup.auto_bri_sleep === 1 displayHdrSleep.value = backup.display_hdr_sleep === 1 + compatibilityMode.value = backup.compatibility_mode === 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 @@ -244,6 +249,7 @@ export function useConfig() { logMaxSize, autoBriSleep, displayHdrSleep, + compatibilityMode, sleepMode, sleepStartH, sleepStartM, diff --git a/webui/src/views/ConfigView.vue b/webui/src/views/ConfigView.vue index 04a9563..6ddf73c 100644 --- a/webui/src/views/ConfigView.vue +++ b/webui/src/views/ConfigView.vue @@ -144,6 +144,17 @@ function handleSaveWebUI() { +
+
+ 兼容模式 (轮询驱动) + 不使用事件监听,改用 2 秒一次轮询 + 仅在事件驱动失效时开启,会略微增加耗电 +
+ +
+
定时休眠