mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-04-22 08:38:33 +02:00
perf(bar): use explicit redraw and data refresh strategies
This commit is contained in:
@@ -100,6 +100,7 @@ fn main() -> eframe::Result<()> {
|
||||
.with_decorations(false)
|
||||
.with_transparent(config.transparent)
|
||||
.with_position(config.position)
|
||||
.with_taskbar(false)
|
||||
.with_inner_size(config.inner_size),
|
||||
..Default::default()
|
||||
};
|
||||
@@ -119,9 +120,15 @@ fn main() -> eframe::Result<()> {
|
||||
"komorebi-bar",
|
||||
native_options,
|
||||
Box::new(|cc| {
|
||||
let frame = cc.egui_ctx.clone();
|
||||
let config_cl = config_arc.clone();
|
||||
|
||||
let ctx_repainter = cc.egui_ctx.clone();
|
||||
std::thread::spawn(move || loop {
|
||||
std::thread::sleep(Duration::from_secs(1));
|
||||
ctx_repainter.request_repaint();
|
||||
});
|
||||
|
||||
let ctx_komorebi = cc.egui_ctx.clone();
|
||||
std::thread::spawn(move || {
|
||||
let listener = komorebi_client::subscribe("komorebi-bar").unwrap();
|
||||
|
||||
@@ -165,7 +172,7 @@ fn main() -> eframe::Result<()> {
|
||||
)
|
||||
{
|
||||
tx_gui.send(notification).unwrap();
|
||||
frame.request_repaint();
|
||||
ctx_komorebi.request_repaint();
|
||||
}
|
||||
}
|
||||
Err(error) => {
|
||||
@@ -347,7 +354,6 @@ impl eframe::App for Komobar {
|
||||
ui.with_layout(Layout::right_to_left(Align::Center), |ui| {
|
||||
if self.time.enable {
|
||||
for time in self.time.output() {
|
||||
ctx.request_repaint();
|
||||
if ui
|
||||
.add(
|
||||
Label::new(format!("🕐 {}", time))
|
||||
@@ -393,7 +399,7 @@ impl eframe::App for Komobar {
|
||||
.clicked()
|
||||
{
|
||||
if let Err(error) =
|
||||
Command::new("cmd.exe").args(["/C", "taskmgr.exe"]).output()
|
||||
Command::new("cmd.exe").args(["/C", "taskmgr.exe"]).spawn()
|
||||
{
|
||||
eprintln!("{}", error)
|
||||
}
|
||||
@@ -419,7 +425,7 @@ impl eframe::App for Komobar {
|
||||
"explorer.exe",
|
||||
disk.split(' ').collect::<Vec<&str>>()[0],
|
||||
])
|
||||
.output()
|
||||
.spawn()
|
||||
{
|
||||
eprintln!("{}", error)
|
||||
}
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
use crate::widget::BarWidget;
|
||||
use std::time::Duration;
|
||||
use std::time::Instant;
|
||||
use sysinfo::RefreshKind;
|
||||
use sysinfo::System;
|
||||
|
||||
pub struct Memory {
|
||||
pub enable: bool,
|
||||
system: System,
|
||||
last_updated: Instant,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
@@ -14,18 +17,27 @@ pub struct MemoryConfig {
|
||||
|
||||
impl From<MemoryConfig> for Memory {
|
||||
fn from(value: MemoryConfig) -> Self {
|
||||
let mut system =
|
||||
System::new_with_specifics(RefreshKind::default().without_cpu().without_processes());
|
||||
|
||||
system.refresh_memory();
|
||||
|
||||
Self {
|
||||
enable: value.enable,
|
||||
system: System::new_with_specifics(
|
||||
RefreshKind::default().without_cpu().without_processes(),
|
||||
),
|
||||
system,
|
||||
last_updated: Instant::now(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl BarWidget for Memory {
|
||||
fn output(&mut self) -> Vec<String> {
|
||||
self.system.refresh_memory();
|
||||
let now = Instant::now();
|
||||
if now.duration_since(self.last_updated) > Duration::from_secs(10) {
|
||||
self.system.refresh_memory();
|
||||
self.last_updated = now;
|
||||
}
|
||||
|
||||
let used = self.system.used_memory();
|
||||
let total = self.system.total_memory();
|
||||
vec![format!("RAM: {}%", (used * 100) / total)]
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
use crate::widget::BarWidget;
|
||||
use std::time::Duration;
|
||||
use std::time::Instant;
|
||||
use sysinfo::Disks;
|
||||
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
@@ -11,6 +13,7 @@ impl From<StorageConfig> for Storage {
|
||||
Self {
|
||||
enable: value.enable,
|
||||
disks: Disks::new_with_refreshed_list(),
|
||||
last_updated: Instant::now(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,11 +21,16 @@ impl From<StorageConfig> for Storage {
|
||||
pub struct Storage {
|
||||
pub enable: bool,
|
||||
disks: Disks,
|
||||
last_updated: Instant,
|
||||
}
|
||||
|
||||
impl BarWidget for Storage {
|
||||
fn output(&mut self) -> Vec<String> {
|
||||
self.disks.refresh();
|
||||
let now = Instant::now();
|
||||
if now.duration_since(self.last_updated) > Duration::from_secs(10) {
|
||||
self.disks.refresh();
|
||||
self.last_updated = now;
|
||||
}
|
||||
|
||||
let mut disks = vec![];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user