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

@ -66,31 +66,31 @@ impl Browser {
// Connect events // Connect events
action.about.connect_activate({ action.about.connect_activate({
let window = window.clone(); let w = window.clone();
move || AboutDialog::about().present(Some(&window.g_box)) move || AboutDialog::about().present(Some(&w.g_box))
}); });
action.close.connect_activate({ action.close.connect_activate({
let widget = widget.clone(); let w = widget.clone();
move || widget.application_window.close() move || w.application_window.close()
}); });
action.debug.connect_activate({ action.debug.connect_activate({
let widget = widget.clone(); let w = widget.clone();
move || { move || {
widget.application_window.emit_enable_debugging(true); w.application_window.emit_enable_debugging(true);
} }
}); });
action.profile.connect_activate({ action.profile.connect_activate({
let profile = profile.clone(); let p = profile.clone();
move || { move || {
FileLauncher::new(Some(&File::for_path(profile.config_path.as_path()))).launch( FileLauncher::new(Some(&File::for_path(p.config_path.as_path()))).launch(
adw::Window::NONE, adw::Window::NONE,
Cancellable::NONE, Cancellable::NONE,
|result| { |r| {
if let Err(error) = result { if let Err(e) = r {
println!("{error}") println!("{e}")
} }
}, },
); // @TODO move out? ); // @TODO move out?
@ -98,25 +98,32 @@ impl Browser {
}); });
action.history.connect_activate({ action.history.connect_activate({
let profile = profile.clone(); let p = profile.clone();
let window = window.clone(); let w = window.clone();
move || { move || PreferencesDialog::history(&w.action, &p).present(Some(&w.g_box))
PreferencesDialog::history(&window.action, &profile).present(Some(&window.g_box))
}
}); });
action.bookmarks.connect_activate({ action.bookmarks.connect_activate({
let profile = profile.clone(); let p = profile.clone();
let window = window.clone(); let w = window.clone();
move || { move || PreferencesDialog::bookmarks(&w.action, &p).present(Some(&w.g_box))
PreferencesDialog::bookmarks(&window.action, &profile).present(Some(&window.g_box))
}
}); });
action.proxy.connect_activate({ action.proxy.connect_activate({
let profile = profile.clone(); let p = profile.clone();
let window = window.clone(); let w = window.clone();
move || PreferencesDialog::proxy(&profile).present(Some(&window.g_box)) move || {
PreferencesDialog::proxy(&p, {
let w = w.clone();
move || {
w.tab
.items()
.into_iter()
.for_each(|i| i.page.navigation.request.refresh())
}
})
.present(Some(&w.g_box))
}
}); });
// Return new activated `Self` // Return new activated `Self`
@ -130,11 +137,11 @@ impl Browser {
// Actions // Actions
pub fn clean(&self, transaction: &Transaction, app_id: i64) -> Result<()> { pub fn clean(&self, transaction: &Transaction, app_id: i64) -> Result<()> {
for record in database::select(transaction, app_id)? { for r in database::select(transaction, app_id)? {
database::delete(transaction, record.id)?; database::delete(transaction, r.id)?;
// Delegate clean action to childs // Delegate clean action to childs
self.window.clean(transaction, record.id)?; self.window.clean(transaction, r.id)?;
self.widget.clean(transaction, record.id)?; self.widget.clean(transaction, r.id)?;
/* @TODO /* @TODO
self.header.clean(transaction, &record.id)?; */ self.header.clean(transaction, &record.id)?; */
} }
@ -142,12 +149,12 @@ impl Browser {
} }
pub fn restore(&self, transaction: &Transaction, app_id: i64) -> Result<()> { pub fn restore(&self, transaction: &Transaction, app_id: i64) -> Result<()> {
for record in database::select(transaction, app_id)? { for r in database::select(transaction, app_id)? {
// Delegate restore action to childs // Delegate restore action to childs
self.widget.restore(transaction, record.id)?; self.widget.restore(transaction, r.id)?;
self.window.restore(transaction, record.id)?; self.window.restore(transaction, r.id)?;
/* @TODO /* @TODO
self.header.restore(transaction, &record.id)?; */ self.header.restore(transaction, &r.id)?; */
} }
Ok(()) Ok(())
} }

View File

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

View File

@ -358,6 +358,10 @@ impl Tab {
// @TODO other/child features.. // @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` /// Find `Item` by `TabPage` position in HashMap `index`
fn item(&self, page_position: Option<i32>) -> Option<Rc<Item>> { fn item(&self, page_position: Option<i32>) -> Option<Rc<Item>> {
match page_position { match page_position {

View File

@ -141,33 +141,8 @@ impl Request {
if e.focus_child().is_some() { if e.focus_child().is_some() {
s.update(Some(50)); // @TODO optional s.update(Some(50)); // @TODO optional
} }
// Indicate proxy connections @TODO cancel previous operation on update
if p.proxy.misc.is_highlight_request_entry() refresh_proxy_resolver(e, &p, &r)
&& 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)
}
} }
})); // `suggestion` wants `signal_handler_id` to block this event on autocomplete navigation })); // `suggestion` wants `signal_handler_id` to block this event on autocomplete navigation
@ -280,6 +255,10 @@ impl Request {
Ok(()) Ok(())
} }
pub fn refresh(&self) {
refresh_proxy_resolver(&self.entry, &self.profile, &self.proxy_resolver)
}
pub fn update_secondary_icon(&self, info: &Info) { pub fn update_secondary_icon(&self, info: &Info) {
update_secondary_icon(&self.entry, info); update_secondary_icon(&self.entry, info);
} }
@ -494,3 +473,38 @@ fn update_blocked(
update_primary_icon(entry, profile); update_primary_icon(entry, profile);
entry.unblock_signal(signal_handler_id); 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)
}
}