-
-
Notifications
You must be signed in to change notification settings - Fork 385
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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())), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. duration should be 2 seconds as with every other variable except time |
||
|
||
// @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 { | ||
|
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 { | ||||||||||
|
@@ -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(); | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please don't crash the application. |
||||||||||
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
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 | ||||||||||
} |
There was a problem hiding this comment.
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