Compare commits
No commits in common. "master" and "de2e6017f5ad0c6d3d6894d64b19c8da4dfe82d0" have entirely different histories.
master
...
de2e6017f5
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -914,7 +914,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rsblocks"
|
name = "rsblocks"
|
||||||
version = "0.1.20"
|
version = "0.1.19"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"alsa",
|
"alsa",
|
||||||
"async-std",
|
"async-std",
|
||||||
|
@ -3,7 +3,6 @@ use std::default::Default;
|
|||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||||
pub struct CpuTemp {
|
pub struct CpuTemp {
|
||||||
pub path: String,
|
|
||||||
pub icon: String,
|
pub icon: String,
|
||||||
pub enabled: bool,
|
pub enabled: bool,
|
||||||
pub delay: f64,
|
pub delay: f64,
|
||||||
@ -12,7 +11,6 @@ pub struct CpuTemp {
|
|||||||
impl Default for CpuTemp {
|
impl Default for CpuTemp {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
CpuTemp {
|
CpuTemp {
|
||||||
path: String::from("/sys/class/thermal/thermal_zone0/temp"),
|
|
||||||
icon: String::from(""),
|
icon: String::from(""),
|
||||||
enabled: false,
|
enabled: false,
|
||||||
delay: 120.0,
|
delay: 120.0,
|
||||||
|
@ -5,8 +5,6 @@ use std::default::Default;
|
|||||||
pub struct LocalIp {
|
pub struct LocalIp {
|
||||||
pub icon: String,
|
pub icon: String,
|
||||||
pub enabled: bool,
|
pub enabled: bool,
|
||||||
pub show4: bool,
|
|
||||||
pub show6: bool,
|
|
||||||
pub delay: f64,
|
pub delay: f64,
|
||||||
pub interface: String,
|
pub interface: String,
|
||||||
}
|
}
|
||||||
@ -16,8 +14,6 @@ impl Default for LocalIp {
|
|||||||
LocalIp {
|
LocalIp {
|
||||||
icon: String::from(""),
|
icon: String::from(""),
|
||||||
enabled: false,
|
enabled: false,
|
||||||
show4: true,
|
|
||||||
show6: false,
|
|
||||||
delay: 120.0,
|
delay: 120.0,
|
||||||
interface: String::from("wlan0"),
|
interface: String::from("wlan0"),
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,6 @@ use std::default::Default;
|
|||||||
pub struct PubIp {
|
pub struct PubIp {
|
||||||
pub icon: String,
|
pub icon: String,
|
||||||
pub enabled: bool,
|
pub enabled: bool,
|
||||||
pub show6: bool,
|
|
||||||
pub delay: f64,
|
pub delay: f64,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -14,7 +13,6 @@ impl Default for PubIp {
|
|||||||
PubIp {
|
PubIp {
|
||||||
icon: String::from(""),
|
icon: String::from(""),
|
||||||
enabled: false,
|
enabled: false,
|
||||||
show6: false,
|
|
||||||
delay: 120.0,
|
delay: 120.0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,9 +3,7 @@ use std::default::Default;
|
|||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||||
pub struct Volume {
|
pub struct Volume {
|
||||||
pub icon_high: String,
|
pub icon: String,
|
||||||
pub icon_low: String,
|
|
||||||
pub icon_muted: String,
|
|
||||||
pub enabled: bool,
|
pub enabled: bool,
|
||||||
pub delay: f64,
|
pub delay: f64,
|
||||||
pub card: String,
|
pub card: String,
|
||||||
@ -14,9 +12,7 @@ pub struct Volume {
|
|||||||
impl Default for Volume {
|
impl Default for Volume {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Volume {
|
Volume {
|
||||||
icon_high: String::from("🕪"),
|
icon: String::from(""),
|
||||||
icon_low: String::from("🕩"),
|
|
||||||
icon_muted: String::from("🔇"),
|
|
||||||
enabled: false,
|
enabled: false,
|
||||||
delay: 0.17,
|
delay: 0.17,
|
||||||
card: String::from("ALSA"),
|
card: String::from("ALSA"),
|
||||||
|
@ -60,9 +60,7 @@ pub struct Disk {
|
|||||||
}
|
}
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Volume {
|
pub struct Volume {
|
||||||
pub icon_muted: String,
|
pub icon: String,
|
||||||
pub icon_high: String,
|
|
||||||
pub icon_low: String,
|
|
||||||
pub enabled: bool,
|
pub enabled: bool,
|
||||||
pub delay: f64,
|
pub delay: f64,
|
||||||
pub card: String,
|
pub card: String,
|
||||||
@ -86,7 +84,6 @@ pub struct Battery {
|
|||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct CpuTemp {
|
pub struct CpuTemp {
|
||||||
pub path: String,
|
|
||||||
pub icon: String,
|
pub icon: String,
|
||||||
pub enabled: bool,
|
pub enabled: bool,
|
||||||
pub delay: f64,
|
pub delay: f64,
|
||||||
|
@ -4,7 +4,7 @@ use std::fs::read_to_string;
|
|||||||
|
|
||||||
// getting cpu temperature
|
// getting cpu temperature
|
||||||
pub async fn get_cpu_temp() -> ThreadsData {
|
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,
|
Ok(data) => data,
|
||||||
_ => return ThreadsData::CpuTemp(String::from("Error reading temp")),
|
_ => 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 value = buf.trim().parse::<f32>().unwrap();
|
||||||
|
|
||||||
let result = format!(
|
let result = format!(
|
||||||
" {} {: <3.1}° {}",
|
" {} {}° {}",
|
||||||
CONFIG.cpu_temperature.icon,
|
CONFIG.cpu_temperature.icon,
|
||||||
value / 1000.0,
|
value / 1000.0,
|
||||||
CONFIG.seperator
|
CONFIG.seperator
|
||||||
|
@ -3,33 +3,15 @@ use crate::types::ThreadsData;
|
|||||||
|
|
||||||
pub async fn get_local_ip() -> ThreadsData {
|
pub async fn get_local_ip() -> ThreadsData {
|
||||||
let addrs = nix::ifaddrs::getifaddrs().unwrap();
|
let addrs = nix::ifaddrs::getifaddrs().unwrap();
|
||||||
let mut ip = String::new();
|
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 {
|
for ifaddr in addrs {
|
||||||
match ifaddr.address {
|
match ifaddr.address {
|
||||||
Some(address) => {
|
Some(address) => {
|
||||||
if found4 && found6 { break; }
|
|
||||||
if ifaddr.interface_name == CONFIG.local_ip.interface {
|
if ifaddr.interface_name == CONFIG.local_ip.interface {
|
||||||
match address.family() {
|
match address.family() {
|
||||||
nix::sys::socket::AddressFamily::Inet => {
|
nix::sys::socket::AddressFamily::Inet => {
|
||||||
if found4 { continue; }
|
ip = address.to_string().split(':').next().unwrap().to_string();
|
||||||
ip = if CONFIG.local_ip.show4 {
|
break;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
_ => continue,
|
_ => continue,
|
||||||
};
|
};
|
||||||
@ -41,9 +23,6 @@ pub async fn get_local_ip() -> ThreadsData {
|
|||||||
if ip.is_empty() {
|
if ip.is_empty() {
|
||||||
ip = String::from("Error!")
|
ip = String::from("Error!")
|
||||||
}
|
}
|
||||||
if !ip6.is_empty() {
|
let data = format!(" {} {} {}", CONFIG.local_ip.icon, ip, CONFIG.seperator);
|
||||||
ip6 = format!(" {}", ip6)
|
|
||||||
}
|
|
||||||
let data = format!(" {} {}{} {}", CONFIG.local_ip.icon, ip, ip6, CONFIG.seperator);
|
|
||||||
ThreadsData::LocalIp(data)
|
ThreadsData::LocalIp(data)
|
||||||
}
|
}
|
||||||
|
@ -18,8 +18,8 @@ pub async fn get_netspeed() -> ThreadsData {
|
|||||||
let rx = calculate(rx_bps);
|
let rx = calculate(rx_bps);
|
||||||
|
|
||||||
let data = format!(
|
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)
|
ThreadsData::NetSpeed(data)
|
||||||
}
|
}
|
||||||
@ -36,12 +36,12 @@ fn parse_speed_file(pth: &str) -> u64 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn calculate(speed: u64) -> String {
|
fn calculate(speed: u64) -> String {
|
||||||
let lookup = ["b", "kb", "Mb"];
|
let lookup = ["B", "kB", "MB"];
|
||||||
let mut speed = speed as f64;
|
let mut speed = speed as f64;
|
||||||
let mut idx = 0;
|
let mut idx = 0;
|
||||||
while speed >= 1024.0 && idx < lookup.len() {
|
while speed >= 1024.0 && idx < lookup.len() {
|
||||||
speed /= 1024.0;
|
speed /= 1024.0;
|
||||||
idx += 1;
|
idx += 1;
|
||||||
}
|
}
|
||||||
format!("{: >5.1}{: >2}", speed, lookup[idx])
|
format!("{:.1} {}", speed, lookup[idx])
|
||||||
}
|
}
|
||||||
|
@ -2,28 +2,16 @@ use crate::config::CONFIG;
|
|||||||
use crate::types::ThreadsData;
|
use crate::types::ThreadsData;
|
||||||
|
|
||||||
pub async fn get_pub_ip() -> ThreadsData {
|
pub async fn get_pub_ip() -> ThreadsData {
|
||||||
let url4 = "http://api.ipify.org".to_string();
|
let url = "http://api.ipify.org".to_string();
|
||||||
let url6 = "http://api64.ipify.org".to_string();
|
let _err = String::from("Error");
|
||||||
let _err4 = String::from("Error4");
|
let res = match minreq::get(url).send() {
|
||||||
let res4 = match minreq::get(url4).send() {
|
|
||||||
Ok(resp) => match resp.as_str() {
|
Ok(resp) => match resp.as_str() {
|
||||||
Ok(res_str) => res_str.trim().to_string(),
|
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)
|
ThreadsData::PubIp(data)
|
||||||
}
|
}
|
||||||
|
@ -20,25 +20,14 @@ pub async fn get_volume() -> ThreadsData {
|
|||||||
.get_playback_volume(selem_chan_id)
|
.get_playback_volume(selem_chan_id)
|
||||||
.expect("Failed to get raw_volume");
|
.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 range = max - min;
|
||||||
let vol = if muted || range == 0 {
|
let vol = if range == 0 {
|
||||||
0
|
0
|
||||||
} else {
|
} else {
|
||||||
raw_volume -= min;
|
raw_volume -= min;
|
||||||
((raw_volume as f64 / range as f64) * 100.) as u64
|
((raw_volume as f64 / range as f64) * 100.) as u64
|
||||||
};
|
};
|
||||||
|
|
||||||
let icon = match muted {
|
let data = format!(" {} {}% {}", CONFIG.volume.icon, vol, CONFIG.seperator);
|
||||||
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);
|
|
||||||
ThreadsData::Sound(data)
|
ThreadsData::Sound(data)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user