Skip to content

Commit

Permalink
chore: clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
NotAShelf committed Mar 18, 2024
1 parent 14a7f61 commit 9d71fca
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 22 deletions.
8 changes: 2 additions & 6 deletions src/svg/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,15 @@ impl ResvgRenderer {
}

pub fn load_icon(enabled: bool) -> Vec<Icon> {
let svg_data = std::fs::read_to_string(SVG_DATA).unwrap_or_else(|e| {
panic!("Failed to read SVG: {}", e);
});

let mut renderer = ResvgRenderer {
options: Options::default(),
transform: Transform::default(),
font_db: fontdb::Database::new(),
};

match enabled {
true => vec![renderer.to_icon(&svg_data)],
false => vec![renderer.to_icon(&svg_data.replace("1.0", "0.4"))],
true => vec![renderer.to_icon(&SVG_DATA)],
false => vec![renderer.to_icon(&SVG_DATA.replace("1.0", "0.4"))],
}
}
}
8 changes: 4 additions & 4 deletions src/tailscale/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ use which::which;

pub fn get_current_status() -> Context {
let status: utils::Status = utils::get_status().unwrap();
let ctx = Context {


Context {
ip: status.this_machine.ips[0].clone(),
pkexec: which("pkexec").unwrap(),
status,
};

ctx
}
}
20 changes: 10 additions & 10 deletions src/tailscale/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,21 +98,21 @@ fn dns_or_quote_hostname(m: &mut Machine, dns_suffix: &str) {
}
}
fn has_suffix(name: &str, suffix: &str) -> bool {
let name = name.trim_end_matches(".");
let mut suffix = suffix.trim_end_matches(".");
suffix = suffix.trim_start_matches(".");
let name = name.trim_end_matches('.');
let mut suffix = suffix.trim_end_matches('.');
suffix = suffix.trim_start_matches('.');
let name_base = name.trim_end_matches(suffix);
name_base.len() < name.len() && name_base.ends_with(".")
name_base.len() < name.len() && name_base.ends_with('.')
}

fn trim_suffix(name: &str, suffix: &str) -> String {
let mut new_name = name;
if has_suffix(name, &suffix) {
new_name = new_name.trim_end_matches(".");
let suffix = suffix.trim_start_matches(".").trim_end_matches(".");
if has_suffix(name, suffix) {
new_name = new_name.trim_end_matches('.');
let suffix = suffix.trim_start_matches('.').trim_end_matches('.');
new_name = new_name.trim_end_matches(suffix);
}
new_name.trim_end_matches(".").to_string()
new_name.trim_end_matches('.').to_string()
}

fn sanitize_hostname(hostname: &str) -> String {
Expand All @@ -132,13 +132,13 @@ fn sanitize_hostname(hostname: &str) -> String {
if chars.nth(start).unwrap().is_alphanumeric() {
break;
}
start = start + 1;
start += 1;
}
while start < end {
if chars.nth(end - 1).unwrap().is_alphanumeric() {
break;
}
end = end - 1;
end -= 1;
}
let seperators: HashMap<char, bool> =
HashMap::from([(' ', true), ('.', true), ('@', true), ('_', true)]);
Expand Down
3 changes: 1 addition & 2 deletions src/tray.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,7 @@ impl Tray for SysTray {
label: format!(
"This device: {} ({})",
self.ctx.status.this_machine.display_name, self.ctx.ip
)
.into(),
),
activate: Box::new(move |_| Self::copy_peer_ip(&my_ip, "This device")),
..Default::default()
}
Expand Down

0 comments on commit 9d71fca

Please sign in to comment.