Move image check in the engine

This commit is contained in:
Federico Terzi 2019-11-28 23:06:12 +01:00
parent 5c875eeaed
commit 283db379c8
2 changed files with 15 additions and 14 deletions

View File

@ -56,18 +56,13 @@ impl super::ClipboardManager for MacClipboardManager {
}
fn set_clipboard_image(&self, image_path: &Path) {
// Make sure the image exist beforehand
if !image_path.exists() {
error!("Image not found in path: {:?}", image_path);
}else{
let path_string = image_path.to_string_lossy().into_owned();
let res = CString::new(path_string);
if let Ok(path) = res {
unsafe {
let result = set_clipboard_image(path.as_ptr());
if result != 1 {
warn!("Couldn't set clipboard for image: {:?}", image_path)
}
let path_string = image_path.to_string_lossy().into_owned();
let res = CString::new(path_string);
if let Ok(path) = res {
unsafe {
let result = set_clipboard_image(path.as_ptr());
if result != 1 {
warn!("Couldn't set clipboard for image: {:?}", image_path)
}
}
}

View File

@ -219,8 +219,14 @@ impl <'a, S: KeyboardManager, C: ClipboardManager, M: ConfigManager<'a>, U: UIMa
// Image Match
MatchContentType::Image(content) => {
let image_path = PathBuf::from(&content.path);
self.clipboard_manager.set_clipboard_image(&image_path);
self.keyboard_manager.trigger_paste();
// Make sure the image exist beforehand
if image_path.exists() {
self.clipboard_manager.set_clipboard_image(&image_path);
self.keyboard_manager.trigger_paste();
}else{
error!("Image not found in path: {:?}", image_path);
}
},
}
}