aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMustafa Salih <37256744+MustafaSalih1993@users.noreply.github.com>2021-02-02 02:23:37 +0300
committerGitHub <noreply@github.com>2021-02-02 02:23:37 +0300
commit303808ea191f4c8d047c14a77a1bd322d4dcc081 (patch)
tree7496e0b92c754eafe734d6e10a9300c3d4fc00bb
parent6c0dfddead48e603826fbf637fe51f02e8320223 (diff)
showing current public ip address (#43)
-rw-r--r--Cargo.lock56
-rw-r--r--Cargo.toml2
-rw-r--r--README.md1
-rw-r--r--rsblocks.yml61
-rw-r--r--src/config/mod.rs6
-rw-r--r--src/config/pub_ip.rs19
-rw-r--r--src/run.rs28
-rw-r--r--src/types.rs9
-rw-r--r--src/utils/mod.rs1
-rw-r--r--src/utils/pub_ip.rs15
10 files changed, 138 insertions, 60 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 72786a7..131781b 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -111,9 +111,9 @@ dependencies = [
[[package]]
name = "breadx"
-version = "0.1.11"
+version = "0.1.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "9bff92e2ec549fe3f20386d73efb30263be7467463def0c2a780d7cee5dbf5e3"
+checksum = "31dd6e33f086d25e35f64029cf4680bc1117b4d33053971e7943ae4c1b70fa89"
dependencies = [
"async-io",
"async-net",
@@ -138,9 +138,9 @@ checksum = "40e38929add23cdf8a366df9b0e088953150724bcbe5fc330b0d8eb3b328eec8"
[[package]]
name = "bytemuck"
-version = "1.4.1"
+version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "41aa2ec95ca3b5c54cf73c91acf06d24f4495d5f1b1c12506ae3483d646177ac"
+checksum = "5a4bad0c5981acc24bc09e532f35160f952e35422603f0563cd7a73c2c2e65a0"
[[package]]
name = "cache-padded"
@@ -227,15 +227,15 @@ dependencies = [
[[package]]
name = "futures-core"
-version = "0.3.8"
+version = "0.3.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "847ce131b72ffb13b6109a221da9ad97a64cbe48feb1028356b836b47b8f1748"
+checksum = "79e5145dde8da7d1b3892dad07a9c98fc04bc39892b1ecc9692cf53e2b780a65"
[[package]]
name = "futures-io"
-version = "0.3.8"
+version = "0.3.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "611834ce18aaa1bd13c4b374f5d653e1027cf99b6b502584ff8c9a64413b30bb"
+checksum = "28be053525281ad8259d47e4de5de657b25e7bac113458555bb4b70bc6870500"
[[package]]
name = "futures-lite"
@@ -278,9 +278,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "libc"
-version = "0.2.81"
+version = "0.2.84"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "1482821306169ec4d07f6aca392a4681f66c75c9918aa49641a2595db64053cb"
+checksum = "1cca32fa0182e8c0989459524dc356b8f2b5c10f1b9eb521b7d182c03cf8c5ff"
[[package]]
name = "libdbus-sys"
@@ -293,17 +293,17 @@ dependencies = [
[[package]]
name = "linked-hash-map"
-version = "0.5.3"
+version = "0.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8dd5a6d5999d9907cda8ed67bbd137d3af8085216c2ac62de5be860bd41f304a"
+checksum = "7fb9b38af92608140b86b693604b9ffcc5824240a484d1ecd4795bacb2fe88f3"
[[package]]
name = "log"
-version = "0.4.11"
+version = "0.4.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "4fabed175da42fed1fa0746b0ea71f412aa9d35e76e95e59b192c64b9dc2bf8b"
+checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710"
dependencies = [
- "cfg-if 0.1.10",
+ "cfg-if 1.0.0",
]
[[package]]
@@ -314,9 +314,9 @@ checksum = "0ee1c47aaa256ecabcaea351eae4a9b01ef39ed810004e298d2511ed284b1525"
[[package]]
name = "minreq"
-version = "2.2.1"
+version = "2.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "2466d0a7e6bfcd54f69e4a17d4a4318985aaaf7fe3df4cd3b6f11ff551129ca3"
+checksum = "85b112458b07e0864c7415847c423fe758c7189a28e72347e95d92c4bfd33f5d"
[[package]]
name = "mpd"
@@ -397,9 +397,9 @@ checksum = "427c3892f9e783d91cc128285287e70a59e206ca452770ece88a76f7a3eddd72"
[[package]]
name = "pin-project-lite"
-version = "0.2.0"
+version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "6b063f57ec186e6140e2b8b6921e5f1bd89c7356dda5b33acc5401203ca6131c"
+checksum = "439697af366c49a6d0a010c56a0d97685bc140ce0d377b13a2ea2aa42d64a827"
[[package]]
name = "pkg-config"
@@ -446,7 +446,7 @@ checksum = "4e1b7878800220a76a08f32c057829511440f65528b63b940f2f2bc145d7ac68"
[[package]]
name = "rsblocks"
-version = "0.1.11"
+version = "0.1.12"
dependencies = [
"alsa",
"breadx",
@@ -468,18 +468,18 @@ checksum = "dcf128d1287d2ea9d80910b5f1120d0b8eede3fbf1abe91c40d39ea7d51e6fda"
[[package]]
name = "serde"
-version = "1.0.120"
+version = "1.0.123"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "166b2349061381baf54a58e4b13c89369feb0ef2eaa57198899e2312aac30aab"
+checksum = "92d5161132722baa40d802cc70b15262b98258453e85e5d1d365c757c73869ae"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
-version = "1.0.120"
+version = "1.0.123"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0ca2a8cb5805ce9e3b95435e3765b7b553cecc762d938d409434338386cb5775"
+checksum = "9391c295d64fc0abb2c556bad848f33cb8296276b1ad2677d1ae1ace4f258f31"
dependencies = [
"proc-macro2",
"quote",
@@ -500,9 +500,9 @@ dependencies = [
[[package]]
name = "syn"
-version = "1.0.58"
+version = "1.0.60"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "cc60a3d73ea6594cd712d830cc1f0390fd71542d8c8cd24e70cc54cdfd5e05d5"
+checksum = "c700597eca8a5a762beb35753ef6b94df201c81cca676604f547495a0d7f0081"
dependencies = [
"proc-macro2",
"quote",
@@ -522,9 +522,9 @@ dependencies = [
[[package]]
name = "tinyvec"
-version = "1.1.0"
+version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ccf8dbc19eb42fba10e8feaaec282fb50e2c14b2726d6301dbfeed0f73306a6f"
+checksum = "317cca572a0e89c3ce0ca1f1bdc9369547fe318a683418e42ac8f59d14701023"
dependencies = [
"tinyvec_macros",
]
diff --git a/Cargo.toml b/Cargo.toml
index 37e34b9..e85723d 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "rsblocks"
-version = "0.1.11"
+version = "0.1.12"
authors = ["mustafa salih <mustafasalih1991@gmail.com>"]
edition = "2018"
readme = "README.md"
diff --git a/README.md b/README.md
index a75e195..33b70a1 100644
--- a/README.md
+++ b/README.md
@@ -19,6 +19,7 @@ A multi threaded fast status bar for dwm window manager written in **Rust** 🦀
* Battery Percentage
* Cpu Temperature
* Load Average
+* Public Ip Address
* Uptime
* Mpd Current Song
* Spotify Current Song
diff --git a/rsblocks.yml b/rsblocks.yml
index d5981ff..d0918cc 100644
--- a/rsblocks.yml
+++ b/rsblocks.yml
@@ -6,9 +6,24 @@ seperator: '┃'
# Time always running, no enabled option for this
time:
- icon: ''
- format: '%d %b, %I:%M:%S %p'
delay: 1.0
+ format: '%d %b, %I:%M:%S %p'
+ icon: ''
+
+
+# public ip address
+pub_ip:
+ delay: 120.0
+ enabled: true
+ icon: ''
+
+
+# ethernet/wifi bandwith
+netspeed:
+ enabled: false
+ interface: 'wlan0'
+ recieve_icon: ''
+ transmit_icon: ''
# ethernet/wifi bandwith
@@ -20,56 +35,56 @@ netspeed:
memory:
- icon: '▦'
- enabled: true
delay: 2.0
+ enabled: true
+ icon: '▦'
disk:
- icon: ''
- enabled: true
delay: 120.0
+ enabled: true
+ icon: ''
battery:
- icon: ''
+ delay: 120.0
enabled: false
+ icon: ''
source: 'BAT0'
- delay: 120.0
cpu_temperature:
- icon: ''
- enabled: true
delay: 120.0
+ enabled: true
+ icon: ''
# cpu load average
loadavg:
- icon: ''
- enabled: false
delay: 2.0
+ enabled: false
+ icon: ''
mpd:
- icon: ''
+ delay: 5.0
+ enabled: false
host: '127.0.0.1'
+ icon: ''
port: '6600'
- enabled: false
- delay: 5.0
volume:
- icon: ''
- enabled: true
- delay: 0.18
card: 'PULSE'
+ delay: 0.18
+ enabled: true
+ icon: ''
spotify:
- icon: ''
- enabled: false
delay: 0.5
+ enabled: false
+ icon: ''
# weather format options is available on
@@ -79,8 +94,8 @@ spotify:
# - if you have multiple formats and want to insert space between them use '+' instead.
# - giving (city) a value is recommended.
weather:
- enabled: true
- icon: ''
city: ''
- format: '%l:+%t'
delay: 7200.0 # 7200 seconds = 2 hours
+ enabled: true
+ format: '%l:+%t'
+ icon: ''
diff --git a/src/config/mod.rs b/src/config/mod.rs
index 5741b11..e55465f 100644
--- a/src/config/mod.rs
+++ b/src/config/mod.rs
@@ -5,6 +5,7 @@ mod loadavg;
mod memory;
mod mpd;
mod netspeed;
+mod pub_ip;
mod spotify;
mod time;
mod uptime;
@@ -18,6 +19,7 @@ use disk::Disk;
use loadavg::LoadAvg;
use memory::Memory;
use netspeed::NetSpeed;
+use pub_ip::PubIp;
use spotify::Spotify;
use time::Time;
use uptime::Uptime;
@@ -87,6 +89,9 @@ pub struct Config {
#[serde(default)]
pub netspeed: NetSpeed,
+
+ #[serde(default)]
+ pub pub_ip: PubIp,
}
impl Default for Config {
@@ -105,6 +110,7 @@ impl Default for Config {
spotify: Default::default(),
loadavg: Default::default(),
netspeed: Default::default(),
+ pub_ip: Default::default(),
}
}
}
diff --git a/src/config/pub_ip.rs b/src/config/pub_ip.rs
new file mode 100644
index 0000000..df27f28
--- /dev/null
+++ b/src/config/pub_ip.rs
@@ -0,0 +1,19 @@
+use serde::{Deserialize, Serialize};
+use std::default::Default;
+
+#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
+pub struct PubIp {
+ pub icon: String,
+ pub enabled: bool,
+ pub delay: f64,
+}
+
+impl Default for PubIp {
+ fn default() -> Self {
+ PubIp {
+ icon: String::from(""),
+ enabled: false,
+ delay: 120.0,
+ }
+ }
+}
diff --git a/src/run.rs b/src/run.rs
index 141e32d..12efefa 100644
--- a/src/run.rs
+++ b/src/run.rs
@@ -17,6 +17,16 @@ pub fn run(mut blocks: Blocks) {
thread::sleep(Duration::from_secs_f64(CONFIG.loadavg.delay))
});
}
+ // public ip thread
+ if CONFIG.pub_ip.enabled {
+ let pub_ip_tx = tx.clone();
+ thread::spawn(move || loop {
+ let pub_ip_data = ThreadsData::PubIp(pub_ip::get_pub_ip());
+ pub_ip_tx.send(pub_ip_data).unwrap();
+ thread::sleep(Duration::from_secs_f64(CONFIG.pub_ip.delay))
+ });
+ }
+
// spotify thread
if CONFIG.spotify.enabled {
let spotify_tx = tx.clone();
@@ -130,7 +140,8 @@ pub fn run(mut blocks: Blocks) {
//Main
{
// NOTE: order matters to the final format
- let mut bar: Vec<String> = vec![String::from(""); 12];
+
+ let mut bar: Vec<String> = vec![String::from(""); 13];
//iterating the values recieved from the threads
for data in rx {
match data {
@@ -139,13 +150,14 @@ pub fn run(mut blocks: Blocks) {
ThreadsData::Sound(x) => bar[2] = x,
ThreadsData::Weather(x) => bar[3] = x,
ThreadsData::NetSpeed(x) => bar[4] = x,
- ThreadsData::Disk(x) => bar[5] = x,
- ThreadsData::Memory(x) => bar[6] = x,
- ThreadsData::CpuTemp(x) => bar[7] = x,
- ThreadsData::LoadAvg(x) => bar[8] = x,
- ThreadsData::Battery(x) => bar[9] = x,
- ThreadsData::Uptime(x) => bar[10] = x,
- ThreadsData::Time(x) => bar[11] = x,
+ ThreadsData::PubIp(x) => bar[5] = x,
+ ThreadsData::Disk(x) => bar[6] = x,
+ ThreadsData::Memory(x) => bar[7] = x,
+ ThreadsData::CpuTemp(x) => bar[8] = x,
+ ThreadsData::LoadAvg(x) => bar[9] = x,
+ ThreadsData::Battery(x) => bar[10] = x,
+ ThreadsData::Uptime(x) => bar[11] = x,
+ ThreadsData::Time(x) => bar[12] = x,
}
// match ends here
diff --git a/src/types.rs b/src/types.rs
index 7184d47..5def739 100644
--- a/src/types.rs
+++ b/src/types.rs
@@ -14,6 +14,7 @@ pub enum ThreadsData {
Spotify(String),
LoadAvg(String),
NetSpeed(String),
+ PubIp(String),
}
#[derive(Clone)]
@@ -30,6 +31,7 @@ pub struct Config {
pub mpd: Mpd,
pub spotify: Spotify,
pub loadavg: LoadAvg,
+ pub pub_ip: PubIp,
}
#[derive(Clone)]
@@ -122,6 +124,13 @@ pub struct NetSpeed {
pub enabled: bool,
}
+#[derive(Clone)]
+pub struct PubIp {
+ pub icon: String,
+ pub enabled: bool,
+ pub delay: f64,
+}
+
pub struct Blocks {
pub disp: Display<name::NameConnection>,
pub root: Window,
diff --git a/src/utils/mod.rs b/src/utils/mod.rs
index 3b4eb7b..e70cf88 100644
--- a/src/utils/mod.rs
+++ b/src/utils/mod.rs
@@ -5,6 +5,7 @@ pub mod load_average;
pub mod memory;
pub mod mpd;
pub mod netspeed;
+pub mod pub_ip;
pub mod spotify;
pub mod time;
pub mod uptime;
diff --git a/src/utils/pub_ip.rs b/src/utils/pub_ip.rs
new file mode 100644
index 0000000..ce2da92
--- /dev/null
+++ b/src/utils/pub_ip.rs
@@ -0,0 +1,15 @@
+use crate::config::CONFIG;
+
+pub fn get_pub_ip() -> String {
+ let url = format!("http://api.ipify.org");
+ let err_string = 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(_) => err_string,
+ },
+ Err(_) => err_string,
+ };
+
+ format!(" {} {} {}", CONFIG.pub_ip.icon, res, CONFIG.seperator)
+}