Compare commits

..

No commits in common. "master" and "de2e6017f5ad0c6d3d6894d64b19c8da4dfe82d0" have entirely different histories.

11 changed files with 22 additions and 81 deletions

2
Cargo.lock generated
View File

@ -914,7 +914,7 @@ dependencies = [
[[package]]
name = "rsblocks"
version = "0.1.20"
version = "0.1.19"
dependencies = [
"alsa",
"async-std",

View File

@ -3,7 +3,6 @@ use std::default::Default;
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct CpuTemp {
pub path: String,
pub icon: String,
pub enabled: bool,
pub delay: f64,
@ -12,7 +11,6 @@ pub struct CpuTemp {
impl Default for CpuTemp {
fn default() -> Self {
CpuTemp {
path: String::from("/sys/class/thermal/thermal_zone0/temp"),
icon: String::from(""),
enabled: false,
delay: 120.0,

View File

@ -5,8 +5,6 @@ use std::default::Default;
pub struct LocalIp {
pub icon: String,
pub enabled: bool,
pub show4: bool,
pub show6: bool,
pub delay: f64,
pub interface: String,
}
@ -16,8 +14,6 @@ impl Default for LocalIp {
LocalIp {
icon: String::from(""),
enabled: false,
show4: true,
show6: false,
delay: 120.0,
interface: String::from("wlan0"),
}

View File

@ -5,7 +5,6 @@ use std::default::Default;
pub struct PubIp {
pub icon: String,
pub enabled: bool,
pub show6: bool,
pub delay: f64,
}
@ -14,7 +13,6 @@ impl Default for PubIp {
PubIp {
icon: String::from(""),
enabled: false,
show6: false,
delay: 120.0,
}
}

View File

@ -3,9 +3,7 @@ use std::default::Default;
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Volume {
pub icon_high: String,
pub icon_low: String,
pub icon_muted: String,
pub icon: String,
pub enabled: bool,
pub delay: f64,
pub card: String,
@ -14,9 +12,7 @@ pub struct Volume {
impl Default for Volume {
fn default() -> Self {
Volume {
icon_high: String::from("🕪"),
icon_low: String::from("🕩"),
icon_muted: String::from("🔇"),
icon: String::from(""),
enabled: false,
delay: 0.17,
card: String::from("ALSA"),

View File

@ -60,9 +60,7 @@ pub struct Disk {
}
#[derive(Clone)]
pub struct Volume {
pub icon_muted: String,
pub icon_high: String,
pub icon_low: String,
pub icon: String,
pub enabled: bool,
pub delay: f64,
pub card: String,
@ -86,7 +84,6 @@ pub struct Battery {
#[derive(Clone)]
pub struct CpuTemp {
pub path: String,
pub icon: String,
pub enabled: bool,
pub delay: f64,

View File

@ -4,7 +4,7 @@ use std::fs::read_to_string;
// getting cpu temperature
pub async fn get_cpu_temp() -> ThreadsData {
let buf = match read_to_string(&CONFIG.cpu_temperature.path) {
let buf = match read_to_string("/sys/class/thermal/thermal_zone0/temp") {
Ok(data) => data,
_ => return ThreadsData::CpuTemp(String::from("Error reading temp")),
};
@ -12,7 +12,7 @@ pub async fn get_cpu_temp() -> ThreadsData {
let value = buf.trim().parse::<f32>().unwrap();
let result = format!(
" {} {: <3.1}° {}",
" {} {}° {}",
CONFIG.cpu_temperature.icon,
value / 1000.0,
CONFIG.seperator

View File

@ -4,32 +4,14 @@ use crate::types::ThreadsData;
pub async fn get_local_ip() -> ThreadsData {
let addrs = nix::ifaddrs::getifaddrs().unwrap();
let mut ip = String::new();
let mut ip6 = String::new();
let mut found4 = !CONFIG.local_ip.show4;
let mut found6 = !CONFIG.local_ip.show4;
for ifaddr in addrs {
match ifaddr.address {
Some(address) => {
if found4 && found6 { break; }
if ifaddr.interface_name == CONFIG.local_ip.interface {
match address.family() {
nix::sys::socket::AddressFamily::Inet => {
if found4 { continue; }
ip = if CONFIG.local_ip.show4 {
address.to_string().split(':').next().unwrap().to_string()
} else {
String::from(" ")
};
found4 = true;
}
nix::sys::socket::AddressFamily::Inet6 => {
if found6 { continue; }
ip6 = if CONFIG.local_ip.show6 {
address.to_string().rsplit_once(':').unwrap().0.to_string()
} else {
String::from(" ")
};
found6 = true;
ip = address.to_string().split(':').next().unwrap().to_string();
break;
}
_ => continue,
};
@ -41,9 +23,6 @@ pub async fn get_local_ip() -> ThreadsData {
if ip.is_empty() {
ip = String::from("Error!")
}
if !ip6.is_empty() {
ip6 = format!(" {}", ip6)
}
let data = format!(" {} {}{} {}", CONFIG.local_ip.icon, ip, ip6, CONFIG.seperator);
let data = format!(" {} {} {}", CONFIG.local_ip.icon, ip, CONFIG.seperator);
ThreadsData::LocalIp(data)
}

View File

@ -19,7 +19,7 @@ pub async fn get_netspeed() -> ThreadsData {
let data = format!(
" {} {} {} {} {}",
rx, CONFIG.netspeed.recieve_icon, tx, CONFIG.netspeed.transmit_icon, CONFIG.seperator
CONFIG.netspeed.recieve_icon, rx, CONFIG.netspeed.transmit_icon, tx, CONFIG.seperator
);
ThreadsData::NetSpeed(data)
}
@ -36,12 +36,12 @@ fn parse_speed_file(pth: &str) -> u64 {
}
fn calculate(speed: u64) -> String {
let lookup = ["b", "kb", "Mb"];
let lookup = ["B", "kB", "MB"];
let mut speed = speed as f64;
let mut idx = 0;
while speed >= 1024.0 && idx < lookup.len() {
speed /= 1024.0;
idx += 1;
}
format!("{: >5.1}{: >2}", speed, lookup[idx])
format!("{:.1} {}", speed, lookup[idx])
}

View File

@ -2,28 +2,16 @@ use crate::config::CONFIG;
use crate::types::ThreadsData;
pub async fn get_pub_ip() -> ThreadsData {
let url4 = "http://api.ipify.org".to_string();
let url6 = "http://api64.ipify.org".to_string();
let _err4 = String::from("Error4");
let res4 = match minreq::get(url4).send() {
let url = "http://api.ipify.org".to_string();
let _err = String::from("Error");
let res = match minreq::get(url).send() {
Ok(resp) => match resp.as_str() {
Ok(res_str) => res_str.trim().to_string(),
Err(_) => _err4,
Err(_) => _err,
},
Err(_) => _err4,
Err(_) => _err,
};
let _err6 = String::from("Error6");
let mut res6 = String::from("");
if CONFIG.pub_ip.show6 {
res6 = match minreq::get(url6).send() {
Ok(resp) => match resp.as_str() {
Ok(res_str) => format!("[{}]", res_str.trim().to_string()),
Err(_) => _err6,
},
Err(_) => _err6,
}
}
let data = format!(" {} {} {} {}", CONFIG.pub_ip.icon, res4, res6, CONFIG.seperator);
let data = format!(" {} {} {}", CONFIG.pub_ip.icon, res, CONFIG.seperator);
ThreadsData::PubIp(data)
}

View File

@ -20,25 +20,14 @@ pub async fn get_volume() -> ThreadsData {
.get_playback_volume(selem_chan_id)
.expect("Failed to get raw_volume");
let muted = selem
.get_playback_switch(selem_chan_id)
.expect("Failed to get playback state")
== 0;
let range = max - min;
let vol = if muted || range == 0 {
let vol = if range == 0 {
0
} else {
raw_volume -= min;
((raw_volume as f64 / range as f64) * 100.) as u64
};
let icon = match muted {
true => &CONFIG.volume.icon_muted,
false => if vol < 50 { &CONFIG.volume.icon_low } else { &CONFIG.volume.icon_high }
};
let data = format!(" {} {:>2}% {}", icon, vol, CONFIG.seperator);
let data = format!(" {} {}% {}", CONFIG.volume.icon, vol, CONFIG.seperator);
ThreadsData::Sound(data)
}