diff --git a/crates/komorebi-bar-core/src/widgets/mod.rs b/crates/komorebi-bar-core/src/widgets/mod.rs index 1e786dae..0a231ba1 100644 --- a/crates/komorebi-bar-core/src/widgets/mod.rs +++ b/crates/komorebi-bar-core/src/widgets/mod.rs @@ -5,6 +5,7 @@ pub mod date; pub mod icons; pub mod komorebi_config; pub mod memory; +pub mod network_config; pub mod platform_config; pub mod storage; pub mod time; diff --git a/crates/komorebi-bar-core/src/widgets/network_config.rs b/crates/komorebi-bar-core/src/widgets/network_config.rs new file mode 100644 index 00000000..d958b453 --- /dev/null +++ b/crates/komorebi-bar-core/src/widgets/network_config.rs @@ -0,0 +1,66 @@ +//! The configuration of the network widget: data only, shared by both bars. The Windows bar +//! reads `default_interface_options`; the macOS bar accepts the key and ignores it. + +use crate::config::LabelPrefix; +use serde::Deserialize; +use serde::Serialize; + +#[derive(Copy, Clone, Debug, Serialize, Deserialize)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] +/// Network widget configuration +pub struct NetworkConfig { + /// Enable the Network widget + pub enable: bool, + /// Show total received and transmitted activity + #[serde(alias = "show_total_data_transmitted")] + pub show_total_activity: bool, + /// Show received and transmitted activity + #[serde(alias = "show_network_activity")] + pub show_activity: bool, + /// Show default interface + pub show_default_interface: Option, + /// Default interface options: whether to show the friendly name, IPv4 or IPv6 address + pub default_interface_options: Option, + /// Characters to reserve for received and transmitted activity + #[serde(alias = "network_activity_fill_characters")] + pub activity_left_padding: Option, + /// Data refresh interval in seconds + #[cfg_attr(feature = "schemars", schemars(extend("default" = 10)))] + pub data_refresh_interval: Option, + /// Display label prefix + pub label_prefix: Option, + /// Select when the value is over a limit (1MiB is 1048576 bytes (1024*1024)) + pub auto_select: Option, +} + +#[derive(Copy, Clone, Debug, Serialize, Deserialize)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] +/// Network select configuration +pub struct NetworkSelectConfig { + /// Select the total received data when it's over this value + pub total_received_over: Option, + /// Select the total transmitted data when it's over this value + pub total_transmitted_over: Option, + /// Select the received data when it's over this value + pub received_over: Option, + /// Select the transmitted data when it's over this value + pub transmitted_over: Option, +} + +#[derive(Copy, Clone, Debug, Serialize, Deserialize, Default)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] +/// Which IP address to show for the default interface +pub enum InterfaceDisplayType { + #[default] + FriendlyName, + Ipv4, + Ipv6, +} + +#[derive(Copy, Clone, Debug, Serialize, Deserialize)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] +/// Default interface configuration +pub struct DefaultInterfaceConfig { + #[serde(default)] + pub display_type: InterfaceDisplayType, +} diff --git a/komorebi-bar/src/widgets/network.rs b/komorebi-bar/src/widgets/network.rs index 740702ca..35dd3022 100644 --- a/komorebi-bar/src/widgets/network.rs +++ b/komorebi-bar/src/widgets/network.rs @@ -1,4 +1,8 @@ use crate::bar::Alignment; +pub use komorebi_bar_core::widgets::network_config::DefaultInterfaceConfig; +pub use komorebi_bar_core::widgets::network_config::InterfaceDisplayType; +pub use komorebi_bar_core::widgets::network_config::NetworkConfig; +pub use komorebi_bar_core::widgets::network_config::NetworkSelectConfig; use crate::config::LabelPrefix; use crate::render::RenderConfig; use crate::selected_frame::SelectableFrame; @@ -11,8 +15,6 @@ use eframe::egui::TextFormat; use eframe::egui::Ui; use eframe::egui::text::LayoutJob; use num_derive::FromPrimitive; -use serde::Deserialize; -use serde::Serialize; use std::fmt; use std::process::Command; use std::sync::Arc; @@ -24,66 +26,6 @@ use std::time::Duration; use std::time::Instant; use sysinfo::Networks; -#[derive(Copy, Clone, Debug, Serialize, Deserialize)] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] -/// Network widget configuration -pub struct NetworkConfig { - /// Enable the Network widget - pub enable: bool, - /// Show total received and transmitted activity - #[serde(alias = "show_total_data_transmitted")] - pub show_total_activity: bool, - /// Show received and transmitted activity - #[serde(alias = "show_network_activity")] - pub show_activity: bool, - /// Show default interface - pub show_default_interface: Option, - /// Default interface options: whether to show the friendly name, IPv4 or IPv6 address - pub default_interface_options: Option, - /// Characters to reserve for received and transmitted activity - #[serde(alias = "network_activity_fill_characters")] - pub activity_left_padding: Option, - /// Data refresh interval in seconds - #[cfg_attr(feature = "schemars", schemars(extend("default" = 10)))] - pub data_refresh_interval: Option, - /// Display label prefix - pub label_prefix: Option, - /// Select when the value is over a limit (1MiB is 1048576 bytes (1024*1024)) - pub auto_select: Option, -} - -#[derive(Copy, Clone, Debug, Serialize, Deserialize)] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] -/// Network select configuration -pub struct NetworkSelectConfig { - /// Select the total received data when it's over this value - pub total_received_over: Option, - /// Select the total transmitted data when it's over this value - pub total_transmitted_over: Option, - /// Select the received data when it's over this value - pub received_over: Option, - /// Select the transmitted data when it's over this value - pub transmitted_over: Option, -} - -#[derive(Copy, Clone, Debug, Serialize, Deserialize, Default)] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] -/// Which IP address to show for the default interface -pub enum InterfaceDisplayType { - #[default] - FriendlyName, - Ipv4, - Ipv6, -} - -#[derive(Copy, Clone, Debug, Serialize, Deserialize)] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] -/// Default interface configuration -pub struct DefaultInterfaceConfig { - #[serde(default)] - pub display_type: InterfaceDisplayType, -} - impl From for Network { fn from(value: NetworkConfig) -> Self { let default_refresh_interval = 10; diff --git a/komorebi-for-mac/komorebi-bar/src/widgets/network.rs b/komorebi-for-mac/komorebi-bar/src/widgets/network.rs index 806c7968..bd6f2476 100644 --- a/komorebi-for-mac/komorebi-bar/src/widgets/network.rs +++ b/komorebi-for-mac/komorebi-bar/src/widgets/network.rs @@ -1,4 +1,6 @@ use crate::bar::Alignment; +pub use komorebi_bar_core::widgets::network_config::NetworkConfig; +pub use komorebi_bar_core::widgets::network_config::NetworkSelectConfig; use crate::config::LabelPrefix; use crate::render::RenderConfig; use crate::selected_frame::SelectableFrame; @@ -12,8 +14,6 @@ use eframe::egui::Ui; use eframe::egui::text::LayoutJob; use num_derive::FromPrimitive; use parking_lot::Mutex; -use serde::Deserialize; -use serde::Serialize; use std::fmt; use std::process::Command; use std::sync::Arc; @@ -24,48 +24,14 @@ use std::time::Duration; use std::time::Instant; use sysinfo::Networks; -#[derive(Copy, Clone, Debug, Serialize, Deserialize)] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] -/// Network widget configuration -pub struct NetworkConfig { - /// Enable the Network widget - pub enable: bool, - /// Show total received and transmitted activity - #[serde(alias = "show_total_data_transmitted")] - pub show_total_activity: bool, - /// Show received and transmitted activity - #[serde(alias = "show_network_activity")] - pub show_activity: bool, - /// Show default interface - pub show_default_interface: Option, - /// Characters to reserve for received and transmitted activity - #[serde(alias = "network_activity_fill_characters")] - pub activity_left_padding: Option, - /// Data refresh interval in seconds - #[cfg_attr(feature = "schemars", schemars(extend("default" = 10)))] - pub data_refresh_interval: Option, - /// Display label prefix - pub label_prefix: Option, - /// Select when the value is over a limit (1MiB is 1048576 bytes (1024*1024)) - pub auto_select: Option, -} - -#[derive(Copy, Clone, Debug, Serialize, Deserialize)] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] -/// Network select configuration -pub struct NetworkSelectConfig { - /// Select the total received data when it's over this value - pub total_received_over: Option, - /// Select the total transmitted data when it's over this value - pub total_transmitted_over: Option, - /// Select the received data when it's over this value - pub received_over: Option, - /// Select the transmitted data when it's over this value - pub transmitted_over: Option, -} - impl From for Network { fn from(value: NetworkConfig) -> Self { + if value.default_interface_options.is_some() { + tracing::warn!( + "the network widget option `default_interface_options` is not supported on macOS and is ignored" + ); + } + let default_refresh_interval = 10; let data_refresh_interval = value.data_refresh_interval.unwrap_or(10);