apply clippy optimizations

This commit is contained in:
yggverse 2025-08-22 18:03:34 +03:00
parent 5d3d6d4c7f
commit adadb149b8
8 changed files with 112 additions and 115 deletions

View File

@ -400,33 +400,34 @@ fn update_actions(
index: &Rc<RefCell<HashMap<TabPage, Rc<Item>>>>, index: &Rc<RefCell<HashMap<TabPage, Rc<Item>>>>,
window_action: &Rc<WindowAction>, window_action: &Rc<WindowAction>,
) { ) {
if let Some(tab_page) = tab_page { if let Some(tab_page) = tab_page
if let Some(item) = index.borrow().get(tab_page) { && let Some(item) = index.borrow().get(tab_page)
window_action {
.home window_action
.simple_action .home
.set_enabled(item.action.home.is_enabled()); .simple_action
window_action .set_enabled(item.action.home.is_enabled());
.reload window_action
.simple_action .reload
.set_enabled(item.action.reload.is_enabled()); .simple_action
window_action .set_enabled(item.action.reload.is_enabled());
.history_back window_action
.simple_action .history_back
.set_enabled(item.action.history.back.is_enabled()); .simple_action
window_action .set_enabled(item.action.history.back.is_enabled());
.history_forward window_action
.simple_action .history_forward
.set_enabled(item.action.history.forward.is_enabled()); .simple_action
window_action .set_enabled(item.action.history.forward.is_enabled());
.save_as window_action
.simple_action .save_as
.set_enabled(!item.page.navigation.request.is_file()); .simple_action
.set_enabled(!item.page.navigation.request.is_file());
window_action.change_state(Some(tab_view.page_position(tab_page)));
return;
} // @TODO `connect_selected_page_notify` panics on unwrap
window_action.change_state(Some(tab_view.page_position(tab_page)));
return;
} // @TODO `connect_selected_page_notify` panics on unwrap
}
// Reset to defaults // Reset to defaults
window_action.home.simple_action.set_enabled(false); window_action.home.simple_action.set_enabled(false);
window_action.reload.simple_action.set_enabled(false); window_action.reload.simple_action.set_enabled(false);

View File

@ -12,15 +12,15 @@ pub fn format(source_code: &str) -> Vec<(TextTag, String)> {
let mut tag = Tag::new(); let mut tag = Tag::new();
for ref entity in source_code.ansi_parse() { for ref entity in source_code.ansi_parse() {
if let Output::Escape(AnsiSequence::SetGraphicsMode(color)) = entity { if let Output::Escape(AnsiSequence::SetGraphicsMode(color)) = entity
if color.len() > 1 { && color.len() > 1
if color[0] == 38 { {
tag.text_tag if color[0] == 38 {
.set_foreground_rgba(rgba::default(*color.last().unwrap()).as_ref()); tag.text_tag
} else { .set_foreground_rgba(rgba::default(*color.last().unwrap()).as_ref());
tag.text_tag } else {
.set_background_rgba(rgba::default(*color.last().unwrap()).as_ref()); tag.text_tag
} .set_background_rgba(rgba::default(*color.last().unwrap()).as_ref());
} }
} }
if let Output::TextBlock(text) = entity { if let Output::TextBlock(text) = entity {

View File

@ -69,45 +69,41 @@ impl Nex for TextView {
// it may be confusing: gemini://bbs.geminispace.org/s/nex/29641 // it may be confusing: gemini://bbs.geminispace.org/s/nex/29641
if base.to_string().ends_with("/") { if base.to_string().ends_with("/") {
// just borrow ggemtext parser as compatible API // just borrow ggemtext parser as compatible API
if let Some(link) = ggemtext::line::Link::parse(line) { if let Some(link) = ggemtext::line::Link::parse(line)
if let Some(uri) = link.uri(Some(base)) { && let Some(uri) = link.uri(Some(base))
let a = TextTag::builder() {
.foreground_rgba(&link_color.0) let a = TextTag::builder()
// .foreground_rgba(&adw::StyleManager::default().accent_color_rgba()) @TODO adw 1.6 / ubuntu 24.10+ .foreground_rgba(&link_color.0)
.sentence(true) // .foreground_rgba(&adw::StyleManager::default().accent_color_rgba()) @TODO adw 1.6 / ubuntu 24.10+
.wrap_mode(WrapMode::Word) .sentence(true)
.build(); .wrap_mode(WrapMode::Word)
.build();
if !tags.add(&a) { if !tags.add(&a) {
panic!() panic!()
}
buffer.insert_with_tags(
&mut buffer.end_iter(),
&format!(
"{} {}",
if uri.scheme() == base.scheme() {
"=>"
} else {
"<="
},
link.url
),
&[&a],
);
if let Some(alt) = link.alt {
buffer.insert_with_tags(
&mut buffer.end_iter(),
&format!(" {alt}"),
&[&p],
);
}
buffer.insert(&mut buffer.end_iter(), NEW_LINE);
links.insert(a, uri);
continue;
} }
buffer.insert_with_tags(
&mut buffer.end_iter(),
&format!(
"{} {}",
if uri.scheme() == base.scheme() {
"=>"
} else {
"<="
},
link.url
),
&[&a],
);
if let Some(alt) = link.alt {
buffer.insert_with_tags(&mut buffer.end_iter(), &format!(" {alt}"), &[&p]);
}
buffer.insert(&mut buffer.end_iter(), NEW_LINE);
links.insert(a, uri);
continue;
} }
} }
// Nothing match custom tags above, // Nothing match custom tags above,

View File

@ -386,24 +386,24 @@ fn is_focused(entry: &Entry) -> bool {
fn show_identity_dialog(entry: &Entry, profile: &Rc<Profile>) { fn show_identity_dialog(entry: &Entry, profile: &Rc<Profile>) {
// connect identity traits // connect identity traits
use identity::{Common, Unsupported}; use identity::{Common, Unsupported};
if let Some(uri) = uri(entry) { if let Some(uri) = uri(entry)
if ["gemini", "titan"].contains(&uri.scheme().as_str()) { && ["gemini", "titan"].contains(&uri.scheme().as_str())
return AlertDialog::common( {
profile, return AlertDialog::common(
&uri, profile,
&Rc::new({ &uri,
let p = profile.clone(); &Rc::new({
let e = entry.clone(); let p = profile.clone();
move |is_reload| { let e = entry.clone();
update_primary_icon(&e, &p); move |is_reload| {
if is_reload { update_primary_icon(&e, &p);
e.emit_activate(); if is_reload {
} e.emit_activate();
} }
}), }
) }),
.present(Some(entry)); )
} .present(Some(entry));
} }
AlertDialog::unsupported().present(Some(entry)); AlertDialog::unsupported().present(Some(entry));
} }

View File

@ -11,18 +11,18 @@ pub fn new_for_profile_identity_id(certificate: &TlsCertificate, scope: &[String
tooltip.push_str(&format!("\n<small><b>issuer</b>\n{issuer_name}</small>")); tooltip.push_str(&format!("\n<small><b>issuer</b>\n{issuer_name}</small>"));
} }
if let Some(not_valid_before) = certificate.not_valid_before() { if let Some(not_valid_before) = certificate.not_valid_before()
if let Ok(timestamp) = not_valid_before.format_iso8601() { && let Ok(timestamp) = not_valid_before.format_iso8601()
tooltip.push_str(&format!("\n<small><b>valid after</b>\n{timestamp}</small>")); {
} tooltip.push_str(&format!("\n<small><b>valid after</b>\n{timestamp}</small>"));
} }
if let Some(not_valid_after) = certificate.not_valid_after() { if let Some(not_valid_after) = certificate.not_valid_after()
if let Ok(timestamp) = not_valid_after.format_iso8601() { && let Ok(timestamp) = not_valid_after.format_iso8601()
tooltip.push_str(&format!( {
"\n<small><b>valid before</b>\n{timestamp}</small>" tooltip.push_str(&format!(
)); "\n<small><b>valid before</b>\n{timestamp}</small>"
} ));
} }
if !scope.is_empty() { if !scope.is_empty() {

View File

@ -148,11 +148,11 @@ impl Dialog for PreferencesDialog {
if let Some(iso_code) = c.iso_code { if let Some(iso_code) = c.iso_code {
b.push(iso_code) b.push(iso_code)
} }
if let Some(n) = c.names { if let Some(n) = c.names
if let Some(s) = n.get("en") { && let Some(s) = n.get("en")
b.push(s) {
} // @TODO multi-lang b.push(s)
} } // @TODO multi-lang
// @TODO city DB // @TODO city DB
b.join(", ") b.join(", ")
}) })

View File

@ -29,7 +29,7 @@ pub enum PrimaryIcon<'a> {
}, },
} }
pub fn from(request: &str) -> PrimaryIcon { pub fn from(request: &str) -> PrimaryIcon<'_> {
let prefix = request.to_lowercase(); let prefix = request.to_lowercase();
if prefix.starts_with("download:") { if prefix.starts_with("download:") {

View File

@ -51,16 +51,16 @@ impl Suggestion {
let r = resolver.clone(); let r = resolver.clone();
let signal_handler_id = signal_handler_id.clone(); let signal_handler_id = signal_handler_id.clone();
move |this| { move |this| {
if let Some(selected_item) = this.selected_item() { if let Some(selected_item) = this.selected_item()
if let Some(signal_handler_id) = signal_handler_id.borrow().as_ref() { && let Some(signal_handler_id) = signal_handler_id.borrow().as_ref()
super::update_blocked( {
&p, super::update_blocked(
&e, &p,
signal_handler_id, &e,
&selected_item.downcast_ref::<Item>().unwrap().request(), signal_handler_id,
&r, &selected_item.downcast_ref::<Item>().unwrap().request(),
); &r,
} );
} // @TODO find signal to handle selected item only } // @TODO find signal to handle selected item only
} }
}); });