diff --git a/komorebi-bar/src/battery.rs b/komorebi-bar/src/battery.rs index 65764c86f..9c5820dcd 100644 --- a/komorebi-bar/src/battery.rs +++ b/komorebi-bar/src/battery.rs @@ -17,6 +17,8 @@ use std::time::Instant; pub struct BatteryConfig { /// Enable the Battery widget pub enable: bool, + /// Data refresh interval (default: 10 seconds) + pub data_refresh_interval: Option, } impl From for Battery { @@ -41,6 +43,7 @@ impl From for Battery { enable: value.enable, manager, last_state, + data_refresh_interval: value.data_refresh_interval.unwrap_or(10), state: state.unwrap_or(BatteryState::Discharging), last_updated: Instant::now(), } @@ -56,6 +59,7 @@ pub struct Battery { pub enable: bool, manager: Manager, pub state: BatteryState, + data_refresh_interval: u64, last_state: Vec, last_updated: Instant, } @@ -65,7 +69,7 @@ impl Battery { let mut outputs = self.last_state.clone(); let now = Instant::now(); - if now.duration_since(self.last_updated) > Duration::from_secs(10) { + if now.duration_since(self.last_updated) > Duration::from_secs(self.data_refresh_interval) { outputs.clear(); if let Ok(mut batteries) = self.manager.batteries() { diff --git a/komorebi-bar/src/memory.rs b/komorebi-bar/src/memory.rs index 3d750f1b5..4e8875028 100644 --- a/komorebi-bar/src/memory.rs +++ b/komorebi-bar/src/memory.rs @@ -17,6 +17,8 @@ use sysinfo::System; pub struct MemoryConfig { /// Enable the Memory widget pub enable: bool, + /// Data refresh interval (default: 10 seconds) + pub data_refresh_interval: Option, } impl From for Memory { @@ -29,6 +31,7 @@ impl From for Memory { Self { enable: value.enable, system, + data_refresh_interval: value.data_refresh_interval.unwrap_or(10), last_updated: Instant::now(), } } @@ -37,13 +40,14 @@ impl From for Memory { pub struct Memory { pub enable: bool, system: System, + data_refresh_interval: u64, last_updated: Instant, } impl Memory { fn output(&mut self) -> Vec { let now = Instant::now(); - if now.duration_since(self.last_updated) > Duration::from_secs(10) { + if now.duration_since(self.last_updated) > Duration::from_secs(self.data_refresh_interval) { self.system.refresh_memory(); self.last_updated = now; } diff --git a/komorebi-bar/src/network.rs b/komorebi-bar/src/network.rs index 5e3c8fff5..d9bccbc59 100644 --- a/komorebi-bar/src/network.rs +++ b/komorebi-bar/src/network.rs @@ -18,6 +18,8 @@ pub struct NetworkConfig { pub enable: bool, /// Show network transfer data pub show_data: bool, + /// Data refresh interval (default: 10 seconds) + pub data_refresh_interval: Option, } impl From for Network { @@ -48,6 +50,7 @@ impl From for Network { enable: value.enable, last_state, networks, + data_refresh_interval: value.data_refresh_interval.unwrap_or(10), show_data: value.show_data, last_updated: Instant::now(), } @@ -58,6 +61,7 @@ pub struct Network { pub enable: bool, pub show_data: bool, networks: Networks, + data_refresh_interval: u64, last_state: Vec, last_updated: Instant, } @@ -67,7 +71,7 @@ impl Network { let mut outputs = self.last_state.clone(); let now = Instant::now(); - if now.duration_since(self.last_updated) > Duration::from_secs(10) { + if now.duration_since(self.last_updated) > Duration::from_secs(self.data_refresh_interval) { outputs.clear(); if let Ok(interface) = netdev::get_default_interface() { diff --git a/komorebi-bar/src/storage.rs b/komorebi-bar/src/storage.rs index 06c3be8a9..30d5eb27b 100644 --- a/komorebi-bar/src/storage.rs +++ b/komorebi-bar/src/storage.rs @@ -16,6 +16,8 @@ use sysinfo::Disks; pub struct StorageConfig { /// Enable the Storage widget pub enable: bool, + /// Data refresh interval (default: 10 seconds) + pub data_refresh_interval: Option, } impl From for Storage { @@ -23,6 +25,7 @@ impl From for Storage { Self { enable: value.enable, disks: Disks::new_with_refreshed_list(), + data_refresh_interval: value.data_refresh_interval.unwrap_or(10), last_updated: Instant::now(), } } @@ -31,13 +34,14 @@ impl From for Storage { pub struct Storage { pub enable: bool, disks: Disks, + data_refresh_interval: u64, last_updated: Instant, } impl Storage { fn output(&mut self) -> Vec { let now = Instant::now(); - if now.duration_since(self.last_updated) > Duration::from_secs(10) { + if now.duration_since(self.last_updated) > Duration::from_secs(self.data_refresh_interval) { self.disks.refresh(); self.last_updated = now; } diff --git a/schema.bar.json b/schema.bar.json index 766aa1118..f830a2e65 100644 --- a/schema.bar.json +++ b/schema.bar.json @@ -5,8 +5,7 @@ "required": [ "left_widgets", "monitor", - "right_widgets", - "theme" + "right_widgets" ], "properties": { "font_family": { @@ -59,6 +58,12 @@ "enable" ], "properties": { + "data_refresh_interval": { + "description": "Data refresh interval (default: 10 seconds)", + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, "enable": { "description": "Enable the Battery widget", "type": "boolean" @@ -237,6 +242,12 @@ "enable" ], "properties": { + "data_refresh_interval": { + "description": "Data refresh interval (default: 10 seconds)", + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, "enable": { "description": "Enable the Memory widget", "type": "boolean" @@ -259,6 +270,12 @@ "show_data" ], "properties": { + "data_refresh_interval": { + "description": "Data refresh interval (default: 10 seconds)", + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, "enable": { "description": "Enable the Network widget", "type": "boolean" @@ -284,6 +301,12 @@ "enable" ], "properties": { + "data_refresh_interval": { + "description": "Data refresh interval (default: 10 seconds)", + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, "enable": { "description": "Enable the Storage widget", "type": "boolean" @@ -414,6 +437,12 @@ "enable" ], "properties": { + "data_refresh_interval": { + "description": "Data refresh interval (default: 10 seconds)", + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, "enable": { "description": "Enable the Battery widget", "type": "boolean" @@ -592,6 +621,12 @@ "enable" ], "properties": { + "data_refresh_interval": { + "description": "Data refresh interval (default: 10 seconds)", + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, "enable": { "description": "Enable the Memory widget", "type": "boolean" @@ -614,6 +649,12 @@ "show_data" ], "properties": { + "data_refresh_interval": { + "description": "Data refresh interval (default: 10 seconds)", + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, "enable": { "description": "Enable the Network widget", "type": "boolean" @@ -639,6 +680,12 @@ "enable" ], "properties": { + "data_refresh_interval": { + "description": "Data refresh interval (default: 10 seconds)", + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, "enable": { "description": "Enable the Storage widget", "type": "boolean"