mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-04-22 08:38:33 +02:00
feat(bar): add optional data refresh intervals to config
This commit is contained in:
@@ -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<u64>,
|
||||
}
|
||||
|
||||
impl From<BatteryConfig> for Battery {
|
||||
@@ -41,6 +43,7 @@ impl From<BatteryConfig> 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<String>,
|
||||
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() {
|
||||
|
||||
@@ -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<u64>,
|
||||
}
|
||||
|
||||
impl From<MemoryConfig> for Memory {
|
||||
@@ -29,6 +31,7 @@ impl From<MemoryConfig> 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<MemoryConfig> for Memory {
|
||||
pub struct Memory {
|
||||
pub enable: bool,
|
||||
system: System,
|
||||
data_refresh_interval: u64,
|
||||
last_updated: Instant,
|
||||
}
|
||||
|
||||
impl Memory {
|
||||
fn output(&mut self) -> Vec<String> {
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -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<u64>,
|
||||
}
|
||||
|
||||
impl From<NetworkConfig> for Network {
|
||||
@@ -48,6 +50,7 @@ impl From<NetworkConfig> 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<String>,
|
||||
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() {
|
||||
|
||||
@@ -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<u64>,
|
||||
}
|
||||
|
||||
impl From<StorageConfig> for Storage {
|
||||
@@ -23,6 +25,7 @@ impl From<StorageConfig> 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<StorageConfig> for Storage {
|
||||
pub struct Storage {
|
||||
pub enable: bool,
|
||||
disks: Disks,
|
||||
data_refresh_interval: u64,
|
||||
last_updated: Instant,
|
||||
}
|
||||
|
||||
impl Storage {
|
||||
fn output(&mut self) -> Vec<String> {
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user