Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add EWW_IPV4/6 magic variable #930

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ All notable changes to eww will be listed here, starting at changes since versio
- Add `jq` function, offering jq-style json processing
- Add `justify` property to the label widget, allowing text justification (By: n3oney)
- Add `EWW_TIME` magic variable (By: Erenoit)
- Add `EWW_IPV4`, `EWW_IPV6` magic variable (By: Lanpingner)
- Add trigonometric functions (`sin`, `cos`, `tan`, `cot`) and degree/radian conversions (`degtorad`, `radtodeg`) (By: end-4)
- Add `substring` function to simplexpr
- Add `--duration` flag to `eww open`
Expand Down
44 changes: 44 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions crates/eww/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,43 @@ gtk-layer-shell = { version = "0.6.1", optional = true }
gdkx11 = { version = "0.17", optional = true }
x11rb = { version = "0.11.1", features = ["randr"], optional = true }

regex = "1.9.3"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are you adding all of these dependencies?
that's unnecessary

bincode = "1.3.3"
anyhow = "1.0.70"
derive_more = "0.99"
maplit = "1"
clap = {version = "4.3.21", features = ["derive"] }
serde = {version = "1.0", features = ["derive"]}
serde_json = "1.0"
extend = "1.2"
grass = {version = "0.13.1", default-features = false}
itertools = "0.11"
log = "0.4"
pretty_env_logger = "0.5"
libc = "0.2"
once_cell = "1.18"
nix = "0.26.2"
simple-signal = "1.1"
unescape = "0.1"

tokio = { version = "1.31.0", features = ["full"] }
futures = "0.3.28"
tokio-util = "0.7.8"

sysinfo = "0.29.8"
chrono = "0.4.26"
local-ip-address = "0.5.3"

wait-timeout = "0.2"

notify = "6.0.1"

codespan-reporting = "0.11"

simplexpr = { version = "0.1.0", path = "../simplexpr" }
eww_shared_util = { version = "0.1.0", path = "../eww_shared_util" }
yuck = { version = "0.1.0", path = "../yuck", default-features = false}

anyhow.workspace = true
bincode.workspace = true
chrono.workspace = true
Expand Down Expand Up @@ -61,3 +98,4 @@ tokio-util.workspace = true
tokio = { workspace = true, features = ["full"] }
unescape.workspace = true
wait-timeout.workspace = true

6 changes: 6 additions & 0 deletions crates/eww/src/config/inbuilt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ define_builtin_vars! {

// @desc EWW_TIME - the current UNIX timestamp
"EWW_TIME" [1] => || Ok(DynVal::from(get_time())) ,

// @desc EWW_IPV4 - Information about the IPv4 address on all interfaces except "lo"
"EWW_IPV4" [1] => || Ok(DynVal::from(get_ipv4())),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

duration should be 2 seconds as with every other variable except time
i'm not sure whether running this that often is even needed


// @desc EWW_IPV6 - Information about the IPv6 address on all interfaces except "lo"
"EWW_IPV6" [1] => || Ok(DynVal::from(get_ipv6())),
}

macro_rules! define_magic_constants {
Expand Down
16 changes: 16 additions & 0 deletions crates/eww/src/config/system_stats.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use crate::util::IterAverage;
use anyhow::{Context, Result};
use itertools::Itertools;
use once_cell::sync::Lazy;
use std::{fs::read_to_string, sync::Mutex};
use sysinfo::System;
use local_ip_address::list_afinet_netifas;

struct RefreshTime(std::time::Instant);
impl RefreshTime {
Expand Down Expand Up @@ -229,3 +231,17 @@ pub fn net() -> String {
pub fn get_time() -> String {
chrono::offset::Utc::now().timestamp().to_string()
}

pub fn get_ipv4() -> String {
let ifas = list_afinet_netifas().unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please don't crash the application.
make use of the error the function returns.

let joined =
ifas.iter().filter(|ipv| ipv.1.is_ipv4() && ipv.0 != "lo").map(|ip| format!("{}", ip.1)).collect::<Vec<_>>().join(", ");
joined
Comment on lines +237 to +239
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let joined =
ifas.iter().filter(|ipv| ipv.1.is_ipv4() && ipv.0 != "lo").map(|ip| format!("{}", ip.1)).collect::<Vec<_>>().join(", ");
joined
ifas.iter().filter(|ipv| ipv.1.is_ipv4() && ipv.0 != "lo").map(|ip| format!("{}", ip.1)).collect::<Vec<_>>().join(", ")

jsut return this directly

}

pub fn get_ipv6() -> String {
let ifas = list_afinet_netifas().unwrap();
let joined =
ifas.iter().filter(|ipv| ipv.1.is_ipv6() && ipv.0 != "lo").map(|ip| format!("{}", ip.1)).collect::<Vec<_>>().join(", ");
joined
}