Adopt bread_utils::screenshot_cli for --screenshot flags
Some checks failed
check / check (push) Failing after 3s
dev release / build (push) Successful in 29s

Replace the local settle delay, canvas defaults, and pair-validation
error path with bread-utils v0.7.2. Hand-rolled argv parsing stays.
This commit is contained in:
Breadway 2026-08-16 00:26:07 +08:00
parent af6ba1bd82
commit a7a67d7d84
2 changed files with 32 additions and 16 deletions

View file

@ -4,7 +4,10 @@
//! `connect_command_line`, so `--onboard` on a second launch re-triggers the
//! tour in the existing window instead of spawning a duplicate.
#[derive(Clone, Default)]
use bread_utils::screenshot_cli::{validate_pair, DEFAULT_HEIGHT, DEFAULT_WIDTH};
use std::path::Path;
#[derive(Clone)]
pub struct Action {
/// Force-restart the onboarding tour from step 0, regardless of whether
/// it was already completed or in progress.
@ -38,19 +41,36 @@ pub struct Action {
pub height: u32,
}
impl Default for Action {
fn default() -> Self {
Self {
force_onboard: false,
autostart: false,
suggest: None,
tour_event: None,
screenshot: None,
output: None,
width: DEFAULT_WIDTH,
height: DEFAULT_HEIGHT,
}
}
}
impl Action {
/// `None` for a normal run. Exits the process with an error if
/// `--screenshot` was given without `--output`, before any GTK setup
/// `None` for a normal run. Exits the process with an error if the
/// `--screenshot` / `--output` pair is incomplete, before any GTK setup
/// happens.
pub fn screenshot_request(&self) -> Option<crate::screenshot::ScreenshotRequest> {
let view = self.screenshot.clone()?;
let Some(output) = self.output.clone() else {
eprintln!("breadhelp: --screenshot requires --output");
if let Err(e) = validate_pair(
self.screenshot.as_deref(),
self.output.as_deref().map(Path::new),
) {
eprintln!("breadhelp: {e}");
std::process::exit(1);
};
}
Some(crate::screenshot::ScreenshotRequest {
view,
output: output.into(),
view: self.screenshot.clone()?,
output: self.output.clone()?.into(),
width: self.width,
height: self.height,
})
@ -58,7 +78,7 @@ impl Action {
}
pub fn parse(args: &[std::ffi::OsString]) -> Action {
let mut action = Action { width: 1920, height: 1080, ..Action::default() };
let mut action = Action::default();
let mut it = args.iter().skip(1);
while let Some(arg) = it.next() {
if arg == "--onboard" {

View file

@ -21,19 +21,15 @@
//! both render embedded *inside* the Learn/Home tabs respectively, so
//! they're already covered by those tabs' own captures.
use bread_utils::screenshot_cli::SETTLE_DELAY;
use gtk4::prelude::*;
use std::path::PathBuf;
use std::time::Duration;
/// Extra settle time after `map` for the first frame to actually paint
/// before grim runs — `map` fires once the surface exists, not once
/// anything has been drawn into it.
const SETTLE_DELAY: Duration = Duration::from_millis(300);
/// Delay before opening the wizard modal — same reasoning as every other
/// app's PRE_POPUP_DELAY: the parent window's own layout needs a beat to
/// settle first.
const PRE_POPUP_DELAY: Duration = Duration::from_millis(300);
const PRE_POPUP_DELAY: Duration = SETTLE_DELAY;
const KNOWN_VIEWS: &[&str] = &["home", "learn", "ask", "troubleshoot-wizard"];