playback and import issues
This commit is contained in:
@@ -22,7 +22,15 @@ fn default_sam_url() -> String {
|
||||
}
|
||||
|
||||
fn default_cache_capacity() -> usize {
|
||||
500
|
||||
crate::decoder::DEFAULT_CACHE_CAPACITY
|
||||
}
|
||||
|
||||
fn normalize(mut s: Settings) -> Settings {
|
||||
s.cache_capacity = s.cache_capacity.clamp(
|
||||
crate::decoder::MIN_CACHE_CAPACITY,
|
||||
crate::decoder::MAX_CACHE_CAPACITY,
|
||||
);
|
||||
s
|
||||
}
|
||||
|
||||
impl Default for Settings {
|
||||
@@ -51,12 +59,15 @@ pub fn load(app: &AppHandle) -> Result<Settings, String> {
|
||||
return Ok(Settings::default());
|
||||
}
|
||||
let text = fs::read_to_string(&path).map_err(|e| format!("read {}: {e}", path.display()))?;
|
||||
serde_json::from_str(&text).map_err(|e| format!("parse settings: {e}"))
|
||||
serde_json::from_str(&text)
|
||||
.map(normalize)
|
||||
.map_err(|e| format!("parse settings: {e}"))
|
||||
}
|
||||
|
||||
pub fn save(app: &AppHandle, s: &Settings) -> Result<(), String> {
|
||||
let path = settings_path(app)?;
|
||||
let text = serde_json::to_string_pretty(s).map_err(|e| format!("serialize: {e}"))?;
|
||||
let normalized = normalize(s.clone());
|
||||
let text = serde_json::to_string_pretty(&normalized).map_err(|e| format!("serialize: {e}"))?;
|
||||
fs::write(&path, text).map_err(|e| format!("write {}: {e}", path.display()))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user