update bookmark status asynchronously

This commit is contained in:
yggverse 2025-03-14 17:28:38 +02:00
parent c09e1ae722
commit d937d923c5

View file

@ -10,7 +10,7 @@ const TOOLTIP_TEXT: (&str, &str) = ("Add Bookmark", "Remove Bookmark");
pub trait Bookmark { pub trait Bookmark {
fn bookmark(action: &Rc<WindowAction>, profile: &Arc<Profile>, request: &Entry) -> Self; fn bookmark(action: &Rc<WindowAction>, profile: &Arc<Profile>, request: &Entry) -> Self;
fn update(&self, profile: &Profile, request: &Entry); fn update(&self, profile: &Arc<Profile>, request: &Entry);
} }
impl Bookmark for Button { impl Bookmark for Button {
@ -47,10 +47,20 @@ impl Bookmark for Button {
button button
} }
fn update(&self, profile: &Profile, request: &Entry) { fn update(&self, profile: &Arc<Profile>, request: &Entry) {
let has_bookmark = profile.bookmark.is_match_request(&request.text()); self.set_sensitive(false); // lock
self.set_icon_name(icon_name(has_bookmark)); let this = self.clone();
self.set_tooltip_text(Some(tooltip_text(has_bookmark))); let profile = profile.clone();
let query = request.text();
gtk::glib::spawn_future_local(async move {
let has_bookmark =
gtk::gio::spawn_blocking(move || profile.bookmark.is_match_request(&query))
.await
.unwrap();
this.set_icon_name(icon_name(has_bookmark));
this.set_tooltip_text(Some(tooltip_text(has_bookmark)));
this.set_sensitive(true);
}); // may take a while
} }
} }