chore: clippy & fmt

This commit is contained in:
neoarz
2026-01-07 22:35:41 -05:00
parent ef666c53e5
commit fd7da43393
16 changed files with 322 additions and 284 deletions

View File

@@ -45,19 +45,19 @@ pub fn get_battery_info() -> (String, String) {
let value = value_part.trim_matches(';').trim();
is_charging = value == "Yes";
}
} else if line.contains("\"AvgTimeToEmpty\"") {
if let Some(equals_pos) = line.find('=') {
let value_part = &line[equals_pos + 1..].trim();
let value = value_part.trim_matches(';').trim();
if let Ok(time) = value.parse::<i32>() {
avg_time_to_empty = Some(time);
}
} else if line.contains("\"AvgTimeToEmpty\"")
&& let Some(equals_pos) = line.find('=')
{
let value_part = &line[equals_pos + 1..].trim();
let value = value_part.trim_matches(';').trim();
if let Ok(time) = value.parse::<i32>() {
avg_time_to_empty = Some(time);
}
}
}
let percentage = if let Some(capacity) = current_capacity {
if capacity >= 0 && capacity <= 100 {
if (0..=100).contains(&capacity) {
capacity as u32
} else {
return (format!("({})", device_name), "<unknown>".to_string());
@@ -76,20 +76,21 @@ pub fn get_battery_info() -> (String, String) {
let mut result = crate::output::colors::battery_percent(percentage);
if !external_connected && !is_charging {
if let Some(time_mins) = avg_time_to_empty {
if time_mins > 0 && time_mins < 0xFFFF {
let hours = time_mins / 60;
let mins = time_mins % 60;
if !external_connected
&& !is_charging
&& let Some(time_mins) = avg_time_to_empty
&& time_mins > 0
&& time_mins < 0xFFFF
{
let hours = time_mins / 60;
let mins = time_mins % 60;
if hours > 0 && mins > 0 {
result.push_str(&format!(" ({} hours, {} mins remaining)", hours, mins));
} else if hours > 0 {
result.push_str(&format!(" ({} hours remaining)", hours));
} else if mins > 0 {
result.push_str(&format!(" ({} mins remaining)", mins));
}
}
if hours > 0 && mins > 0 {
result.push_str(&format!(" ({} hours, {} mins remaining)", hours, mins));
} else if hours > 0 {
result.push_str(&format!(" ({} hours remaining)", hours));
} else if mins > 0 {
result.push_str(&format!(" ({} mins remaining)", mins));
}
}
@@ -97,4 +98,3 @@ pub fn get_battery_info() -> (String, String) {
(format!("({})", device_name), result)
}

View File

@@ -12,45 +12,53 @@ pub fn get_cursor_info() -> String {
let mut outline = "White".to_string();
let mut size = "32".to_string();
if let Ok(value) = Value::from_file(path) {
if let Some(dict) = value.as_dictionary() {
if let Some(f_dict) = dict.get("cursorFill").and_then(|v| v.as_dictionary()) {
let r = (f_dict.get("red").and_then(|v| v.as_real()).unwrap_or(0.0) * 255.0 + 0.5) as u32;
let g = (f_dict.get("green").and_then(|v| v.as_real()).unwrap_or(0.0) * 255.0 + 0.5) as u32;
let b = (f_dict.get("blue").and_then(|v| v.as_real()).unwrap_or(0.0) * 255.0 + 0.5) as u32;
let a = (f_dict.get("alpha").and_then(|v| v.as_real()).unwrap_or(1.0) * 255.0 + 0.5) as u32;
let color_hex = (r << 24) | (g << 16) | (b << 8) | a;
fill = match color_hex {
0x000000FF => "Black".to_string(),
0xFFFFFFFF => "White".to_string(),
0xFF2600FF => "Red".to_string(),
0x0433FFFF => "Blue".to_string(),
0x00F900FF => "Green".to_string(),
0xFFFB00FF => "Yellow".to_string(),
_ => format!("#{:08X}", color_hex),
};
}
if let Ok(value) = Value::from_file(path)
&& let Some(dict) = value.as_dictionary()
{
if let Some(f_dict) = dict.get("cursorFill").and_then(|v| v.as_dictionary()) {
let r =
(f_dict.get("red").and_then(|v| v.as_real()).unwrap_or(0.0) * 255.0 + 0.5) as u32;
let g =
(f_dict.get("green").and_then(|v| v.as_real()).unwrap_or(0.0) * 255.0 + 0.5) as u32;
let b =
(f_dict.get("blue").and_then(|v| v.as_real()).unwrap_or(0.0) * 255.0 + 0.5) as u32;
let a =
(f_dict.get("alpha").and_then(|v| v.as_real()).unwrap_or(1.0) * 255.0 + 0.5) as u32;
let color_hex = (r << 24) | (g << 16) | (b << 8) | a;
fill = match color_hex {
0x000000FF => "Black".to_string(),
0xFFFFFFFF => "White".to_string(),
0xFF2600FF => "Red".to_string(),
0x0433FFFF => "Blue".to_string(),
0x00F900FF => "Green".to_string(),
0xFFFB00FF => "Yellow".to_string(),
_ => format!("#{:08X}", color_hex),
};
}
if let Some(o_dict) = dict.get("cursorOutline").and_then(|v| v.as_dictionary()) {
let r = (o_dict.get("red").and_then(|v| v.as_real()).unwrap_or(0.0) * 255.0 + 0.5) as u32;
let g = (o_dict.get("green").and_then(|v| v.as_real()).unwrap_or(0.0) * 255.0 + 0.5) as u32;
let b = (o_dict.get("blue").and_then(|v| v.as_real()).unwrap_or(0.0) * 255.0 + 0.5) as u32;
let a = (o_dict.get("alpha").and_then(|v| v.as_real()).unwrap_or(1.0) * 255.0 + 0.5) as u32;
let color_hex = (r << 24) | (g << 16) | (b << 8) | a;
outline = match color_hex {
0x000000FF => "Black".to_string(),
0xFFFFFFFF => "White".to_string(),
0xFF2600FF => "Red".to_string(),
0x0433FFFF => "Blue".to_string(),
0x00F900FF => "Green".to_string(),
0xFFFB00FF => "Yellow".to_string(),
_ => format!("#{:08X}", color_hex),
};
}
if let Some(o_dict) = dict.get("cursorOutline").and_then(|v| v.as_dictionary()) {
let r =
(o_dict.get("red").and_then(|v| v.as_real()).unwrap_or(0.0) * 255.0 + 0.5) as u32;
let g =
(o_dict.get("green").and_then(|v| v.as_real()).unwrap_or(0.0) * 255.0 + 0.5) as u32;
let b =
(o_dict.get("blue").and_then(|v| v.as_real()).unwrap_or(0.0) * 255.0 + 0.5) as u32;
let a =
(o_dict.get("alpha").and_then(|v| v.as_real()).unwrap_or(1.0) * 255.0 + 0.5) as u32;
let color_hex = (r << 24) | (g << 16) | (b << 8) | a;
outline = match color_hex {
0x000000FF => "Black".to_string(),
0xFFFFFFFF => "White".to_string(),
0xFF2600FF => "Red".to_string(),
0x0433FFFF => "Blue".to_string(),
0x00F900FF => "Green".to_string(),
0xFFFB00FF => "Yellow".to_string(),
_ => format!("#{:08X}", color_hex),
};
}
if let Some(s_val) = dict.get("mouseDriverCursorSize").and_then(|v| v.as_real()) {
size = format!("{:.0}", s_val * 32.0);
}
if let Some(s_val) = dict.get("mouseDriverCursorSize").and_then(|v| v.as_real()) {
size = format!("{:.0}", s_val * 32.0);
}
}

View File

@@ -18,10 +18,20 @@ pub fn get_display_info() -> String {
};
if display_count > 1 {
let name = if main.name.is_empty() { "Color LCD" } else { &main.name };
let name = if main.name.is_empty() {
"Color LCD"
} else {
&main.name
};
format!(
"({}) {}x{} @ {}x in {}\", {} Hz {}",
name, p_width, p_height, main.scale_factor as u32, inches, main.frequency as u32, tag
name,
p_width,
p_height,
main.scale_factor as u32,
inches,
main.frequency as u32,
tag
)
} else {
format!(

View File

@@ -20,9 +20,7 @@ pub fn get_gpu_info() -> String {
.nth(1)
.unwrap_or("")
.trim()
.replace('"', "")
.replace('<', "")
.replace('>', "");
.replace(['"', '<', '>'], "");
}
if line.contains("\"gpu-core-count\"") {
cores = line.split('=').nth(1).unwrap_or("").trim().to_string();

View File

@@ -11,13 +11,16 @@ pub fn get_host_info() -> String {
}
fn model_to_name(model: &str) -> Option<String> {
let version = if model.starts_with("Mac") && !model.starts_with("MacBook") && !model.starts_with("Macmini") && !model.starts_with("MacPro") {
let version = if model.starts_with("Mac")
&& !model.starts_with("MacBook")
&& !model.starts_with("Macmini")
&& !model.starts_with("MacPro")
{
Some(model.strip_prefix("Mac")?)
} else {
None
};
// Database stolen from https://github.com/fastfetch-cli/fastfetch/blob/dev/src/detection/host/host_mac.c
// Macbook Pro: https://support.apple.com/en-us/HT201300
// Macbook Air: https://support.apple.com/en-us/HT201862
@@ -26,80 +29,86 @@ fn model_to_name(model: &str) -> Option<String> {
// Mac Pro: https://support.apple.com/en-us/HT202888
// Mac Studio: https://support.apple.com/en-us/HT213073
if let Some(v) = version {
return Some(match v {
// MacBook Air
"16,13" => "MacBook Air (15-inch, M4, 2025)",
"16,12" => "MacBook Air (13-inch, M4, 2025)",
"15,13" => "MacBook Air (15-inch, M3, 2024)",
"15,12" => "MacBook Air (13-inch, M3, 2024)",
"14,15" => "MacBook Air (15-inch, M2, 2023)",
"14,2" => "MacBook Air (M2, 2022)",
// MacBook Pro
"16,8" => "MacBook Pro (16-inch, M4 Max, 2024)",
"16,7" => "MacBook Pro (16-inch, M4 Pro, 2024)",
"16,6" => "MacBook Pro (14-inch, M4 Max, 2024)",
"16,5" => "MacBook Pro (14-inch, M4 Pro, 2024)",
"16,1" => "MacBook Pro (14-inch, M4, 2024)",
"15,11" => "MacBook Pro (16-inch, M3 Max, 2023)",
"15,9" => "MacBook Pro (16-inch, M3 Pro, 2023)",
"15,10" => "MacBook Pro (14-inch, M3 Max, 2023)",
"15,8" => "MacBook Pro (14-inch, M3 Pro, 2023)",
"15,6" | "15,7" => "MacBook Pro (16-inch, M2 Max, 2023)",
"15,3" => "MacBook Pro (14-inch, M2 Max, 2023)",
"14,10" | "14,6" => "MacBook Pro (16-inch, M2 Pro/Max, 2023)",
"14,9" | "14,5" => "MacBook Pro (14-inch, M2 Pro/Max, 2023)",
"14,7" => "MacBook Pro (13-inch, M2, 2022)",
// Mac Studio
"14,14" => "Mac Studio (M2 Ultra, 2023)",
"14,13" => "Mac Studio (M2 Max, 2023)",
"13,2" => "Mac Studio (M1 Ultra, 2022)",
"13,1" => "Mac Studio (M1 Max, 2022)",
// Mac mini
"16,10" => "Mac mini (M4, 2024)",
"16,3" => "Mac mini (M4 Pro, 2024)",
"14,12" => "Mac mini (M2 Pro, 2023)",
"14,3" => "Mac mini (M2, 2023)",
// Mac Pro
"14,8" => "Mac Pro (M2 Ultra, 2023)",
// iMac
"16,2" => "iMac (24-inch, M4, 2024)",
"15,4" | "15,5" => "iMac (24-inch, M3, 2023)",
_ => return None,
}.to_string());
return Some(
match v {
// MacBook Air
"16,13" => "MacBook Air (15-inch, M4, 2025)",
"16,12" => "MacBook Air (13-inch, M4, 2025)",
"15,13" => "MacBook Air (15-inch, M3, 2024)",
"15,12" => "MacBook Air (13-inch, M3, 2024)",
"14,15" => "MacBook Air (15-inch, M2, 2023)",
"14,2" => "MacBook Air (M2, 2022)",
// MacBook Pro
"16,8" => "MacBook Pro (16-inch, M4 Max, 2024)",
"16,7" => "MacBook Pro (16-inch, M4 Pro, 2024)",
"16,6" => "MacBook Pro (14-inch, M4 Max, 2024)",
"16,5" => "MacBook Pro (14-inch, M4 Pro, 2024)",
"16,1" => "MacBook Pro (14-inch, M4, 2024)",
"15,11" => "MacBook Pro (16-inch, M3 Max, 2023)",
"15,9" => "MacBook Pro (16-inch, M3 Pro, 2023)",
"15,10" => "MacBook Pro (14-inch, M3 Max, 2023)",
"15,8" => "MacBook Pro (14-inch, M3 Pro, 2023)",
"15,6" | "15,7" => "MacBook Pro (16-inch, M2 Max, 2023)",
"15,3" => "MacBook Pro (14-inch, M2 Max, 2023)",
"14,10" | "14,6" => "MacBook Pro (16-inch, M2 Pro/Max, 2023)",
"14,9" | "14,5" => "MacBook Pro (14-inch, M2 Pro/Max, 2023)",
"14,7" => "MacBook Pro (13-inch, M2, 2022)",
// Mac Studio
"14,14" => "Mac Studio (M2 Ultra, 2023)",
"14,13" => "Mac Studio (M2 Max, 2023)",
"13,2" => "Mac Studio (M1 Ultra, 2022)",
"13,1" => "Mac Studio (M1 Max, 2022)",
// Mac mini
"16,10" => "Mac mini (M4, 2024)",
"16,3" => "Mac mini (M4 Pro, 2024)",
"14,12" => "Mac mini (M2 Pro, 2023)",
"14,3" => "Mac mini (M2, 2023)",
// Mac Pro
"14,8" => "Mac Pro (M2 Ultra, 2023)",
// iMac
"16,2" => "iMac (24-inch, M4, 2024)",
"15,4" | "15,5" => "iMac (24-inch, M3, 2023)",
_ => return None,
}
.to_string(),
);
}
// Older Macs with specific prefixes
Some(match model {
// MacBook Air (Intel/M1)
"MacBookAir10,1" => "MacBook Air (M1, 2020)",
"MacBookAir9,1" => "MacBook Air (Retina, 13-inch, 2020)",
"MacBookAir8,2" => "MacBook Air (Retina, 13-inch, 2019)",
"MacBookAir8,1" => "MacBook Air (Retina, 13-inch, 2018)",
// MacBook Pro (Intel/M1)
"MacBookPro18,4" => "MacBook Pro (14-inch, M1 Max, 2021)",
"MacBookPro18,3" => "MacBook Pro (14-inch, M1 Pro, 2021)",
"MacBookPro18,2" => "MacBook Pro (16-inch, M1 Max, 2021)",
"MacBookPro18,1" => "MacBook Pro (16-inch, M1 Pro, 2021)",
"MacBookPro17,1" => "MacBook Pro (13-inch, M1, 2020)",
"MacBookPro16,4" => "MacBook Pro (16-inch, 2019)",
"MacBookPro16,3" => "MacBook Pro (13-inch, 2020, Two Thunderbolt 3 ports)",
"MacBookPro16,2" => "MacBook Pro (13-inch, 2020, Four Thunderbolt 3 ports)",
"MacBookPro16,1" => "MacBook Pro (16-inch, 2019)",
"MacBookPro15,4" => "MacBook Pro (13-inch, 2019, Two Thunderbolt 3 ports)",
"MacBookPro15,3" => "MacBook Pro (15-inch, 2019)",
"MacBookPro15,2" => "MacBook Pro (13-inch, 2018/2019, Four Thunderbolt 3 ports)",
"MacBookPro15,1" => "MacBook Pro (15-inch, 2018/2019)",
// Mac mini
"Macmini9,1" => "Mac mini (M1, 2020)",
"Macmini8,1" => "Mac mini (2018)",
// iMac
"iMac21,2" | "iMac21,1" => "iMac (24-inch, M1, 2021)",
"iMac20,2" | "iMac20,1" => "iMac (Retina 5K, 27-inch, 2020)",
"iMac19,2" => "iMac (Retina 4K, 21.5-inch, 2019)",
"iMac19,1" => "iMac (Retina 5K, 27-inch, 2019)",
// Mac Pro
"MacPro7,1" => "Mac Pro (2019)",
"MacPro6,1" => "Mac Pro (Late 2013)",
_ => return None,
}.to_string())
Some(
match model {
// MacBook Air (Intel/M1)
"MacBookAir10,1" => "MacBook Air (M1, 2020)",
"MacBookAir9,1" => "MacBook Air (Retina, 13-inch, 2020)",
"MacBookAir8,2" => "MacBook Air (Retina, 13-inch, 2019)",
"MacBookAir8,1" => "MacBook Air (Retina, 13-inch, 2018)",
// MacBook Pro (Intel/M1)
"MacBookPro18,4" => "MacBook Pro (14-inch, M1 Max, 2021)",
"MacBookPro18,3" => "MacBook Pro (14-inch, M1 Pro, 2021)",
"MacBookPro18,2" => "MacBook Pro (16-inch, M1 Max, 2021)",
"MacBookPro18,1" => "MacBook Pro (16-inch, M1 Pro, 2021)",
"MacBookPro17,1" => "MacBook Pro (13-inch, M1, 2020)",
"MacBookPro16,4" => "MacBook Pro (16-inch, 2019)",
"MacBookPro16,3" => "MacBook Pro (13-inch, 2020, Two Thunderbolt 3 ports)",
"MacBookPro16,2" => "MacBook Pro (13-inch, 2020, Four Thunderbolt 3 ports)",
"MacBookPro16,1" => "MacBook Pro (16-inch, 2019)",
"MacBookPro15,4" => "MacBook Pro (13-inch, 2019, Two Thunderbolt 3 ports)",
"MacBookPro15,3" => "MacBook Pro (15-inch, 2019)",
"MacBookPro15,2" => "MacBook Pro (13-inch, 2018/2019, Four Thunderbolt 3 ports)",
"MacBookPro15,1" => "MacBook Pro (15-inch, 2018/2019)",
// Mac mini
"Macmini9,1" => "Mac mini (M1, 2020)",
"Macmini8,1" => "Mac mini (2018)",
// iMac
"iMac21,2" | "iMac21,1" => "iMac (24-inch, M1, 2021)",
"iMac20,2" | "iMac20,1" => "iMac (Retina 5K, 27-inch, 2020)",
"iMac19,2" => "iMac (Retina 4K, 21.5-inch, 2019)",
"iMac19,1" => "iMac (Retina 5K, 27-inch, 2019)",
// Mac Pro
"MacPro7,1" => "Mac Pro (2019)",
"MacPro6,1" => "Mac Pro (Late 2013)",
_ => return None,
}
.to_string(),
)
}

View File

@@ -3,25 +3,21 @@ use std::process::Command;
pub fn get_ip_info() -> String {
let mut interface = "en0".to_string();
let route_output = Command::new("route")
.args(["get", "default"])
.output();
let route_output = Command::new("route").args(["get", "default"]).output();
if let Ok(output) = route_output {
let stdout = String::from_utf8_lossy(&output.stdout);
for line in stdout.lines() {
if line.trim().starts_with("interface:") {
if let Some(iface) = line.split_whitespace().nth(1) {
interface = iface.to_string();
break;
}
if line.trim().starts_with("interface:")
&& let Some(iface) = line.split_whitespace().nth(1)
{
interface = iface.to_string();
break;
}
}
}
let ifconfig_output = Command::new("ifconfig")
.arg(&interface)
.output();
let ifconfig_output = Command::new("ifconfig").arg(&interface).output();
if let Ok(output) = ifconfig_output {
let stdout = String::from_utf8_lossy(&output.stdout);
@@ -32,15 +28,15 @@ pub fn get_ip_info() -> String {
let ip = parts[1];
let mut ip_with_cidr = ip.to_string();
if let Some(netmask_idx) = parts.iter().position(|&x| x == "netmask") {
if netmask_idx + 1 < parts.len() {
let netmask_hex = parts[netmask_idx + 1];
if netmask_hex.starts_with("0x") {
if let Ok(num) = u32::from_str_radix(&netmask_hex[2..], 16) {
let cidr = num.count_ones();
ip_with_cidr = format!("{}/{}", ip, cidr);
}
}
if let Some(netmask_idx) = parts.iter().position(|&x| x == "netmask")
&& netmask_idx + 1 < parts.len()
{
let netmask_hex = parts[netmask_idx + 1];
if netmask_hex.starts_with("0x")
&& let Ok(num) = u32::from_str_radix(&netmask_hex[2..], 16)
{
let cidr = num.count_ones();
ip_with_cidr = format!("{}/{}", ip, cidr);
}
}
@@ -52,4 +48,3 @@ pub fn get_ip_info() -> String {
"<unknown>".to_string()
}

View File

@@ -1,18 +1,17 @@
use std::env;
pub fn get_locale_info() -> String {
if let Ok(locale) = env::var("LC_ALL") {
if !locale.is_empty() {
return locale;
}
if let Ok(locale) = env::var("LC_ALL")
&& !locale.is_empty()
{
return locale;
}
if let Ok(locale) = env::var("LANG") {
if !locale.is_empty() {
return locale;
}
if let Ok(locale) = env::var("LANG")
&& !locale.is_empty()
{
return locale;
}
"<unknown>".to_string()
}

View File

@@ -74,6 +74,8 @@ pub fn get_memory_info() -> String {
format!(
"{:.2} GiB / {:.2} GiB ({})",
used_gib, total_gib, crate::output::colors::percent(percentage)
used_gib,
total_gib,
crate::output::colors::percent(percentage)
)
}

View File

@@ -3,8 +3,9 @@ use std::process::Command;
pub fn get_shell_info() -> String {
let shell_path = env::var("SHELL").unwrap_or_else(|_| "unknown".to_string());
let shell_name = shell_path.split('/').last().unwrap_or("unknown");
let version = Command::new(&shell_path)
let shell_name = shell_path.split('/').next_back().unwrap_or("unknown");
Command::new(&shell_path)
.arg("--version")
.output()
.map(|output| {
@@ -16,7 +17,5 @@ pub fn get_shell_info() -> String {
.collect::<Vec<_>>()
.join(" ")
})
.unwrap_or_else(|_| shell_name.to_string());
version
.unwrap_or_else(|_| shell_name.to_string())
}

View File

@@ -1,6 +1,6 @@
// https://github.com/fastfetch-cli/fastfetch/blob/dev/src/detection/disk/disk.c
use libc::{c_int, c_char};
use libc::{c_char, c_int};
use std::ffi::CStr;
#[repr(C)]
@@ -79,7 +79,9 @@ pub fn get_storage_info() -> String {
let mut result = format!(
"{:.2} GiB / {:.2} GiB ({})",
used_gib, total_gib, crate::output::colors::percent(percentage)
used_gib,
total_gib,
crate::output::colors::percent(percentage)
);
if !filesystem.is_empty() {
@@ -97,4 +99,3 @@ pub fn get_storage_info() -> String {
"<unknown>".to_string()
}

View File

@@ -12,13 +12,13 @@ pub fn get_swap_info() -> String {
let mut used_mb = 0.0;
for part in stdout.split_whitespace() {
if let Some(val) = part.strip_suffix('M') {
if let Ok(num) = val.parse::<f64>() {
if stdout.contains(&format!("total = {}", part)) {
total_mb = num;
} else if stdout.contains(&format!("used = {}", part)) {
used_mb = num;
}
if let Some(val) = part.strip_suffix('M')
&& let Ok(num) = val.parse::<f64>()
{
if stdout.contains(&format!("total = {}", part)) {
total_mb = num;
} else if stdout.contains(&format!("used = {}", part)) {
used_mb = num;
}
}
}
@@ -33,7 +33,9 @@ pub fn get_swap_info() -> String {
return format!(
"{:.2} GiB / {:.2} GiB ({})",
used_gib, total_gib, crate::output::colors::percent(percentage)
used_gib,
total_gib,
crate::output::colors::percent(percentage)
);
}

View File

@@ -26,12 +26,11 @@ pub fn get_terminal_info() -> String {
let my_pid = sysinfo::get_current_pid().unwrap_or(sysinfo::Pid::from(0));
if let Some(process) = sys.process(my_pid) {
if let Some(parent_pid) = process.parent() {
if let Some(parent_proc) = sys.process(parent_pid) {
return parent_proc.name().to_string_lossy().replace(".app", "");
}
}
if let Some(process) = sys.process(my_pid)
&& let Some(parent_pid) = process.parent()
&& let Some(parent_proc) = sys.process(parent_pid)
{
return parent_proc.name().to_string_lossy().replace(".app", "");
}
"unknown".to_string()

View File

@@ -15,30 +15,25 @@ pub fn get_window_manager_info() -> DisplayServerResult {
if cfg!(target_os = "macos") {
let plist_path = "/System/Library/CoreServices/WindowManager.app/Contents/version.plist";
if Path::new(plist_path).exists() {
if let Ok(value) = Value::from_file(plist_path) {
if let Some(dict) = value.as_dictionary() {
if let Some(raw_version) = dict.get("SourceVersion").and_then(|v| v.as_string())
{
// Apple format: AAAABBBCCDDDDDD (Major, Minor, Patch, Build)
if raw_version.len() >= 8 && raw_version.chars().all(|c| c.is_numeric()) {
let major =
raw_version[..raw_version.len() - 12].trim_start_matches('0');
let minor = raw_version[raw_version.len() - 12..raw_version.len() - 9]
.trim_start_matches('0');
let patch = raw_version[raw_version.len() - 9..raw_version.len() - 7]
.trim_start_matches('0');
if Path::new(plist_path).exists()
&& let Ok(value) = Value::from_file(plist_path)
&& let Some(dict) = value.as_dictionary()
&& let Some(raw_version) = dict.get("SourceVersion").and_then(|v| v.as_string())
{
// Apple format: AAAABBBCCDDDDDD (Major, Minor, Patch, Build)
if raw_version.len() >= 8 && raw_version.chars().all(|c| c.is_numeric()) {
let major = raw_version[..raw_version.len() - 12].trim_start_matches('0');
let minor = raw_version[raw_version.len() - 12..raw_version.len() - 9]
.trim_start_matches('0');
let patch = raw_version[raw_version.len() - 9..raw_version.len() - 7]
.trim_start_matches('0');
let m = if minor.is_empty() { "0" } else { minor };
let p = if patch.is_empty() { "0" } else { patch };
let m = if minor.is_empty() { "0" } else { minor };
let p = if patch.is_empty() { "0" } else { patch };
result.wm_pretty_name =
format!("Quartz Compositor {}.{}.{}", major, m, p);
} else {
result.wm_pretty_name = format!("Quartz Compositor {}", raw_version);
}
}
}
result.wm_pretty_name = format!("Quartz Compositor {}.{}.{}", major, m, p);
} else {
result.wm_pretty_name = format!("Quartz Compositor {}", raw_version);
}
}
}

View File

@@ -11,28 +11,28 @@ pub fn get_wm_theme_info() -> String {
let mut accent_name = "Multicolor".to_string();
let mut appearance = "Light".to_string();
if let Ok(value) = Value::from_file(path) {
if let Some(dict) = value.as_dictionary() {
if let Some(accent_val) = dict
.get("AppleAccentColor")
.and_then(|v| v.as_signed_integer())
{
accent_name = match accent_val {
-1 => "Graphite".to_string(),
0 => "Red".to_string(),
1 => "Orange".to_string(),
2 => "Yellow".to_string(),
3 => "Green".to_string(),
4 => "Blue".to_string(),
5 => "Purple".to_string(),
6 => "Pink".to_string(),
_ => "Multicolor".to_string(),
};
}
if let Ok(value) = Value::from_file(path)
&& let Some(dict) = value.as_dictionary()
{
if let Some(accent_val) = dict
.get("AppleAccentColor")
.and_then(|v| v.as_signed_integer())
{
accent_name = match accent_val {
-1 => "Graphite".to_string(),
0 => "Red".to_string(),
1 => "Orange".to_string(),
2 => "Yellow".to_string(),
3 => "Green".to_string(),
4 => "Blue".to_string(),
5 => "Purple".to_string(),
6 => "Pink".to_string(),
_ => "Multicolor".to_string(),
};
}
if let Some(style) = dict.get("AppleInterfaceStyle").and_then(|v| v.as_string()) {
appearance = style.to_string(); // Usually "Dark"
}
if let Some(style) = dict.get("AppleInterfaceStyle").and_then(|v| v.as_string()) {
appearance = style.to_string(); // Usually "Dark"
}
}