mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-04-25 10:08: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;
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user