mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-07-10 07:02:44 +02:00
feat(bar): configurable network activity fill char len
This commit is contained in:
Generated
+37
@@ -2690,6 +2690,9 @@ dependencies = [
|
|||||||
"image",
|
"image",
|
||||||
"komorebi-client",
|
"komorebi-client",
|
||||||
"netdev",
|
"netdev",
|
||||||
|
"num",
|
||||||
|
"num-derive",
|
||||||
|
"num-traits",
|
||||||
"schemars",
|
"schemars",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json_lenient",
|
"serde_json_lenient",
|
||||||
@@ -3368,6 +3371,20 @@ dependencies = [
|
|||||||
"winapi",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "num"
|
||||||
|
version = "0.4.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "35bd024e8b2ff75562e5f34e7f4905839deb4b22955ef5e73d2fea1b9813cb23"
|
||||||
|
dependencies = [
|
||||||
|
"num-bigint",
|
||||||
|
"num-complex",
|
||||||
|
"num-integer",
|
||||||
|
"num-iter",
|
||||||
|
"num-rational",
|
||||||
|
"num-traits",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "num-bigint"
|
name = "num-bigint"
|
||||||
version = "0.4.6"
|
version = "0.4.6"
|
||||||
@@ -3378,6 +3395,15 @@ dependencies = [
|
|||||||
"num-traits",
|
"num-traits",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "num-complex"
|
||||||
|
version = "0.4.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "73f88a1307638156682bada9d7604135552957b7818057dcef22705b4d509495"
|
||||||
|
dependencies = [
|
||||||
|
"num-traits",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "num-conv"
|
name = "num-conv"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
@@ -3404,6 +3430,17 @@ dependencies = [
|
|||||||
"num-traits",
|
"num-traits",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "num-iter"
|
||||||
|
version = "0.1.45"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1429034a0490724d0075ebb2bc9e875d6503c3cf69e235a8941aa757d83ef5bf"
|
||||||
|
dependencies = [
|
||||||
|
"autocfg",
|
||||||
|
"num-integer",
|
||||||
|
"num-traits",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "num-rational"
|
name = "num-rational"
|
||||||
version = "0.4.2"
|
version = "0.4.2"
|
||||||
|
|||||||
@@ -20,6 +20,9 @@ font-loader = "0.11"
|
|||||||
hotwatch = "0.5"
|
hotwatch = "0.5"
|
||||||
image = "0.25"
|
image = "0.25"
|
||||||
netdev = "0.30"
|
netdev = "0.30"
|
||||||
|
num = "0.4.3"
|
||||||
|
num-derive = "0.4.2"
|
||||||
|
num-traits = "0.2.19"
|
||||||
schemars = { workspace = true }
|
schemars = { workspace = true }
|
||||||
serde = { workspace = true }
|
serde = { workspace = true }
|
||||||
serde_json = { workspace = true }
|
serde_json = { workspace = true }
|
||||||
@@ -31,6 +34,3 @@ tracing-appender = "0.2"
|
|||||||
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
|
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
|
||||||
windows = { workspace = true }
|
windows = { workspace = true }
|
||||||
windows-icons = "0.1"
|
windows-icons = "0.1"
|
||||||
num = "0.4.3"
|
|
||||||
num-derive = "0.4.2"
|
|
||||||
num-traits = "0.2.19"
|
|
||||||
|
|||||||
@@ -4,15 +4,15 @@ use eframe::egui::Context;
|
|||||||
use eframe::egui::Label;
|
use eframe::egui::Label;
|
||||||
use eframe::egui::Sense;
|
use eframe::egui::Sense;
|
||||||
use eframe::egui::Ui;
|
use eframe::egui::Ui;
|
||||||
|
use num_derive::FromPrimitive;
|
||||||
use schemars::JsonSchema;
|
use schemars::JsonSchema;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
use std::fmt;
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
use sysinfo::Networks;
|
use sysinfo::Networks;
|
||||||
use std::fmt;
|
|
||||||
use num_derive::FromPrimitive;
|
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema)]
|
#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema)]
|
||||||
pub struct NetworkConfig {
|
pub struct NetworkConfig {
|
||||||
@@ -22,6 +22,8 @@ pub struct NetworkConfig {
|
|||||||
pub show_total_data_transmitted: bool,
|
pub show_total_data_transmitted: bool,
|
||||||
/// Show network activity
|
/// Show network activity
|
||||||
pub show_network_activity: bool,
|
pub show_network_activity: bool,
|
||||||
|
/// Characters to reserve for network activity data
|
||||||
|
pub network_activity_fill_characters: Option<usize>,
|
||||||
/// Data refresh interval (default: 10 seconds)
|
/// Data refresh interval (default: 10 seconds)
|
||||||
pub data_refresh_interval: Option<u64>,
|
pub data_refresh_interval: Option<u64>,
|
||||||
}
|
}
|
||||||
@@ -60,11 +62,12 @@ impl From<NetworkConfig> for Network {
|
|||||||
for (interface_name, data) in &networks_network_activity {
|
for (interface_name, data) in &networks_network_activity {
|
||||||
if friendly_name.eq(interface_name) {
|
if friendly_name.eq(interface_name) {
|
||||||
last_state_transmitted.push(format!(
|
last_state_transmitted.push(format!(
|
||||||
"{} {: >10}/s {} {: >10}/s",
|
"{} {: >width$}/s {} {: >width$}/s",
|
||||||
egui_phosphor::regular::ARROW_FAT_DOWN,
|
egui_phosphor::regular::ARROW_FAT_DOWN,
|
||||||
to_pretty_bytes(data.received(), 1),
|
to_pretty_bytes(data.received(), 1),
|
||||||
egui_phosphor::regular::ARROW_FAT_UP,
|
egui_phosphor::regular::ARROW_FAT_UP,
|
||||||
to_pretty_bytes(data.transmitted(), 1),
|
to_pretty_bytes(data.transmitted(), 1),
|
||||||
|
width = value.network_activity_fill_characters.unwrap_or_default(),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -80,6 +83,9 @@ impl From<NetworkConfig> for Network {
|
|||||||
data_refresh_interval: value.data_refresh_interval.unwrap_or(10),
|
data_refresh_interval: value.data_refresh_interval.unwrap_or(10),
|
||||||
show_total_data_transmitted: value.show_total_data_transmitted,
|
show_total_data_transmitted: value.show_total_data_transmitted,
|
||||||
show_network_activity: value.show_network_activity,
|
show_network_activity: value.show_network_activity,
|
||||||
|
network_activity_fill_characters: value
|
||||||
|
.network_activity_fill_characters
|
||||||
|
.unwrap_or_default(),
|
||||||
last_state_total_data_transmitted: last_state_data,
|
last_state_total_data_transmitted: last_state_data,
|
||||||
last_state_network_activity: last_state_transmitted,
|
last_state_network_activity: last_state_transmitted,
|
||||||
last_updated_total_data_transmitted: Instant::now(),
|
last_updated_total_data_transmitted: Instant::now(),
|
||||||
@@ -100,6 +106,7 @@ pub struct Network {
|
|||||||
last_state_network_activity: Vec<String>,
|
last_state_network_activity: Vec<String>,
|
||||||
last_updated_total_data_transmitted: Instant,
|
last_updated_total_data_transmitted: Instant,
|
||||||
last_updated_network_activity: Instant,
|
last_updated_network_activity: Instant,
|
||||||
|
network_activity_fill_characters: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Network {
|
impl Network {
|
||||||
@@ -128,11 +135,12 @@ impl Network {
|
|||||||
for (interface_name, data) in &self.networks_network_activity {
|
for (interface_name, data) in &self.networks_network_activity {
|
||||||
if friendly_name.eq(interface_name) {
|
if friendly_name.eq(interface_name) {
|
||||||
outputs.push(format!(
|
outputs.push(format!(
|
||||||
"{} {: >10}/s {} {: >10}/s",
|
"{} {: >width$}/s {} {: >width$}/s",
|
||||||
egui_phosphor::regular::ARROW_FAT_DOWN,
|
egui_phosphor::regular::ARROW_FAT_DOWN,
|
||||||
to_pretty_bytes(data.received(), self.data_refresh_interval),
|
to_pretty_bytes(data.received(), self.data_refresh_interval),
|
||||||
egui_phosphor::regular::ARROW_FAT_UP,
|
egui_phosphor::regular::ARROW_FAT_UP,
|
||||||
to_pretty_bytes(data.transmitted(), self.data_refresh_interval),
|
to_pretty_bytes(data.transmitted(), self.data_refresh_interval),
|
||||||
|
width = self.network_activity_fill_characters,
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -250,7 +258,7 @@ impl fmt::Display for DataUnit {
|
|||||||
|
|
||||||
fn to_pretty_bytes(input_in_bytes: u64, timespan_in_s: u64) -> String {
|
fn to_pretty_bytes(input_in_bytes: u64, timespan_in_s: u64) -> String {
|
||||||
let input = input_in_bytes as f32 / timespan_in_s as f32;
|
let input = input_in_bytes as f32 / timespan_in_s as f32;
|
||||||
let mut magnitude = input.log(1024 as f32) as u32;
|
let mut magnitude = input.log(1024f32) as u32;
|
||||||
|
|
||||||
// let the base unit be KiB
|
// let the base unit be KiB
|
||||||
if magnitude < 1 {
|
if magnitude < 1 {
|
||||||
@@ -258,11 +266,11 @@ fn to_pretty_bytes(input_in_bytes: u64, timespan_in_s: u64) -> String {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let base: Option<DataUnit> = num::FromPrimitive::from_u32(magnitude);
|
let base: Option<DataUnit> = num::FromPrimitive::from_u32(magnitude);
|
||||||
let result = input as f32 / ((1 as u64) << (magnitude * 10)) as f32;
|
let result = input / ((1u64) << (magnitude * 10)) as f32;
|
||||||
|
|
||||||
match base {
|
match base {
|
||||||
Some(DataUnit::B) => format!("{result:.1} B"),
|
Some(DataUnit::B) => format!("{result:.1} B"),
|
||||||
Some(unit) => format!("{result:.1} {unit}iB"),
|
Some(unit) => format!("{result:.1} {unit}iB"),
|
||||||
None => format!("Unknown data unit"),
|
None => String::from("Unknown data unit"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -281,6 +281,12 @@
|
|||||||
"description": "Enable the Network widget",
|
"description": "Enable the Network widget",
|
||||||
"type": "boolean"
|
"type": "boolean"
|
||||||
},
|
},
|
||||||
|
"network_activity_fill_characters": {
|
||||||
|
"description": "Characters to reserve for network activity data",
|
||||||
|
"type": "integer",
|
||||||
|
"format": "uint",
|
||||||
|
"minimum": 0.0
|
||||||
|
},
|
||||||
"show_network_activity": {
|
"show_network_activity": {
|
||||||
"description": "Show network activity",
|
"description": "Show network activity",
|
||||||
"type": "boolean"
|
"type": "boolean"
|
||||||
@@ -665,6 +671,12 @@
|
|||||||
"description": "Enable the Network widget",
|
"description": "Enable the Network widget",
|
||||||
"type": "boolean"
|
"type": "boolean"
|
||||||
},
|
},
|
||||||
|
"network_activity_fill_characters": {
|
||||||
|
"description": "Characters to reserve for network activity data",
|
||||||
|
"type": "integer",
|
||||||
|
"format": "uint",
|
||||||
|
"minimum": 0.0
|
||||||
|
},
|
||||||
"show_network_activity": {
|
"show_network_activity": {
|
||||||
"description": "Show network activity",
|
"description": "Show network activity",
|
||||||
"type": "boolean"
|
"type": "boolean"
|
||||||
|
|||||||
Reference in New Issue
Block a user