refresh processes & delay on polling data

This commit is contained in:
anna 2023-02-15 09:22:12 +00:00
parent 29c24d253a
commit de6e845993
No known key found for this signature in database
GPG Key ID: C72F3433D1A673B4
2 changed files with 18 additions and 4 deletions

View File

@ -1,4 +1,4 @@
use std::{borrow::BorrowMut, ops::Deref, sync::mpsc::{Receiver, Sender}}; use std::{borrow::BorrowMut, ops::Deref, sync::mpsc::{Receiver, Sender}, rc::Rc, cell::RefCell};
use eframe::CreationContext; use eframe::CreationContext;
use egui::{TextStyle, TextEdit}; use egui::{TextStyle, TextEdit};
@ -9,7 +9,7 @@ use crate::Data;
#[derive(serde::Deserialize, serde::Serialize,Debug)] #[derive(serde::Deserialize, serde::Serialize,Debug)]
pub struct gdkeApp { pub struct gdkeApp {
#[serde(skip)] #[serde(skip)]
procs : Vec<ExPartialProcess>, procs : Rc<RefCell<Vec<ExPartialProcess>>>,
#[serde(skip)] #[serde(skip)]
selected: Option<ExPartialProcess>, selected: Option<ExPartialProcess>,
#[serde(skip)] #[serde(skip)]
@ -32,7 +32,7 @@ impl Default for gdkeApp {
Vec::new() Vec::new()
}; };
Self { Self {
procs, procs: Rc::new(RefCell::new(procs)),
selected: None, selected: None,
process: None, process: None,
search_query: String::new(), search_query: String::new(),
@ -99,7 +99,16 @@ impl eframe::App for gdkeApp {
egui::TextEdit::singleline(&mut self.search_query).hint_text("Search...").show(ui); egui::TextEdit::singleline(&mut self.search_query).hint_text("Search...").show(ui);
let text_style = TextStyle::Body; let text_style = TextStyle::Body;
let row_height = ui.text_style_height(&text_style); let row_height = ui.text_style_height(&text_style);
let filtered_procs = if self.search_query.is_empty() {self.procs.iter().collect::<Vec::<&ExPartialProcess>>()} else {self.procs.iter() if ui.button("refresh processes").clicked() {
procs.clone().borrow_mut().replace(if let Ok(procs) = ExProcess::get_processes() {
procs
} else {
Vec::new()
});
}
let mut procsrn = procs.clone();
let proca = procsrn.borrow();
let filtered_procs = if self.search_query.is_empty() {proca.iter().collect::<Vec::<&ExPartialProcess>>()} else {proca.iter()
.filter(|p| p.name.contains(&self.search_query) || p.pid.to_string().contains(&self.search_query)).collect() .filter(|p| p.name.contains(&self.search_query) || p.pid.to_string().contains(&self.search_query)).collect()
}; };
let selval = selected.clone(); let selval = selected.clone();

View File

@ -1,3 +1,7 @@
#![cfg_attr(
all(not(debug_assertions), target_os = "windows"),
windows_subsystem = "windows"
)]
use gdke_gui::{app::gdkeApp, Data}; use gdke_gui::{app::gdkeApp, Data};
use poggers::{external::process::ExProcess, traits::Mem}; use poggers::{external::process::ExProcess, traits::Mem};
@ -47,6 +51,7 @@ fn main() {
_ => {} _ => {}
} }
} }
std::thread::sleep(std::time::Duration::from_millis(1000));
} }
}); });