Adopt bread_utils::screenshot_cli for --screenshot flags
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:
parent
af6ba1bd82
commit
a7a67d7d84
2 changed files with 32 additions and 16 deletions
40
src/cli.rs
40
src/cli.rs
|
|
@ -4,7 +4,10 @@
|
||||||
//! `connect_command_line`, so `--onboard` on a second launch re-triggers the
|
//! `connect_command_line`, so `--onboard` on a second launch re-triggers the
|
||||||
//! tour in the existing window instead of spawning a duplicate.
|
//! 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 {
|
pub struct Action {
|
||||||
/// Force-restart the onboarding tour from step 0, regardless of whether
|
/// Force-restart the onboarding tour from step 0, regardless of whether
|
||||||
/// it was already completed or in progress.
|
/// it was already completed or in progress.
|
||||||
|
|
@ -38,19 +41,36 @@ pub struct Action {
|
||||||
pub height: u32,
|
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 {
|
impl Action {
|
||||||
/// `None` for a normal run. Exits the process with an error if
|
/// `None` for a normal run. Exits the process with an error if the
|
||||||
/// `--screenshot` was given without `--output`, before any GTK setup
|
/// `--screenshot` / `--output` pair is incomplete, before any GTK setup
|
||||||
/// happens.
|
/// happens.
|
||||||
pub fn screenshot_request(&self) -> Option<crate::screenshot::ScreenshotRequest> {
|
pub fn screenshot_request(&self) -> Option<crate::screenshot::ScreenshotRequest> {
|
||||||
let view = self.screenshot.clone()?;
|
if let Err(e) = validate_pair(
|
||||||
let Some(output) = self.output.clone() else {
|
self.screenshot.as_deref(),
|
||||||
eprintln!("breadhelp: --screenshot requires --output");
|
self.output.as_deref().map(Path::new),
|
||||||
|
) {
|
||||||
|
eprintln!("breadhelp: {e}");
|
||||||
std::process::exit(1);
|
std::process::exit(1);
|
||||||
};
|
}
|
||||||
Some(crate::screenshot::ScreenshotRequest {
|
Some(crate::screenshot::ScreenshotRequest {
|
||||||
view,
|
view: self.screenshot.clone()?,
|
||||||
output: output.into(),
|
output: self.output.clone()?.into(),
|
||||||
width: self.width,
|
width: self.width,
|
||||||
height: self.height,
|
height: self.height,
|
||||||
})
|
})
|
||||||
|
|
@ -58,7 +78,7 @@ impl Action {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse(args: &[std::ffi::OsString]) -> 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);
|
let mut it = args.iter().skip(1);
|
||||||
while let Some(arg) = it.next() {
|
while let Some(arg) = it.next() {
|
||||||
if arg == "--onboard" {
|
if arg == "--onboard" {
|
||||||
|
|
|
||||||
|
|
@ -21,19 +21,15 @@
|
||||||
//! both render embedded *inside* the Learn/Home tabs respectively, so
|
//! both render embedded *inside* the Learn/Home tabs respectively, so
|
||||||
//! they're already covered by those tabs' own captures.
|
//! they're already covered by those tabs' own captures.
|
||||||
|
|
||||||
|
use bread_utils::screenshot_cli::SETTLE_DELAY;
|
||||||
use gtk4::prelude::*;
|
use gtk4::prelude::*;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::time::Duration;
|
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
|
/// 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
|
/// app's PRE_POPUP_DELAY: the parent window's own layout needs a beat to
|
||||||
/// settle first.
|
/// 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"];
|
const KNOWN_VIEWS: &[&str] = &["home", "learn", "ask", "troubleshoot-wizard"];
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue