Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions apps/chuzz/src/capture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,29 @@ fn capture_scale() -> f32 {
.unwrap_or(1.0)
}

/// CSS pixel size to lay the page out at. Defaults to 1440 by 960.
///
/// A capture is only comparable against a reference browser when both laid the
/// page out at the same width: every responsive breakpoint, every percentage
/// width and every centred box moves with it. These were exported by
/// `scripts/render-check.sh` and read by nothing, so a run at another size
/// silently produced the default and the resulting diff was all viewport and
/// no signal.
pub fn capture_viewport() -> (u32, u32) {
fn dimension(name: &str, fallback: u32) -> u32 {
std::env::var(name)
.ok()
.and_then(|value| value.parse().ok())
.filter(|pixels: &u32| *pixels > 0)
.unwrap_or(fallback)
}

(
dimension("CHUZZ_CAPTURE_WIDTH", 1440),
dimension("CHUZZ_CAPTURE_HEIGHT", 960),
)
}

/// Which colour scheme to render at. Defaults to dark.
///
/// A site that respects `prefers-color-scheme` is a different page in each, so
Expand Down
5 changes: 3 additions & 2 deletions apps/chuzz/src/tauri_main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,11 @@ fn main() {
.enable_all()
.build()
.expect("capture needs a tokio runtime");
let (width, height) = capture::capture_viewport();
let result = runtime.block_on(capture::capture(
&url,
1440,
960,
width,
height,
std::path::Path::new(&output),
));
match result {
Expand Down
Loading