From d937d923c5e0273208a067e5ba168eca43943804 Mon Sep 17 00:00:00 2001 From: yggverse Date: Fri, 14 Mar 2025 17:28:38 +0200 Subject: [PATCH] update bookmark status asynchronously --- .../tab/item/page/navigation/bookmark.rs | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/app/browser/window/tab/item/page/navigation/bookmark.rs b/src/app/browser/window/tab/item/page/navigation/bookmark.rs index 1c87ba75..a4701fa4 100644 --- a/src/app/browser/window/tab/item/page/navigation/bookmark.rs +++ b/src/app/browser/window/tab/item/page/navigation/bookmark.rs @@ -10,7 +10,7 @@ const TOOLTIP_TEXT: (&str, &str) = ("Add Bookmark", "Remove Bookmark"); pub trait Bookmark { fn bookmark(action: &Rc, profile: &Arc, request: &Entry) -> Self; - fn update(&self, profile: &Profile, request: &Entry); + fn update(&self, profile: &Arc, request: &Entry); } impl Bookmark for Button { @@ -47,10 +47,20 @@ impl Bookmark for Button { button } - fn update(&self, profile: &Profile, request: &Entry) { - let has_bookmark = profile.bookmark.is_match_request(&request.text()); - self.set_icon_name(icon_name(has_bookmark)); - self.set_tooltip_text(Some(tooltip_text(has_bookmark))); + fn update(&self, profile: &Arc, request: &Entry) { + self.set_sensitive(false); // lock + let this = self.clone(); + 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 } }