Avoid lock AppOp during the call to wait_is_image_available

Fix #284
This commit is contained in:
Daniel García Moreno 2018-10-29 19:27:39 +01:00
parent d8b8796393
commit 0cdda08a08
3 changed files with 29 additions and 20 deletions

View file

@ -2,6 +2,7 @@ use gdk;
use gtk;
use gtk::prelude::*;
use sourceview::BufferExt;
use appop::attach;
use app::App;
@ -56,7 +57,7 @@ impl App {
op = self.op.clone();
msg_entry.connect_paste_clipboard(move |_| {
op.lock().unwrap().paste();
attach::paste(op.clone());
});
msg_entry.connect_focus_in_event(clone!(msg_entry_box => move |_, _| {

View file

@ -1,5 +1,6 @@
use i18n::i18n;
use std::sync::{Arc, Mutex};
use std::fs::File;
use std::io::prelude::*;
use std::path::PathBuf;
@ -22,24 +23,6 @@ use util::get_pixbuf_data;
impl AppOp {
pub fn paste(&self) {
if let Some(display) = gdk::Display::get_default() {
if let Some(clipboard) = gtk::Clipboard::get_default(&display) {
if clipboard.wait_is_image_available() {
if let Some(pixb) = clipboard.wait_for_image() {
self.draw_image_paste_dialog(&pixb);
// removing text from clipboard
clipboard.set_text("");
clipboard.set_image(&pixb);
}
} else {
// TODO: manage code pasting
}
}
}
}
fn draw_image_paste_dialog(&self, pixb: &Pixbuf) {
let w = pixb.get_width();
let h = pixb.get_height();
@ -107,3 +90,28 @@ fn store_pixbuf(pixb: &Pixbuf) -> Result<String, Error> {
Ok(file)
}
/// This function receives the appop mutex to avoid lock the interface
/// This was previously an appop method that receives &self, but that
/// force us to lock the interface for the entire function that causes
/// problems because we call to wait_is_image_available that makes that
/// tries to continue the loop and that give us to a deadlock so
/// this function minimize the lock and avoid that kind of problems
/// See: https://gitlab.gnome.org/World/fractal/issues/284
pub fn paste(op: Arc<Mutex<AppOp>>) {
if let Some(display) = gdk::Display::get_default() {
if let Some(clipboard) = gtk::Clipboard::get_default(&display) {
if clipboard.wait_is_image_available() {
if let Some(pixb) = clipboard.wait_for_image() {
op.lock().unwrap().draw_image_paste_dialog(&pixb);
// removing text from clipboard
clipboard.set_text("");
clipboard.set_image(&pixb);
}
} else {
// TODO: manage code pasting
}
}
}
}

View file

@ -36,7 +36,7 @@ mod files;
mod message;
mod directory;
mod notify;
mod attach;
pub mod attach;
mod member;
mod invite;
mod about;