From de6e8459937b070dce4f31ff7e91eb04d8a7a10e Mon Sep 17 00:00:00 2001 From: anna <44528100+pozm@users.noreply.github.com> Date: Wed, 15 Feb 2023 09:22:12 +0000 Subject: [PATCH] refresh processes & delay on polling data --- gdke-gui/src/app.rs | 17 +++++++++++++---- gdke-gui/src/main.rs | 5 +++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/gdke-gui/src/app.rs b/gdke-gui/src/app.rs index 491e2ef..f785917 100644 --- a/gdke-gui/src/app.rs +++ b/gdke-gui/src/app.rs @@ -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 egui::{TextStyle, TextEdit}; @@ -9,7 +9,7 @@ use crate::Data; #[derive(serde::Deserialize, serde::Serialize,Debug)] pub struct gdkeApp { #[serde(skip)] - procs : Vec, + procs : Rc>>, #[serde(skip)] selected: Option, #[serde(skip)] @@ -32,7 +32,7 @@ impl Default for gdkeApp { Vec::new() }; Self { - procs, + procs: Rc::new(RefCell::new(procs)), selected: None, process: None, 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); let text_style = TextStyle::Body; let row_height = ui.text_style_height(&text_style); - let filtered_procs = if self.search_query.is_empty() {self.procs.iter().collect::>()} 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::>()} else {proca.iter() .filter(|p| p.name.contains(&self.search_query) || p.pid.to_string().contains(&self.search_query)).collect() }; let selval = selected.clone(); diff --git a/gdke-gui/src/main.rs b/gdke-gui/src/main.rs index 0ca8c94..56b4e30 100644 --- a/gdke-gui/src/main.rs +++ b/gdke-gui/src/main.rs @@ -1,3 +1,7 @@ +#![cfg_attr( + all(not(debug_assertions), target_os = "windows"), + windows_subsystem = "windows" +)] use gdke_gui::{app::gdkeApp, Data}; use poggers::{external::process::ExProcess, traits::Mem}; @@ -47,6 +51,7 @@ fn main() { _ => {} } } + std::thread::sleep(std::time::Duration::from_millis(1000)); } });