refresh proxy indication for all tabs on settings change, short local var names

This commit is contained in:
yggverse 2025-07-26 13:15:06 +03:00
parent 6d419f9234
commit 44661c5136
4 changed files with 88 additions and 61 deletions

View file

@ -15,11 +15,11 @@ use rule::Rule;
use std::rc::Rc;
pub trait Proxy {
fn proxy(profile: &Rc<Profile>) -> Self;
fn proxy(profile: &Rc<Profile>, on_close: impl Fn() + 'static) -> Self;
}
impl Proxy for adw::PreferencesDialog {
fn proxy(profile: &Rc<Profile>) -> Self {
fn proxy(profile: &Rc<Profile>, on_close: impl Fn() + 'static) -> Self {
// Init components
let ignore = Ignore::build(profile);
let misc = Misc::build(profile);
@ -98,6 +98,8 @@ impl Proxy for adw::PreferencesDialog {
.proxy
.misc
.set_highlight_request_entry(misc.is_highlight_request_entry());
on_close()
}
});
d

View file

@ -358,6 +358,10 @@ impl Tab {
// @TODO other/child features..
}
pub fn items(&self) -> Vec<Rc<Item>> {
self.index.borrow().values().cloned().collect()
}
/// Find `Item` by `TabPage` position in HashMap `index`
fn item(&self, page_position: Option<i32>) -> Option<Rc<Item>> {
match page_position {

View file

@ -141,33 +141,8 @@ impl Request {
if e.focus_child().is_some() {
s.update(Some(50)); // @TODO optional
}
// Indicate proxy connections @TODO cancel previous operation on update
if p.proxy.misc.is_highlight_request_entry()
&& let Some(m) = p.proxy.matches(&t)
{
m.clone().lookup_async(&t, Cancellable::NONE, {
let e = e.clone();
let r = r.clone();
move |l| {
r.replace(Some(m));
e.set_tooltip_text(Some(&{
match l {
Ok(h) => {
e.set_css_classes(&["accent"]);
format!("Proxy over {}", h.join(","))
}
Err(i) => {
e.set_css_classes(&["error"]);
i.to_string()
}
}
}))
}
})
} else {
e.set_css_classes(&[]);
e.set_tooltip_text(None)
}
refresh_proxy_resolver(e, &p, &r)
}
})); // `suggestion` wants `signal_handler_id` to block this event on autocomplete navigation
@ -280,6 +255,10 @@ impl Request {
Ok(())
}
pub fn refresh(&self) {
refresh_proxy_resolver(&self.entry, &self.profile, &self.proxy_resolver)
}
pub fn update_secondary_icon(&self, info: &Info) {
update_secondary_icon(&self.entry, info);
}
@ -494,3 +473,38 @@ fn update_blocked(
update_primary_icon(entry, profile);
entry.unblock_signal(signal_handler_id);
}
/// Indicate proxy connections @TODO cancel previous operation on update
fn refresh_proxy_resolver(
entry: &Entry,
profile: &Profile,
resolver: &Rc<RefCell<Option<ProxyResolver>>>,
) {
let t = entry.text();
if profile.proxy.misc.is_highlight_request_entry()
&& let Some(m) = profile.proxy.matches(&t)
{
m.clone().lookup_async(&t, Cancellable::NONE, {
let e = entry.clone();
let r = resolver.clone();
move |l| {
r.replace(Some(m));
e.set_tooltip_text(Some(&{
match l {
Ok(h) => {
e.set_css_classes(&["accent"]);
format!("Proxy over {}", h.join(","))
}
Err(i) => {
e.set_css_classes(&["error"]);
i.to_string()
}
}
}))
}
})
} else {
entry.set_css_classes(&[]);
entry.set_tooltip_text(None)
}
}