harden gif pipeline, capture, and audio resilience

fix gif calibration (sample deleted before measurement), swap the
budget-mode application so resolution shrinks width not fps, correct the
color factor comment. accumulate gif encode progress across retry
attempts instead of resetting, surface an over-budget result on the done
screen. stream the audio head padding instead of loading it into memory,
detect mid-record audio device loss and offer the existing retry flow,
invalidate the cached encoder list when the ffmpeg binary changes.
add a capture quality setting so 4k screens can record at native res,
try a stream copy before re-encoding when fixing capture timestamps,
park the overlay poll thread when idle, sweep stale config backups, add
a diagnostics tab, and consolidate the preview render debounce.
This commit is contained in:
2026-06-17 23:57:28 +03:00
parent f732cdda4d
commit c3f132507a
9 changed files with 624 additions and 83 deletions
+44
View File
@@ -35,11 +35,25 @@ pub struct ExportConfig {
pub mp4_codec: Mp4Codec,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
#[serde(rename_all = "lowercase")]
pub enum CaptureQuality {
/// Cap the capture/encode width at 1920px (downscales larger monitors).
/// Lower CPU and disk during recording; the default.
#[default]
Auto,
/// Record at the monitor's native resolution (capped at 3840px to bound
/// CPU). Sharp text on 4K screens at the cost of more encode load.
Full,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CaptureConfig {
pub default_fps: u32,
pub capture_cursor: bool,
pub capture_audio: bool,
#[serde(default)]
pub capture_quality: CaptureQuality,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
@@ -127,6 +141,7 @@ impl Default for CaptureConfig {
default_fps: 30,
capture_cursor: true,
capture_audio: false,
capture_quality: CaptureQuality::Auto,
}
}
}
@@ -139,6 +154,7 @@ impl Default for UpdatesConfig {
impl Config {
pub fn load_or_create(path: &Path) -> Result<Self> {
sweep_stale_backups(path);
if !path.exists() {
let cfg = Self::default();
cfg.save(path)?;
@@ -199,6 +215,33 @@ pub fn config_path(app_dir: &Path) -> PathBuf {
app_dir.join("config.toml")
}
/// Remove config backup files older than 30 days. Corruption handling writes
/// `config-{unix_secs}.toml.bak` (plus a `config.toml.bak` fallback) and never
/// cleaned them up, so a long-lived install could accumulate a pile. Parses
/// the embedded timestamp; anything unparsable is left alone (the fallback
/// name has no timestamp and is kept as the most recent safety net).
fn sweep_stale_backups(config_path: &Path) {
const MAX_AGE_SECS: u64 = 30 * 24 * 3600;
let Some(dir) = config_path.parent() else { return };
let now = std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.map(|d| d.as_secs())
.unwrap_or(0);
let Ok(entries) = std::fs::read_dir(dir) else { return };
for entry in entries.flatten() {
let name = entry.file_name();
let Some(name) = name.to_str() else { continue };
// Match config-{digits}.toml.bak - extract the unix secs and age it out.
if let Some(rest) = name.strip_prefix("config-").and_then(|s| s.strip_suffix(".toml.bak")) {
if let Ok(ts) = rest.parse::<u64>() {
if now.saturating_sub(ts) > MAX_AGE_SECS {
let _ = std::fs::remove_file(entry.path());
}
}
}
}
}
#[cfg(test)]
mod tests {
use super::*;
@@ -216,6 +259,7 @@ mod tests {
default_fps: 60,
capture_cursor: false,
capture_audio: true,
capture_quality: CaptureQuality::Full,
},
hotkeys: HotkeyConfig {
start: Some("F9".to_string()),