feat(bar): network widget - added show_default_interface and use enable to toggle the whole widget

This commit is contained in:
Csaba
2024-12-07 23:46:36 +01:00
committed by جاد
parent f59d7a51f1
commit 830da89529
+11 -4
View File
@@ -27,6 +27,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,
/// Show default interface
pub show_default_interface: Option<bool>,
/// Characters to reserve for network activity data /// Characters to reserve for network activity data
pub network_activity_fill_characters: Option<usize>, pub network_activity_fill_characters: Option<usize>,
/// Data refresh interval (default: 10 seconds) /// Data refresh interval (default: 10 seconds)
@@ -41,12 +43,13 @@ impl From<NetworkConfig> for Network {
Self { Self {
enable: value.enable, enable: value.enable,
show_total_activity: value.show_total_data_transmitted,
show_activity: value.show_network_activity,
show_default_interface: value.show_default_interface.unwrap_or(true),
networks_network_activity: Networks::new_with_refreshed_list(), networks_network_activity: Networks::new_with_refreshed_list(),
default_interface: String::new(), default_interface: String::new(),
data_refresh_interval, data_refresh_interval,
label_prefix: value.label_prefix.unwrap_or(LabelPrefix::Icon), label_prefix: value.label_prefix.unwrap_or(LabelPrefix::Icon),
show_total_activity: value.show_total_data_transmitted,
show_activity: value.show_network_activity,
network_activity_fill_characters: value network_activity_fill_characters: value
.network_activity_fill_characters .network_activity_fill_characters
.unwrap_or_default(), .unwrap_or_default(),
@@ -63,6 +66,7 @@ pub struct Network {
pub enable: bool, pub enable: bool,
pub show_total_activity: bool, pub show_total_activity: bool,
pub show_activity: bool, pub show_activity: bool,
pub show_default_interface: bool,
networks_network_activity: Networks, networks_network_activity: Networks,
data_refresh_interval: u64, data_refresh_interval: u64,
label_prefix: LabelPrefix, label_prefix: LabelPrefix,
@@ -250,6 +254,7 @@ impl Network {
impl BarWidget for Network { impl BarWidget for Network {
fn render(&mut self, ctx: &Context, ui: &mut Ui, config: &mut RenderConfig) { fn render(&mut self, ctx: &Context, ui: &mut Ui, config: &mut RenderConfig) {
if self.enable {
if self.show_total_activity || self.show_activity { if self.show_total_activity || self.show_activity {
let (activity, total_activity) = self.network_activity(); let (activity, total_activity) = self.network_activity();
@@ -270,7 +275,7 @@ impl BarWidget for Network {
} }
} }
if self.enable { if self.show_default_interface {
self.default_interface(); self.default_interface();
if !self.default_interface.is_empty() { if !self.default_interface.is_empty() {
@@ -308,7 +313,8 @@ impl BarWidget for Network {
.show(ui, |ui| ui.add(Label::new(layout_job).selectable(false))) .show(ui, |ui| ui.add(Label::new(layout_job).selectable(false)))
.clicked() .clicked()
{ {
if let Err(error) = Command::new("cmd.exe").args(["/C", "ncpa"]).spawn() { if let Err(error) = Command::new("cmd.exe").args(["/C", "ncpa"]).spawn()
{
eprintln!("{}", error) eprintln!("{}", error)
} }
} }
@@ -316,6 +322,7 @@ impl BarWidget for Network {
} }
} }
} }
}
} }
#[derive(Clone)] #[derive(Clone)]