diff options
| author | Shoelace <pierre.leidbring@gmail.com> | 2021-05-19 21:44:58 +0200 | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-05-19 22:44:58 +0300 | 
| commit | 2a23bd20440b0d1a359c6bb4385b6771f2657a3b (patch) | |
| tree | ec4052da5dff822c70ab20216298fe5be4abfeb7 /src/utils | |
| parent | b1d81bf8c936509b6f83b2eac98da8ae72e0a4e3 (diff) | |
Threaded to async (#58)
* Add async deps
* Rename blocks to 'BlockManager'
* Refactor "Blocks" to own module
* Make all util fn async
* Remove stray println
Diffstat (limited to 'src/utils')
| -rw-r--r-- | src/utils/battery.rs | 2 | ||||
| -rw-r--r-- | src/utils/bitcoins.rs | 2 | ||||
| -rw-r--r-- | src/utils/cpu.rs | 2 | ||||
| -rw-r--r-- | src/utils/disk.rs | 2 | ||||
| -rw-r--r-- | src/utils/load_average.rs | 2 | ||||
| -rw-r--r-- | src/utils/memory.rs | 2 | ||||
| -rw-r--r-- | src/utils/mod.rs | 1 | ||||
| -rw-r--r-- | src/utils/mpd.rs | 2 | ||||
| -rw-r--r-- | src/utils/netspeed.rs | 6 | ||||
| -rw-r--r-- | src/utils/pub_ip.rs | 2 | ||||
| -rw-r--r-- | src/utils/spotify.rs | 2 | ||||
| -rw-r--r-- | src/utils/time.rs | 3 | ||||
| -rw-r--r-- | src/utils/uptime.rs | 2 | ||||
| -rw-r--r-- | src/utils/volume.rs | 2 | ||||
| -rw-r--r-- | src/utils/weather.rs | 2 | 
15 files changed, 17 insertions, 17 deletions
| diff --git a/src/utils/battery.rs b/src/utils/battery.rs index d3688e7..432e22a 100644 --- a/src/utils/battery.rs +++ b/src/utils/battery.rs @@ -5,7 +5,7 @@ use battery::Manager;  // TODO: better error handeling  // getting battery percentage -pub fn get_battery() -> ThreadsData { +pub async fn get_battery() -> ThreadsData {      let battery_manager = if let Ok(manager) = Manager::new() {          manager      } else { diff --git a/src/utils/bitcoins.rs b/src/utils/bitcoins.rs index 465d907..94a0a3b 100644 --- a/src/utils/bitcoins.rs +++ b/src/utils/bitcoins.rs @@ -7,7 +7,7 @@ struct Response {      price_24h: f64,  } -pub fn get_price() -> ThreadsData { +pub async fn get_price() -> ThreadsData {      let url = format!(          "https://api.blockchain.com/v3/exchange/tickers/{}",          CONFIG.bitcoins.symbol diff --git a/src/utils/cpu.rs b/src/utils/cpu.rs index 2047a07..f49fda0 100644 --- a/src/utils/cpu.rs +++ b/src/utils/cpu.rs @@ -3,7 +3,7 @@ use crate::types::ThreadsData;  use std::fs::read_to_string;  // getting cpu temperature -pub fn get_cpu_temp() -> ThreadsData { +pub async fn get_cpu_temp() -> ThreadsData {      let buf = match read_to_string("/sys/class/thermal/thermal_zone0/temp") {          Ok(data) => data,          _ => return ThreadsData::CpuTemp(String::from("Error reading temp")), diff --git a/src/utils/disk.rs b/src/utils/disk.rs index 2250911..33b6449 100644 --- a/src/utils/disk.rs +++ b/src/utils/disk.rs @@ -1,7 +1,7 @@  use crate::config::CONFIG;  use crate::types::ThreadsData; -pub fn get_disk() -> ThreadsData { +pub async fn get_disk() -> ThreadsData {      const GB: u64 = (1024 * 1024) * 1024;      let statvfs = nix::sys::statvfs::statvfs("/").unwrap();      let mut disk_used = String::new(); diff --git a/src/utils/load_average.rs b/src/utils/load_average.rs index 43dc88b..337875c 100644 --- a/src/utils/load_average.rs +++ b/src/utils/load_average.rs @@ -3,7 +3,7 @@ use crate::types::ThreadsData;  use nix::libc::{c_double, c_int, getloadavg}; -pub fn get_load_avg() -> ThreadsData { +pub async fn get_load_avg() -> ThreadsData {      let mut data: [c_double; 3] = [0f64; 3];      unsafe { getloadavg(data.as_mut_ptr(), data.len() as c_int) };      let [load, _, _] = data; diff --git a/src/utils/memory.rs b/src/utils/memory.rs index 3d51fd5..46b571b 100644 --- a/src/utils/memory.rs +++ b/src/utils/memory.rs @@ -7,7 +7,7 @@ mem_used = (mem_total + shmem - mem_free - mem_buffers - mem_cached - mem_srecl  thanks for htop's developer on stackoverflow for providing this algorithm to  calculate used memory.  */ -pub fn get_memory() -> ThreadsData { +pub async fn get_memory() -> ThreadsData {      let buf = match read_to_string("/proc/meminfo") {          Ok(data) => data,          _ => return ThreadsData::Memory(String::from("Error Reading memory!")), diff --git a/src/utils/mod.rs b/src/utils/mod.rs index 22b4bad..6e0d944 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -12,3 +12,4 @@ pub mod time;  pub mod uptime;  pub mod volume;  pub mod weather; + diff --git a/src/utils/mpd.rs b/src/utils/mpd.rs index 678b59d..95af768 100644 --- a/src/utils/mpd.rs +++ b/src/utils/mpd.rs @@ -3,7 +3,7 @@ use crate::types::ThreadsData;  use mpd::{Client, Song};  // getting mpd song file -pub fn get_mpd_current() -> ThreadsData { +pub async fn get_mpd_current() -> ThreadsData {      let stream_path = format!("{}:{}", CONFIG.mpd.host, CONFIG.mpd.port);      let empty_data = ThreadsData::Mpd(String::from(""));      let mut conn = match Client::connect(&stream_path) { diff --git a/src/utils/netspeed.rs b/src/utils/netspeed.rs index 16caaa4..fae36b5 100644 --- a/src/utils/netspeed.rs +++ b/src/utils/netspeed.rs @@ -1,13 +1,13 @@  use crate::config::CONFIG;  use crate::types::ThreadsData;  use std::fs::read_to_string; -use std::thread; +use async_std::task::sleep;  use std::time::Duration; -pub fn get_netspeed() -> ThreadsData { +pub async fn get_netspeed() -> ThreadsData {      let tx1: u64 = parse_speed_file("tx_bytes");      let rx1: u64 = parse_speed_file("rx_bytes"); -    thread::sleep(Duration::from_secs(1)); +    sleep(Duration::from_secs(1)).await;      let tx2: u64 = parse_speed_file("tx_bytes");      let rx2: u64 = parse_speed_file("rx_bytes"); diff --git a/src/utils/pub_ip.rs b/src/utils/pub_ip.rs index 4f1335f..dde354a 100644 --- a/src/utils/pub_ip.rs +++ b/src/utils/pub_ip.rs @@ -1,7 +1,7 @@  use crate::config::CONFIG;  use crate::types::ThreadsData; -pub fn get_pub_ip() -> ThreadsData { +pub async fn get_pub_ip() -> ThreadsData {      let url = "http://api.ipify.org".to_string();      let _err = String::from("Error");      let res = match minreq::get(url).send() { diff --git a/src/utils/spotify.rs b/src/utils/spotify.rs index c48471d..5da9fea 100644 --- a/src/utils/spotify.rs +++ b/src/utils/spotify.rs @@ -5,7 +5,7 @@ use dbus::{arg, blocking::Connection};  use std::time::Duration;  // getting spotify current artist and title. -pub fn get_spotify() -> ThreadsData { +pub async fn get_spotify() -> ThreadsData {      let empty_data = ThreadsData::Spotify(String::from(""));      let conn = match Connection::new_session() {          Ok(conn) => conn, diff --git a/src/utils/time.rs b/src/utils/time.rs index 191d91b..903f301 100644 --- a/src/utils/time.rs +++ b/src/utils/time.rs @@ -2,7 +2,7 @@ use crate::config::CONFIG;  use crate::types::ThreadsData;  use chrono::prelude::*; -pub fn get_time() -> ThreadsData { +pub async fn get_time() -> ThreadsData {      let now = Local::now();      let data = format!( @@ -11,6 +11,5 @@ pub fn get_time() -> ThreadsData {          now.format(&CONFIG.time.format),          CONFIG.seperator      ); -      ThreadsData::Time(data)  } diff --git a/src/utils/uptime.rs b/src/utils/uptime.rs index f635b6b..e575e78 100644 --- a/src/utils/uptime.rs +++ b/src/utils/uptime.rs @@ -2,7 +2,7 @@ use crate::config::CONFIG;  use crate::types::ThreadsData;  use nix::time::clock_gettime; -pub fn get_uptime() -> ThreadsData { +pub async fn get_uptime() -> ThreadsData {      let (_, hour, minutes, seconds) = get_uptime_data();      let uptime = if hour > 0 {          format!("{}:{}:{}", hour, minutes, seconds) diff --git a/src/utils/volume.rs b/src/utils/volume.rs index 05c1dbe..47b4ed3 100644 --- a/src/utils/volume.rs +++ b/src/utils/volume.rs @@ -3,7 +3,7 @@ use crate::types::ThreadsData;  use alsa::mixer::{Mixer, SelemChannelId, SelemId};  // getting volume percentage -pub fn get_volume() -> ThreadsData { +pub async fn get_volume() -> ThreadsData {      let card = if CONFIG.volume.card == "PULSE" {          "pulse"      } else { diff --git a/src/utils/weather.rs b/src/utils/weather.rs index 11e446f..10c887c 100644 --- a/src/utils/weather.rs +++ b/src/utils/weather.rs @@ -2,7 +2,7 @@ use crate::config::CONFIG;  use crate::types::ThreadsData;  // will make a GET request from wttr.in -pub fn get_weather() -> ThreadsData { +pub async fn get_weather() -> ThreadsData {      let format = if CONFIG.weather.format.is_empty() {          String::from("%l:+%t")      } else { | 
