remove deprecated MainContext channel
This commit is contained in:
@ -145,24 +145,29 @@ impl AddSubscriptionDialog {
|
||||
},
|
||||
}
|
||||
|
||||
let (tx, rx) = glib::MainContext::channel(Default::default());
|
||||
let txc = tx.clone();
|
||||
topic_entry.delegate().unwrap().connect_changed(move |_| {
|
||||
txc.send(()).unwrap();
|
||||
});
|
||||
let txc = tx.clone();
|
||||
server_entry.delegate().unwrap().connect_changed(move |_| {
|
||||
txc.send(()).unwrap();
|
||||
});
|
||||
server_expander.connect_enable_expansion_notify(move |_| {
|
||||
tx.send(()).unwrap();
|
||||
});
|
||||
let rx = crate::async_utils::debounce_channel(std::time::Duration::from_millis(500), rx);
|
||||
let objc = obj.clone();
|
||||
rx.attach(None, move |_| {
|
||||
objc.check_errors();
|
||||
glib::ControlFlow::Continue
|
||||
});
|
||||
let debounced_error_check = {
|
||||
let db = crate::async_utils::Debouncer::new();
|
||||
let objc = obj.clone();
|
||||
move || {
|
||||
db.call(std::time::Duration::from_millis(500), move || {
|
||||
objc.check_errors()
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
let f = debounced_error_check.clone();
|
||||
topic_entry
|
||||
.delegate()
|
||||
.unwrap()
|
||||
.connect_changed(move |_| f.clone()());
|
||||
let f = debounced_error_check.clone();
|
||||
server_entry
|
||||
.delegate()
|
||||
.unwrap()
|
||||
.connect_changed(move |_| f.clone()());
|
||||
let f = debounced_error_check.clone();
|
||||
server_expander.connect_enable_expansion_notify(move |_| f.clone()());
|
||||
|
||||
imp.widgets.replace(Widgets {
|
||||
topic_entry,
|
||||
server_expander,
|
||||
|
||||
@ -9,6 +9,8 @@ use gtk::{gdk, gio, glib};
|
||||
use ntfy_daemon::models;
|
||||
use tracing::error;
|
||||
|
||||
use crate::widgets::window::SpawnWithToast;
|
||||
|
||||
mod imp {
|
||||
use super::*;
|
||||
|
||||
@ -161,10 +163,10 @@ impl MessageRow {
|
||||
Ok(bytes)
|
||||
}
|
||||
fn build_image(&self, url: String) -> gtk::Picture {
|
||||
let (tx, rx) = glib::MainContext::channel(Default::default());
|
||||
let (s, r) = async_channel::unbounded();
|
||||
gio::spawn_blocking(move || {
|
||||
if let Err(e) =
|
||||
Self::fetch_image_bytes(&url).map(|bytes| tx.send(glib::Bytes::from_owned(bytes)))
|
||||
if let Err(e) = Self::fetch_image_bytes(&url)
|
||||
.map(|bytes| s.send_blocking(glib::Bytes::from_owned(bytes)))
|
||||
{
|
||||
error!(error = %e)
|
||||
}
|
||||
@ -174,18 +176,15 @@ impl MessageRow {
|
||||
picture.set_can_shrink(true);
|
||||
picture.set_height_request(350);
|
||||
let picturec = picture.clone();
|
||||
rx.attach(Default::default(), move |b| {
|
||||
|
||||
self.spawn_with_near_toast(async move {
|
||||
let b = r.recv().await?;
|
||||
let stream = gio::MemoryInputStream::from_bytes(&b);
|
||||
let pixbuf = match Pixbuf::from_stream(&stream, gio::Cancellable::NONE) {
|
||||
Ok(res) => res,
|
||||
Err(e) => {
|
||||
error!(error = %e, "parsing image contents");
|
||||
return glib::ControlFlow::Break;
|
||||
}
|
||||
};
|
||||
let pixbuf = Pixbuf::from_stream(&stream, gio::Cancellable::NONE)?;
|
||||
picturec.set_paintable(Some(&gdk::Texture::for_pixbuf(&pixbuf)));
|
||||
glib::ControlFlow::Break
|
||||
Ok::<(), anyhow::Error>(())
|
||||
});
|
||||
|
||||
picture
|
||||
}
|
||||
fn build_action_btn(&self, action: models::Action) -> gtk::Button {
|
||||
|
||||
@ -49,23 +49,19 @@ mod imp {
|
||||
self.parent_constructed();
|
||||
let this = self.obj().clone();
|
||||
|
||||
let (tx, rx) = glib::MainContext::channel(glib::Priority::default());
|
||||
let rx =
|
||||
crate::async_utils::debounce_channel(std::time::Duration::from_millis(500), rx);
|
||||
rx.attach(None, move |entry| {
|
||||
this.update_display_name(&entry);
|
||||
glib::ControlFlow::Continue
|
||||
});
|
||||
|
||||
let this = self.obj().clone();
|
||||
self.display_name_entry
|
||||
.set_text(&this.subscription().unwrap().display_name());
|
||||
self.muted_switch_row
|
||||
.set_active(this.subscription().unwrap().muted());
|
||||
|
||||
let debouncer = crate::async_utils::Debouncer::new();
|
||||
self.display_name_entry.connect_changed({
|
||||
move |entry| {
|
||||
tx.send(entry.clone()).unwrap();
|
||||
let entry = entry.clone();
|
||||
let this = this.clone();
|
||||
debouncer.call(std::time::Duration::from_millis(500), move || {
|
||||
this.update_display_name(&entry);
|
||||
})
|
||||
}
|
||||
});
|
||||
let this = self.obj().clone();
|
||||
|
||||
Reference in New Issue
Block a user