Renamed system stat functions
This commit is contained in:
parent
77055b80e7
commit
8234145bf2
2 changed files with 9 additions and 9 deletions
|
@ -23,13 +23,13 @@ macro_rules! builtin_vars {
|
||||||
pub fn get_inbuilt_vars() -> HashMap<VarName, ScriptVarDefinition> {
|
pub fn get_inbuilt_vars() -> HashMap<VarName, ScriptVarDefinition> {
|
||||||
builtin_vars! {Duration::new(2, 0),
|
builtin_vars! {Duration::new(2, 0),
|
||||||
// @desc EWW_TEMPS - Heat of the components in Celcius\nExample: `{(CPU_TEMPS.core_1 + CPU_TEMPS.core_2) / 2}`
|
// @desc EWW_TEMPS - Heat of the components in Celcius\nExample: `{(CPU_TEMPS.core_1 + CPU_TEMPS.core_2) / 2}`
|
||||||
"EWW_TEMPS" => || Ok(DynVal::from(cores())),
|
"EWW_TEMPS" => || Ok(DynVal::from(get_core_temperatures())),
|
||||||
|
|
||||||
// @desc EWW_RAM - The current RAM + Swap usage
|
// @desc EWW_RAM - The current RAM + Swap usage
|
||||||
"EWW_RAM" => || Ok(DynVal::from(format!("{:.2}", ram()))),
|
"EWW_RAM" => || Ok(DynVal::from(format!("{:.2}", get_ram()))),
|
||||||
|
|
||||||
// @desc EWW_DISK - Information on on all mounted partitions (Might report inaccurately on some filesystems, like btrfs)\nExample: `{EWW_DISK["/"]}`
|
// @desc EWW_DISK - Information on on all mounted partitions (Might report inaccurately on some filesystems, like btrfs)\nExample: `{EWW_DISK["/"]}`
|
||||||
"EWW_DISK" => || Ok(DynVal::from(disk())),
|
"EWW_DISK" => || Ok(DynVal::from(get_disks())),
|
||||||
|
|
||||||
// @desc EWW_BATTERY - Battery capacity in procent of the main battery
|
// @desc EWW_BATTERY - Battery capacity in procent of the main battery
|
||||||
"EWW_BATTERY" => || Ok(DynVal::from(
|
"EWW_BATTERY" => || Ok(DynVal::from(
|
||||||
|
@ -43,7 +43,7 @@ pub fn get_inbuilt_vars() -> HashMap<VarName, ScriptVarDefinition> {
|
||||||
)),
|
)),
|
||||||
|
|
||||||
// @desc EWW_CPU_USAGE - Average CPU usage (all cores) since the last update (No MacOS support)
|
// @desc EWW_CPU_USAGE - Average CPU usage (all cores) since the last update (No MacOS support)
|
||||||
"EWW_CPU_USAGE" => || Ok(DynVal::from(get_avg_cpu_usage())),
|
"EWW_CPU_USAGE" => || Ok(DynVal::from(get_cpus())),
|
||||||
|
|
||||||
// @desc EWW_NET - Bytes up/down on all interfaces
|
// @desc EWW_NET - Bytes up/down on all interfaces
|
||||||
"EWW_NET" => || Ok(DynVal::from(net())),
|
"EWW_NET" => || Ok(DynVal::from(net())),
|
||||||
|
|
|
@ -7,7 +7,7 @@ use sysinfo::{ComponentExt, DiskExt, NetworkExt, NetworksExt, ProcessorExt, Syst
|
||||||
|
|
||||||
static SYSTEM: Lazy<Mutex<System>> = Lazy::new(|| Mutex::new(System::new()));
|
static SYSTEM: Lazy<Mutex<System>> = Lazy::new(|| Mutex::new(System::new()));
|
||||||
|
|
||||||
pub fn disk() -> String {
|
pub fn get_disks() -> String {
|
||||||
let mut c = SYSTEM.lock().unwrap();
|
let mut c = SYSTEM.lock().unwrap();
|
||||||
c.refresh_disks_list();
|
c.refresh_disks_list();
|
||||||
|
|
||||||
|
@ -26,13 +26,13 @@ pub fn disk() -> String {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn ram() -> f32 {
|
pub fn get_ram() -> f32 {
|
||||||
let mut c = SYSTEM.lock().unwrap();
|
let mut c = SYSTEM.lock().unwrap();
|
||||||
c.refresh_memory();
|
c.refresh_memory();
|
||||||
(c.get_used_memory() as f32 + c.get_used_swap() as f32) / 1_000_000f32
|
(c.get_used_memory() as f32 + c.get_used_swap() as f32) / 1_000_000f32
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn cores() -> String {
|
pub fn get_core_temperatures() -> String {
|
||||||
let mut c = SYSTEM.lock().unwrap();
|
let mut c = SYSTEM.lock().unwrap();
|
||||||
c.refresh_components_list();
|
c.refresh_components_list();
|
||||||
c.refresh_components();
|
c.refresh_components();
|
||||||
|
@ -45,7 +45,7 @@ pub fn cores() -> String {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_avg_cpu_usage() -> String {
|
pub fn get_cpus() -> String {
|
||||||
let mut c = SYSTEM.lock().unwrap();
|
let mut c = SYSTEM.lock().unwrap();
|
||||||
c.refresh_cpu();
|
c.refresh_cpu();
|
||||||
let processors = c.get_processors();
|
let processors = c.get_processors();
|
||||||
|
@ -133,7 +133,7 @@ pub fn get_battery_capacity() -> Result<String> {
|
||||||
#[cfg(not(target_os = "macos"))]
|
#[cfg(not(target_os = "macos"))]
|
||||||
#[cfg(not(target_os = "linux"))]
|
#[cfg(not(target_os = "linux"))]
|
||||||
pub fn get_battery_capacity() -> Result<u8> {
|
pub fn get_battery_capacity() -> Result<u8> {
|
||||||
anyhow!("eww doesn't support your OS for getting the battery capacity")
|
anyhow!("Eww doesn't support your OS for getting the battery capacity")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn net() -> String {
|
pub fn net() -> String {
|
||||||
|
|
Loading…
Add table
Reference in a new issue