tighten export and capture handling
This commit is contained in:
+42
-11
@@ -182,12 +182,49 @@ struct SaveConfigResult {
|
||||
hotkey_result: HotkeyRegistrationResult,
|
||||
}
|
||||
|
||||
fn validate_config(config: &Config) -> Result<(), String> {
|
||||
let mut keys = Vec::new();
|
||||
if let Some(k) = config
|
||||
.hotkeys
|
||||
.start
|
||||
.as_deref()
|
||||
.filter(|s| !s.trim().is_empty())
|
||||
{
|
||||
keys.push(("start", k));
|
||||
}
|
||||
if let Some(k) = config
|
||||
.hotkeys
|
||||
.stop
|
||||
.as_deref()
|
||||
.filter(|s| !s.trim().is_empty())
|
||||
{
|
||||
keys.push(("stop", k));
|
||||
}
|
||||
if let Some(k) = config
|
||||
.hotkeys
|
||||
.pause
|
||||
.as_deref()
|
||||
.filter(|s| !s.trim().is_empty())
|
||||
{
|
||||
keys.push(("pause", k));
|
||||
}
|
||||
for (i, (a, ka)) in keys.iter().enumerate() {
|
||||
for (b, kb) in keys.iter().skip(i + 1) {
|
||||
if ka.eq_ignore_ascii_case(kb) {
|
||||
return Err(format!("duplicate hotkey: {a} and {b} both use {ka}"));
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn save_config(
|
||||
app: AppHandle,
|
||||
state: State<'_, AppState>,
|
||||
config: Config,
|
||||
) -> Result<SaveConfigResult, String> {
|
||||
validate_config(&config)?;
|
||||
let path = config::config_path(&state.app_dir);
|
||||
config.save(&path).map_err(|e| format!("{e:#}"))?;
|
||||
*lock(&state.config) = config.clone();
|
||||
@@ -794,16 +831,7 @@ fn estimate_gif_params(request: PreviewRequest) -> GifEstimate {
|
||||
gif_budget_mode: request.gif_budget_mode,
|
||||
};
|
||||
let (w, fps) = encode::gif_params(&budget, request.clip_width, request.clip_height);
|
||||
let aspect = if request.clip_height > 0 {
|
||||
request.clip_width as f64 / request.clip_height as f64
|
||||
} else {
|
||||
16.0 / 9.0
|
||||
};
|
||||
let height = if w == 0 {
|
||||
0
|
||||
} else {
|
||||
((w as f64 / aspect).round() as u32 / 2) * 2
|
||||
};
|
||||
let height = encode::gif_height_for_width(w, request.clip_width, request.clip_height);
|
||||
let dims_label = format!("{w}x{height} @ {fps}fps");
|
||||
GifEstimate { width: w, fps, height, dims_label }
|
||||
}
|
||||
@@ -845,7 +873,7 @@ mod tests {
|
||||
assert_eq!(est.fps, encode_fps);
|
||||
// height should be a multiple of 2 and within aspect
|
||||
assert_eq!(est.height % 2, 0);
|
||||
let expected_height = ((encode_w as f64 / (1920.0 / 1080.0)).round() as u32 / 2) * 2;
|
||||
let expected_height = encode::gif_height_for_width(encode_w, 1920, 1080);
|
||||
assert_eq!(est.height, expected_height);
|
||||
// dims_label should be "{w}x{h} @ {fps}fps"
|
||||
assert_eq!(est.dims_label, format!("{}x{} @ {}fps", encode_w, est.height, encode_fps));
|
||||
@@ -1571,7 +1599,10 @@ pub fn run() {
|
||||
let registry = tracing_subscriber::registry().with(env_filter).with(file_layer);
|
||||
#[cfg(debug_assertions)]
|
||||
let registry = registry.with(tracing_subscriber::fmt::layer().with_writer(std::io::stdout));
|
||||
#[cfg(test)]
|
||||
let _ = registry.try_init();
|
||||
#[cfg(not(test))]
|
||||
registry.init();
|
||||
|
||||
let webview_dir = app_dir.join("temp").join("webview");
|
||||
match std::fs::create_dir_all(&webview_dir) {
|
||||
|
||||
Reference in New Issue
Block a user