Compare commits

..

No commits in common. "af71cc35793c6757c19c619226a62f46e3288a57" and "87a657fe81b60f2b0e8c6316fce371d6c33faa6c" have entirely different histories.

4 changed files with 17 additions and 46 deletions

View File

@ -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,
} }
} }

View File

@ -3,25 +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 = false;
let mut found6 = false;
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 = address.to_string().split(':').next().unwrap().to_string();
found4 = true; break;
}
nix::sys::socket::AddressFamily::Inet6 => {
if found6 { continue; }
ip6 = address.to_string().rsplit_once(':').unwrap().0.to_string();
found6 = true;
} }
_ => continue, _ => continue,
}; };
@ -33,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)
} }

View File

@ -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)
} }

View File

@ -20,25 +20,23 @@ 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 muted = selem
.get_playback_switch(selem_chan_id)
.expect("Failed to get playback state");
let icon = match muted { let icon = match muted {
true => &CONFIG.volume.icon_muted, 0 => &CONFIG.volume.icon_muted,
false => if vol < 50 { &CONFIG.volume.icon_low } else { &CONFIG.volume.icon_high } _ => if vol < 50 { &CONFIG.volume.icon_low } else { &CONFIG.volume.icon_high }
}; };
let data = format!(" {} {}% {}", icon, vol, CONFIG.seperator);
let data = format!(" {} {:>2}% {}", icon, vol, CONFIG.seperator);
ThreadsData::Sound(data) ThreadsData::Sound(data)
} }