PM: merge A3 part 2: blame without path, plural messages, screenshot path hardening
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
93a4076b86
10 changed files with 102 additions and 21 deletions
|
|
@ -39,7 +39,8 @@ const CAPTURE_TIMEOUT: Duration = Duration::from_secs(10);
|
|||
///
|
||||
/// # Errors
|
||||
/// A message if the window does not exist or is minimised, the capture fails
|
||||
/// or times out, the result is not a PNG, or the file cannot be written.
|
||||
/// or times out, the result is not a PNG, or the file cannot be written (or
|
||||
/// is missing or short when read back).
|
||||
pub fn capture_window(app: &AppHandle, label: &str, path: &Path) -> Result<(), String> {
|
||||
let window = app
|
||||
.get_webview_window(label)
|
||||
|
|
@ -55,7 +56,17 @@ pub fn capture_window(app: &AppHandle, label: &str, path: &Path) -> Result<(), S
|
|||
if let Some(parent) = path.parent().filter(|p| !p.as_os_str().is_empty()) {
|
||||
std::fs::create_dir_all(parent).map_err(|e| format!("{}: {e}", parent.display()))?;
|
||||
}
|
||||
std::fs::write(path, png).map_err(|e| format!("{}: {e}", path.display()))
|
||||
std::fs::write(path, &png).map_err(|e| format!("{}: {e}", path.display()))?;
|
||||
match std::fs::metadata(path) {
|
||||
Ok(meta) if meta.len() == png.len() as u64 => Ok(()),
|
||||
Ok(meta) => Err(format!(
|
||||
"{}: wrote {} of {} bytes",
|
||||
path.display(),
|
||||
meta.len(),
|
||||
png.len()
|
||||
)),
|
||||
Err(e) => Err(format!("{}: not found after writing: {e}", path.display())),
|
||||
}
|
||||
}
|
||||
|
||||
/// Checks that `bytes` start with the PNG signature and stay within
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue