Load image texture in thread
This commit is contained in:
@ -3,8 +3,6 @@ use std::io::Read;
|
|||||||
use adw::prelude::*;
|
use adw::prelude::*;
|
||||||
use adw::subclass::prelude::*;
|
use adw::subclass::prelude::*;
|
||||||
use chrono::NaiveDateTime;
|
use chrono::NaiveDateTime;
|
||||||
use gdk_pixbuf::Pixbuf;
|
|
||||||
use gtk::gdk_pixbuf;
|
|
||||||
use gtk::{gdk, gio, glib};
|
use gtk::{gdk, gio, glib};
|
||||||
use ntfy_daemon::models;
|
use ntfy_daemon::models;
|
||||||
use tracing::error;
|
use tracing::error;
|
||||||
@ -165,9 +163,11 @@ impl MessageRow {
|
|||||||
fn build_image(&self, url: String) -> gtk::Picture {
|
fn build_image(&self, url: String) -> gtk::Picture {
|
||||||
let (s, r) = async_channel::unbounded();
|
let (s, r) = async_channel::unbounded();
|
||||||
gio::spawn_blocking(move || {
|
gio::spawn_blocking(move || {
|
||||||
if let Err(e) = Self::fetch_image_bytes(&url)
|
if let Err(e) = Self::fetch_image_bytes(&url).and_then(|bytes| {
|
||||||
.map(|bytes| s.send_blocking(glib::Bytes::from_owned(bytes)))
|
let t = gdk::Texture::from_bytes(&glib::Bytes::from_owned(bytes))?;
|
||||||
{
|
s.send_blocking(t)?;
|
||||||
|
Ok(())
|
||||||
|
}) {
|
||||||
error!(error = %e)
|
error!(error = %e)
|
||||||
}
|
}
|
||||||
glib::ControlFlow::Break
|
glib::ControlFlow::Break
|
||||||
@ -178,10 +178,8 @@ impl MessageRow {
|
|||||||
let picturec = picture.clone();
|
let picturec = picture.clone();
|
||||||
|
|
||||||
self.spawn_with_near_toast(async move {
|
self.spawn_with_near_toast(async move {
|
||||||
let b = r.recv().await?;
|
let t = r.recv().await?;
|
||||||
let stream = gio::MemoryInputStream::from_bytes(&b);
|
picturec.set_paintable(Some(&t));
|
||||||
let pixbuf = Pixbuf::from_stream(&stream, gio::Cancellable::NONE)?;
|
|
||||||
picturec.set_paintable(Some(&gdk::Texture::for_pixbuf(&pixbuf)));
|
|
||||||
Ok::<(), anyhow::Error>(())
|
Ok::<(), anyhow::Error>(())
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user