use spawn_future_local

This commit is contained in:
yggverse 2025-07-29 21:47:27 +03:00
parent d5ffc672aa
commit 500ae1a20a

View File

@ -23,11 +23,11 @@ impl Bookmark {
action.bookmark.simple_action.name() action.bookmark.simple_action.name()
)) ))
.build(); .build();
update(profile, &button, &request.entry.text()); update(profile, &button, request.entry.text());
request.entry.connect_changed({ request.entry.connect_changed({
let b = button.clone(); let b = button.clone();
let p = profile.clone(); let p = profile.clone();
move |e| update(&p, &b, &e.text()) move |e| update(&p, &b, e.text())
}); });
Self { Self {
profile: profile.clone(), profile: profile.clone(),
@ -37,15 +37,17 @@ impl Bookmark {
} }
pub fn toggle(&self, title: Option<&str>) { pub fn toggle(&self, title: Option<&str>) {
let button = self.button.clone(); let t = title.map(|t| t.to_string());
let profile = self.profile.clone(); let p = self.profile.clone();
let query = self.request.entry.text(); let b = self.button.clone();
let title = title.map(|t| t.to_string()); let e = self.request.entry.clone();
button.set_sensitive(false); // lock gtk::glib::spawn_future_local(async move {
let has_bookmark = profile.bookmark.toggle(&query, title.as_deref()).unwrap(); b.set_sensitive(false); // lock
button.set_icon_name(icon_name(has_bookmark)); let has_bookmark = p.bookmark.toggle(&e.text(), t.as_deref()).unwrap();
button.set_tooltip_text(Some(tooltip_text(has_bookmark))); b.set_icon_name(icon_name(has_bookmark));
button.set_sensitive(true); b.set_tooltip_text(Some(tooltip_text(has_bookmark)));
b.set_sensitive(true)
}); // may take a while
} }
} }
@ -65,10 +67,14 @@ fn icon_name(has_bookmark: bool) -> &'static str {
} }
} }
fn update(profile: &Profile, button: &Button, request: &str) { fn update(profile: &Rc<Profile>, button: &Button, request: gtk::glib::GString) {
button.set_sensitive(false); // lock let p = profile.clone();
let has_bookmark = profile.bookmark.is_match_request(request); let b = button.clone();
button.set_icon_name(icon_name(has_bookmark)); gtk::glib::spawn_future_local(async move {
button.set_tooltip_text(Some(tooltip_text(has_bookmark))); b.set_sensitive(false); // lock
button.set_sensitive(true); let has_bookmark = p.bookmark.is_match_request(&request);
b.set_icon_name(icon_name(has_bookmark));
b.set_tooltip_text(Some(tooltip_text(has_bookmark)));
b.set_sensitive(true);
}); // may take a while
} }