|
1 | 1 | use std::path::{Path, PathBuf}; |
2 | 2 |
|
3 | | -use anyhow::Result; |
| 3 | +#[cfg(any(windows, target_os = "macos"))] |
| 4 | +use anyhow::Context; |
4 | 5 | use pyo3::prelude::*; |
| 6 | +#[cfg(any(windows, target_os = "macos"))] |
| 7 | +use pyo3::IntoPyObjectExt; |
5 | 8 |
|
6 | 9 | #[cfg(any(windows, target_os = "macos", target_os = "linux"))] |
7 | 10 | use mitmproxy::processes; |
@@ -67,18 +70,17 @@ pub fn active_executables() -> PyResult<Vec<Process>> { |
67 | 70 | /// *Availability: Windows, macOS* |
68 | 71 | #[pyfunction] |
69 | 72 | #[allow(unused_variables)] |
70 | | -pub fn executable_icon(path: PathBuf) -> Result<PyObject> { |
| 73 | +pub fn executable_icon(py: Python<'_>, path: PathBuf) -> PyResult<PyObject> { |
71 | 74 | #[cfg(any(windows, target_os = "macos"))] |
72 | 75 | { |
73 | 76 | let mut icon_cache = processes::ICON_CACHE.lock().unwrap(); |
74 | | - let png_bytes = icon_cache.get_png(path)?; |
75 | | - Ok(Python::with_gil(|py| { |
76 | | - pyo3::types::PyBytes::new(py, png_bytes).to_object(py) |
77 | | - })) |
| 77 | + icon_cache |
| 78 | + .get_png(path) |
| 79 | + .context("failed to get image")? |
| 80 | + .into_py_any(py) |
78 | 81 | } |
79 | 82 | #[cfg(not(any(windows, target_os = "macos")))] |
80 | 83 | Err(pyo3::exceptions::PyNotImplementedError::new_err( |
81 | 84 | "executable_icon is only available on Windows", |
82 | | - ) |
83 | | - .into()) |
| 85 | + )) |
84 | 86 | } |
0 commit comments