diff --git a/rust/src/main.rs b/rust/src/main.rs index 8247b05..8e86881 100644 --- a/rust/src/main.rs +++ b/rust/src/main.rs @@ -84,10 +84,18 @@ mod linux { let mut idx = 0; let mut debounce_ms: u64 = 300; - if args.get(idx).map(String::as_str) == Some("--debounce") { - idx += 1; - debounce_ms = args.get(idx).and_then(|s| s.parse().ok()).unwrap_or(300); - idx += 1; + let mut debug = false; + + loop { + match args.get(idx).map(String::as_str) { + Some("--debug") => { debug = true; idx += 1; } + Some("--debounce") => { + idx += 1; + debounce_ms = args.get(idx).and_then(|s| s.parse().ok()).unwrap_or(300); + idx += 1; + } + _ => break, + } } let handler = match args.get(idx) { @@ -124,6 +132,9 @@ mod linux { let mask = letters_to_mask(letters); match inotify.watches().add(&path, mask) { Ok(wd) => { + if debug { + eprintln!("[lumipro] watching: {} events: {}", path_str, letters); + } watches.insert(wd, (path, letters.to_string())); } Err(e) => { @@ -133,6 +144,10 @@ mod linux { } } + if debug { + eprintln!("[lumipro] debounce={}ms handler={}", debounce_ms, handler); + } + let debounce = Duration::from_millis(debounce_ms); let mut pending: Option = None; let mut buffer = [0u8; 4096]; @@ -161,9 +176,13 @@ mod linux { Ok(events) => { for event in events { if let Some((path, _)) = watches.get(&event.wd) { + let letters = mask_to_letters(event.mask); + if debug { + eprintln!("[lumipro] event: {} path: {}", letters, path.display()); + } pending = Some(Pending { triggered_at: Instant::now(), - event_letters: mask_to_letters(event.mask), + event_letters: letters, path: path.clone(), }); } @@ -174,20 +193,27 @@ mod linux { } } else if let Some(p) = pending.take() { // ── 3. 防抖窗口结束:同步执行 handler ─────────────────────── + if debug { + eprintln!("[lumipro] debounce fired → handler: {} {}", p.event_letters, p.path.display()); + } let _ = Command::new(&handler) .arg(&p.event_letters) .arg(&p.path) .status(); // ── 4. 丢弃 handler 执行期间(亮度渐变写入)积压的全部事件 ─ + let mut drained = 0usize; loop { match inotify.read_events(&mut buffer) { Ok(events) => { - for _ in events {} + for _ in events { drained += 1; } } Err(_) => break, // WouldBlock:积压已清空 } } + if debug && drained > 0 { + eprintln!("[lumipro] drain: discarded {} event(s)", drained); + } } } } diff --git a/script/daemon.sh b/script/daemon.sh index 2b05da8..4042bef 100644 --- a/script/daemon.sh +++ b/script/daemon.sh @@ -77,11 +77,16 @@ while true; do _log "正在启动 lumipro 监听" "INFO" now_bri_file="${current_config%|*}" inotify_events="${current_config#*|}" + debug_mode="$(get_cfg debug_mode "0")" # 缓存当前监听路径(供参考) echo -n "$now_bri_file" >"$MODDIR/config/.cached_path" - "$MODDIR/bin/lumipro" "$MODDIR/script/up.sh" "$now_bri_file:$inotify_events" >>"$log_file" 2>&1 & + 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" diff --git a/webui/src/composables/useConfig.js b/webui/src/composables/useConfig.js index a4f3288..19b15c0 100644 --- a/webui/src/composables/useConfig.js +++ b/webui/src/composables/useConfig.js @@ -31,6 +31,7 @@ export function useConfig() { const nowBriFile = ref(DEFAULT_NOW_BRI_FILE) const sysMaxBriFile = ref(DEFAULT_SYS_MAX_BRI_FILE) const inotifyEvents = ref('c') + const debugMode = ref(false) // Web UI 配置 (localStorage 持久化) const autoRefresh = ref(localStorage.getItem('autoRefresh') !== 'false') @@ -55,6 +56,7 @@ export function useConfig() { 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' + debugMode.value = cfg.debug_mode === 1 const st = cfg.sleep_time || '' if (st && st.includes('-')) { @@ -112,6 +114,7 @@ export function useConfig() { now_bri_file: nowBriFile.value || DEFAULT_NOW_BRI_FILE, max_bri_file: sysMaxBriFile.value || DEFAULT_SYS_MAX_BRI_FILE, inotify_events: inotifyEvents.value || 'c', + debug_mode: debugMode.value ? 1 : 0, }) onPathsChanged?.() toast('高级设置已保存,需重启服务生效') @@ -207,6 +210,7 @@ export function useConfig() { nowBriFile, sysMaxBriFile, inotifyEvents, + debugMode, autoRefresh, statusRefreshInterval, uiZoom, diff --git a/webui/src/views/ConfigView.vue b/webui/src/views/ConfigView.vue index dd21e75..95bff4a 100644 --- a/webui/src/views/ConfigView.vue +++ b/webui/src/views/ConfigView.vue @@ -211,6 +211,17 @@ function handleSaveWebUI() {

运行环境

+
+
+ 调试模式 + 将每个 inotify 事件及防抖触发信息写入日志 + 开启后需重启服务,日志量增大。诊断完成后请关闭 +
+ +
+
inotifyd 监听事件