Skip to content

Commit fe3ae28

Browse files
committed
Load image texture in thread
1 parent 4105696 commit fe3ae28

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

src/widgets/message_row.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ use std::io::Read;
33
use adw::prelude::*;
44
use adw::subclass::prelude::*;
55
use chrono::NaiveDateTime;
6-
use gdk_pixbuf::Pixbuf;
7-
use gtk::gdk_pixbuf;
86
use gtk::{gdk, gio, glib};
97
use ntfy_daemon::models;
108
use tracing::error;
@@ -165,9 +163,11 @@ impl MessageRow {
165163
fn build_image(&self, url: String) -> gtk::Picture {
166164
let (s, r) = async_channel::unbounded();
167165
gio::spawn_blocking(move || {
168-
if let Err(e) = Self::fetch_image_bytes(&url)
169-
.map(|bytes| s.send_blocking(glib::Bytes::from_owned(bytes)))
170-
{
166+
if let Err(e) = Self::fetch_image_bytes(&url).and_then(|bytes| {
167+
let t = gdk::Texture::from_bytes(&glib::Bytes::from_owned(bytes))?;
168+
s.send_blocking(t)?;
169+
Ok(())
170+
}) {
171171
error!(error = %e)
172172
}
173173
glib::ControlFlow::Break
@@ -178,10 +178,8 @@ impl MessageRow {
178178
let picturec = picture.clone();
179179

180180
self.spawn_with_near_toast(async move {
181-
let b = r.recv().await?;
182-
let stream = gio::MemoryInputStream::from_bytes(&b);
183-
let pixbuf = Pixbuf::from_stream(&stream, gio::Cancellable::NONE)?;
184-
picturec.set_paintable(Some(&gdk::Texture::for_pixbuf(&pixbuf)));
181+
let t = r.recv().await?;
182+
picturec.set_paintable(Some(&t));
185183
Ok::<(), anyhow::Error>(())
186184
});
187185

0 commit comments

Comments
 (0)