From 0798fad697141f9c670ecccdf9d6ddd03b66a176 Mon Sep 17 00:00:00 2001 From: Breadway Date: Sun, 16 Aug 2026 00:26:06 +0800 Subject: [PATCH] Adopt bread_utils::screenshot_cli for --screenshot flags Use the crate for pair validation and canvas defaults. Webview settle delays stay local; Tauri still does not have a GTK map signal. --- src/src/screenshot.rs | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/src/screenshot.rs b/src/src/screenshot.rs index 0e7388e..6c8b963 100644 --- a/src/src/screenshot.rs +++ b/src/src/screenshot.rs @@ -23,7 +23,8 @@ //! `KNOWN_VIEWS`) — every one of them has a real registered component (see //! `frontend/src/lib/views/registry.ts`), no Placeholder fallbacks to skip. -use std::path::PathBuf; +use bread_utils::screenshot_cli::{validate_pair, DEFAULT_HEIGHT, DEFAULT_WIDTH}; +use std::path::{Path, PathBuf}; use std::time::Duration; use tauri::Emitter; @@ -84,13 +85,13 @@ pub struct ScreenshotRequest { } /// `None` for a normal run. Exits the process with an error for an unknown -/// view, or if `--screenshot` was given without `--output` — before any -/// Tauri setup happens. +/// view, or if the `--screenshot` / `--output` pair is incomplete — before +/// any Tauri setup happens. pub fn parse(args: &[String]) -> Option { let mut view = None; let mut output = None; - let mut width = 1920u32; - let mut height = 1080u32; + let mut width = DEFAULT_WIDTH; + let mut height = DEFAULT_HEIGHT; let mut it = args.iter().skip(1); while let Some(arg) = it.next() { match arg.as_str() { @@ -109,6 +110,10 @@ pub fn parse(args: &[String]) -> Option { _ => {} } } + if let Err(e) = validate_pair(view.as_deref(), output.as_deref().map(Path::new)) { + eprintln!("bos-settings: {e}"); + std::process::exit(1); + } let view = view?; if !KNOWN_VIEWS.contains(&view.as_str()) { eprintln!( @@ -117,13 +122,9 @@ pub fn parse(args: &[String]) -> Option { ); std::process::exit(1); } - let Some(output) = output else { - eprintln!("bos-settings: --screenshot requires --output"); - std::process::exit(1); - }; Some(ScreenshotRequest { view, - output: output.into(), + output: output?.into(), width, height, })