1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
use image::RgbaImage; use std::process::Command; use std::path::Path; use std::fs; use std::thread; #[derive(Clone)] pub struct OsPhotoPicker; impl OsPhotoPicker { pub fn open(callback: impl FnOnce(Option<RgbaImage>) + Send + 'static) { todo!() //thread::spawn(move || { // let result = Self::try_zenity() // .or_else(|| Self::try_kdialog()); // match result { // Some(file_path) => { // if let Ok(image_data) = fs::read(&file_path) { // callback(image_data); // } else { // callback(Vec::new()); // } // } // None => callback(Vec::new()), // } //}); } //fn try_zenity() -> Option<String> { // let output = Command::new("zenity") // .args(&[ // "--file-selection", // "--file-filter=Image files | *.jpg *.jpeg *.png", // "--file-filter=All files | *", // "--title=Select an Image", // ]) // .output().ok()?; // if output.status.success() { // let file_path = String::from_utf8_lossy(&output.stdout).trim().to_string(); // if !file_path.is_empty() && Path::new(&file_path).exists() { // return Some(file_path); // } // } // None //} //fn try_kdialog() -> Option<String> { // let output = Command::new("kdialog") // .args(&[ // "--getopenfilename", // ".", // "*.jpg *.jpeg *.png|Image files", // "--title", // "Select an Image", // ]) // .output().ok()?; // if output.status.success() { // let file_path = String::from_utf8_lossy(&output.stdout).trim().to_string(); // if !file_path.is_empty() && Path::new(&file_path).exists() { // return Some(file_path); // } // } // None //} }