()
| 241 | } |
| 242 | |
| 243 | fn read_image_windows() -> anyhow::Result<String> { |
| 244 | let ps_script = concat!( |
| 245 | "Add-Type -AssemblyName System.Windows.Forms; ", |
| 246 | "$img = [System.Windows.Forms.Clipboard]::GetImage(); ", |
| 247 | "if ($img -eq $null) { exit 1 }; ", |
| 248 | "$ms = New-Object System.IO.MemoryStream; ", |
| 249 | "$img.Save($ms, [System.Drawing.Imaging.ImageFormat]::Png); ", |
| 250 | "[Convert]::ToBase64String($ms.ToArray())" |
| 251 | ); |
| 252 | |
| 253 | let output = Command::new("powershell") |
| 254 | .args(&["-NoProfile", "-Command", ps_script]) |
| 255 | .output() |
| 256 | .context("failed to execute PowerShell for clipboard image")?; |
| 257 | |
| 258 | if !output.status.success() { |
| 259 | anyhow::bail!( |
| 260 | "PowerShell clipboard image read failed with status {}", |
| 261 | output.status |
| 262 | ); |
| 263 | } |
| 264 | |
| 265 | let b64 = String::from_utf8_lossy(&output.stdout).trim().to_string(); |
| 266 | if b64.is_empty() { |
| 267 | anyhow::bail!("PowerShell clipboard image read returned empty output"); |
| 268 | } |
| 269 | |
| 270 | Ok(b64) |
| 271 | } |
no test coverage detected