feat: 新增兼容兜底的轮询模式

This commit is contained in:
YuleBest committed 2026-06-02 03:49:19 +08:00
1 parent b7e792c126
commit d18393f7d7
4 files changed
+65 -17

No files matched your search

+10
View File
@@ -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
+37 -16
View File
@@ -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
+7 -1
View File
@@ -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,
+11
View File
@@ -144,6 +144,17 @@ function handleSaveWebUI() {
<Switch v-model="config.displayHdrSleep.value" />
</div>
<div class="config-item">
<div class="config-label">
<span class="config-name">兼容模式 (轮询驱动)</span>
<span class="config-desc">不使用事件监听,改用 2 秒一次轮询</span>
<span class="config-desc" style="color: var(--color-warning)"
>仅在事件驱动失效时开启,会略微增加耗电</span
>
</div>
<Switch v-model="config.compatibilityMode.value" />
</div>
<div class="config-item">
<div class="config-label">
<span class="config-name">定时休眠</span>