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>>>>,
window_action: &Rc<WindowAction>,
) {
if let Some(tab_page) = tab_page {
if let Some(item) = index.borrow().get(tab_page) {
window_action
.home
.simple_action
.set_enabled(item.action.home.is_enabled());
window_action
.reload
.simple_action
.set_enabled(item.action.reload.is_enabled());
window_action
.history_back
.simple_action
.set_enabled(item.action.history.back.is_enabled());
window_action
.history_forward
.simple_action
.set_enabled(item.action.history.forward.is_enabled());
window_action
.save_as
.simple_action
.set_enabled(!item.page.navigation.request.is_file());
if let Some(tab_page) = tab_page
&& let Some(item) = index.borrow().get(tab_page)
{
window_action
.home
.simple_action
.set_enabled(item.action.home.is_enabled());
window_action
.reload
.simple_action
.set_enabled(item.action.reload.is_enabled());
window_action
.history_back
.simple_action
.set_enabled(item.action.history.back.is_enabled());
window_action
.history_forward
.simple_action
.set_enabled(item.action.history.forward.is_enabled());
window_action
.save_as
.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
window_action.home.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();
for ref entity in source_code.ansi_parse() {
if let Output::Escape(AnsiSequence::SetGraphicsMode(color)) = entity {
if color.len() > 1 {
if color[0] == 38 {
tag.text_tag
.set_foreground_rgba(rgba::default(*color.last().unwrap()).as_ref());
} else {
tag.text_tag
.set_background_rgba(rgba::default(*color.last().unwrap()).as_ref());
}
if let Output::Escape(AnsiSequence::SetGraphicsMode(color)) = entity
&& color.len() > 1
{
if color[0] == 38 {
tag.text_tag
.set_foreground_rgba(rgba::default(*color.last().unwrap()).as_ref());
} else {
tag.text_tag
.set_background_rgba(rgba::default(*color.last().unwrap()).as_ref());
}
}
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
if base.to_string().ends_with("/") {
// just borrow ggemtext parser as compatible API
if let Some(link) = ggemtext::line::Link::parse(line) {
if let Some(uri) = link.uri(Some(base)) {
let a = TextTag::builder()
.foreground_rgba(&link_color.0)
// .foreground_rgba(&adw::StyleManager::default().accent_color_rgba()) @TODO adw 1.6 / ubuntu 24.10+
.sentence(true)
.wrap_mode(WrapMode::Word)
.build();
if let Some(link) = ggemtext::line::Link::parse(line)
&& let Some(uri) = link.uri(Some(base))
{
let a = TextTag::builder()
.foreground_rgba(&link_color.0)
// .foreground_rgba(&adw::StyleManager::default().accent_color_rgba()) @TODO adw 1.6 / ubuntu 24.10+
.sentence(true)
.wrap_mode(WrapMode::Word)
.build();
if !tags.add(&a) {
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;
if !tags.add(&a) {
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;
}
}
// 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>) {
// connect identity traits
use identity::{Common, Unsupported};
if let Some(uri) = uri(entry) {
if ["gemini", "titan"].contains(&uri.scheme().as_str()) {
return AlertDialog::common(
profile,
&uri,
&Rc::new({
let p = profile.clone();
let e = entry.clone();
move |is_reload| {
update_primary_icon(&e, &p);
if is_reload {
e.emit_activate();
}
if let Some(uri) = uri(entry)
&& ["gemini", "titan"].contains(&uri.scheme().as_str())
{
return AlertDialog::common(
profile,
&uri,
&Rc::new({
let p = profile.clone();
let e = entry.clone();
move |is_reload| {
update_primary_icon(&e, &p);
if is_reload {
e.emit_activate();
}
}),
)
.present(Some(entry));
}
}
}),
)
.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>"));
}
if let Some(not_valid_before) = certificate.not_valid_before() {
if let Ok(timestamp) = not_valid_before.format_iso8601() {
tooltip.push_str(&format!("\n<small><b>valid after</b>\n{timestamp}</small>"));
}
if let Some(not_valid_before) = certificate.not_valid_before()
&& let Ok(timestamp) = not_valid_before.format_iso8601()
{
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 Ok(timestamp) = not_valid_after.format_iso8601() {
tooltip.push_str(&format!(
"\n<small><b>valid before</b>\n{timestamp}</small>"
));
}
if let Some(not_valid_after) = certificate.not_valid_after()
&& let Ok(timestamp) = not_valid_after.format_iso8601()
{
tooltip.push_str(&format!(
"\n<small><b>valid before</b>\n{timestamp}</small>"
));
}
if !scope.is_empty() {

View File

@ -148,11 +148,11 @@ impl Dialog for PreferencesDialog {
if let Some(iso_code) = c.iso_code {
b.push(iso_code)
}
if let Some(n) = c.names {
if let Some(s) = n.get("en") {
b.push(s)
} // @TODO multi-lang
}
if let Some(n) = c.names
&& let Some(s) = n.get("en")
{
b.push(s)
} // @TODO multi-lang
// @TODO city DB
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();
if prefix.starts_with("download:") {

View File

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