Sleep timer (queue footer): tokio monotonic deadline + 1Hz countdown that fires core().pause() at expiry; presets + custom minutes via a popover. Stop after this song: 4 QbzCore passthroughs + playback consume-before-advance seam and the load-bearing gapless-prefetch gate, plus the queue marker/menu so the Queue persists when playback halts. qbz-log crate: TeeLogger wrapping env_logger (stderr + 5000-line ring + ~/.local/share/qbz/logs/qbz.log) with write-time secret redaction (regex + live-secret registry) and a diagnostics bundle builder. Dev panel logs: in-app viewer that shows content the moment it opens, advanced controls behind a discreet [+], "Copy all" as the sole footer button, a copy button on the upload URL, and a redacted public paste upload. Diagnostics: qbz-app::diagnostics (extracted, src-tauri untouched) feeding a 7-section panel with the live active output device + sample rate/format (pactl) and a complete redacted report for the upload. Report an Issue: wires the header menu item to a 1:1 Tauri modal that opens the GitHub bug-report template. Appearance persistence: 6 toggles that were live-only now persist via ui_prefs + handler arm + startup seed (window-title-show, show-volume-steppers, sidebar-playlist-collage, local-library-track-artwork, in-app-toasts, theme-filter). Recommendations cache (per-tab only): TTL select 24/36/48/72h + Refresh now in ExternalRecoView; no change to the other Discover tabs. Bump workspace version 0.1.0 -> 1.2.15 so app_version is correct in the diagnostics report and the QConnect About string. i18n es/de/fr/pt for all new strings. cc
76 lines
2.2 KiB
Rust
76 lines
2.2 KiB
Rust
//! Bounded in-memory ring buffer of the most recent [`LogLine`]s.
|
|
//!
|
|
//! FIFO with a hard cap of [`RING_CAP`]: at capacity the oldest line is dropped.
|
|
//! The critical section is kept tiny (push/pop only — never held across I/O) so the
|
|
//! audio/tokio threads that log never block meaningfully. Lock poisoning is tolerated
|
|
//! (`into_inner`) because a single corrupt line must never wedge logging globally.
|
|
|
|
use std::collections::VecDeque;
|
|
use std::sync::{Arc, Mutex, OnceLock};
|
|
|
|
use crate::line::LogLine;
|
|
|
|
/// Maximum number of lines retained in the ring.
|
|
pub const RING_CAP: usize = 5000;
|
|
|
|
static RING: OnceLock<Arc<Mutex<VecDeque<LogLine>>>> = OnceLock::new();
|
|
|
|
fn ring() -> &'static Arc<Mutex<VecDeque<LogLine>>> {
|
|
RING.get_or_init(|| Arc::new(Mutex::new(VecDeque::with_capacity(RING_CAP))))
|
|
}
|
|
|
|
/// Append a line, dropping the oldest if the ring is full. O(1).
|
|
pub fn push(line: LogLine) {
|
|
let r = ring();
|
|
let mut guard = r.lock().unwrap_or_else(|p| p.into_inner());
|
|
if guard.len() == RING_CAP {
|
|
guard.pop_front();
|
|
}
|
|
guard.push_back(line);
|
|
}
|
|
|
|
/// Clone the current contents (oldest first) for the viewer/bundle. Clones under lock.
|
|
pub fn snapshot() -> Vec<LogLine> {
|
|
let r = ring();
|
|
let guard = r.lock().unwrap_or_else(|p| p.into_inner());
|
|
guard.iter().cloned().collect()
|
|
}
|
|
|
|
/// Empty the ring (the "Clear" action). Does not touch the on-disk file.
|
|
pub fn clear() {
|
|
let r = ring();
|
|
let mut guard = r.lock().unwrap_or_else(|p| p.into_inner());
|
|
guard.clear();
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
use log::Level;
|
|
|
|
fn mk(i: i64) -> LogLine {
|
|
LogLine {
|
|
ts: i,
|
|
level: Level::Info,
|
|
target: "t".into(),
|
|
message: format!("line {i}"),
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn ring_caps_and_is_fifo() {
|
|
clear();
|
|
let total = RING_CAP as i64 + 10;
|
|
for i in 0..total {
|
|
push(mk(i));
|
|
}
|
|
let snap = snapshot();
|
|
// Capacity is enforced.
|
|
assert_eq!(snap.len(), RING_CAP);
|
|
// Oldest 10 (ts 0..10) were dropped, so the first retained line is ts 10.
|
|
assert_eq!(snap.first().unwrap().ts, 10);
|
|
// Newest line is last.
|
|
assert_eq!(snap.last().unwrap().ts, total - 1);
|
|
}
|
|
}
|