From bca7994c8da380348a8e7ab10f8c7bf7de8f6b58 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sun, 10 Nov 2024 22:51:43 +0100 Subject: [PATCH 1/2] Update sysinfo version to 0.32 --- Cargo.lock | 65 ++++++++++++++++++++++++++++-------------- Cargo.toml | 2 +- src/display_procs.rs | 22 ++++++++++---- src/display_sysinfo.rs | 11 +++---- src/main.rs | 4 +-- src/process_dialog.rs | 8 ++++-- 6 files changed, 73 insertions(+), 39 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7773a0a..3645988 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -67,12 +67,6 @@ dependencies = [ "target-lexicon", ] -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - [[package]] name = "concurrent-queue" version = "2.4.0" @@ -84,9 +78,9 @@ dependencies = [ [[package]] name = "core-foundation-sys" -version = "0.8.6" +version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" [[package]] name = "crossbeam-deque" @@ -523,12 +517,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "once_cell" -version = "1.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" - [[package]] name = "pango" version = "0.19.3" @@ -744,15 +732,14 @@ dependencies = [ [[package]] name = "sysinfo" -version = "0.30.11" +version = "0.32.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87341a165d73787554941cd5ef55ad728011566fe714e987d1b976c15dbc3a83" +checksum = "e3b5ae3f4f7d64646c46c4cae4e3f01d1c5d255c7406fdd7c7f999a94e488791" dependencies = [ - "cfg-if", "core-foundation-sys", "libc", + "memchr", "ntapi", - "once_cell", "rayon", "windows", ] @@ -883,9 +870,9 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] name = "windows" -version = "0.52.0" +version = "0.57.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e48a53791691ab099e5e2ad123536d0fff50652600abaf43bbf952894110d0be" +checksum = "12342cb4d8e3b046f3d80effd474a7a02447231330ef77d71daa6fbc40681143" dependencies = [ "windows-core", "windows-targets", @@ -893,9 +880,43 @@ dependencies = [ [[package]] name = "windows-core" -version = "0.52.0" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2ed2439a290666cd67ecce2b0ffaad89c2a56b976b736e6ece670297897832d" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-result", + "windows-targets", +] + +[[package]] +name = "windows-implement" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9107ddc059d5b6fbfbffdfa7a7fe3e22a226def0b2608f72e9d552763d3e1ad7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.60", +] + +[[package]] +name = "windows-interface" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29bee4b38ea3cde66011baa44dba677c432a78593e202392d1e9070cf2a7fca7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.60", +] + +[[package]] +name = "windows-result" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" +checksum = "5e383302e8ec8515204254685643de10811af0ed97ea37210dc26fb0032647f8" dependencies = [ "windows-targets", ] diff --git a/Cargo.toml b/Cargo.toml index 4e1c491..ed895b6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,7 @@ keywords = ["GUI", "process", "viewer", "gtk"] [dependencies] gtk = { version = "0.8", package = "gtk4" } -sysinfo = "0.30" +sysinfo = "0.32" libc = "0.2" serde = "1.0" serde_derive = "1.0" diff --git a/src/display_procs.rs b/src/display_procs.rs index e2223f6..9d39f88 100644 --- a/src/display_procs.rs +++ b/src/display_procs.rs @@ -7,6 +7,7 @@ use crate::utils::format_number; use std::cell::Cell; use std::collections::HashMap; +use std::ffi::{OsStr, OsString}; use std::rc::Rc; #[allow(dead_code)] @@ -81,7 +82,7 @@ impl Procs { for pro in proc_list.values() { if let Some(exe) = pro .exe() - .and_then(|exe| exe.file_name().and_then(|f| f.to_str())) + .and_then(|exe| exe.file_name()) .or_else(|| Some(pro.name())) { create_and_fill_model( @@ -241,14 +242,23 @@ fn append_column( pub fn create_and_fill_model( list_store: >k::ListStore, pid: u32, - cmdline: &[String], - name: &str, + cmdline: &[OsString], + name: &OsStr, cpu: f32, memory: u64, ) { - if cmdline.is_empty() || name.is_empty() { - return; - } + let name = if name.is_empty() { + let Some(cmd) = cmdline + .iter() + .map(|c| c.to_string_lossy().to_string()) + .next() + else { + return; + }; + cmd + } else { + name.to_string_lossy().to_string() + }; list_store.insert_with_values( None, &[ diff --git a/src/display_sysinfo.rs b/src/display_sysinfo.rs index 809b3ca..22d28a1 100644 --- a/src/display_sysinfo.rs +++ b/src/display_sysinfo.rs @@ -143,9 +143,9 @@ impl DisplaySysInfo { p.set_margin_end(5); p.set_margin_start(5); p.set_show_text(true); - let processor = sys.global_cpu_info(); - p.set_text(Some(&format!("{:.1} %", processor.cpu_usage()))); - p.set_fraction(f64::from(processor.cpu_usage() / 100.)); + let cpu_usage = sys.global_cpu_usage(); + p.set_text(Some(&format!("{:.1} %", cpu_usage))); + p.set_fraction(f64::from(cpu_usage / 100.)); vertical_layout.append(p); } let check_box = create_header("Processors usage", &vertical_layout, settings.display_graph); @@ -368,9 +368,10 @@ impl DisplaySysInfo { let v = &*self.procs.borrow_mut(); let h = &mut *self.cpu_usage_history.borrow_mut(); - v[0].set_text(Some(&format!("{:.1} %", sys.global_cpu_info().cpu_usage()))); + let cpu_usage = sys.global_cpu_usage(); + v[0].set_text(Some(&format!("{:.1} %", cpu_usage))); v[0].set_show_text(true); - v[0].set_fraction(f64::from(sys.global_cpu_info().cpu_usage() / 100.)); + v[0].set_fraction(f64::from(cpu_usage / 100.)); for (i, pro) in sys.cpus().iter().enumerate() { let i = i + 1; v[i].set_text(Some(&format!("{:.1} %", pro.cpu_usage()))); diff --git a/src/main.rs b/src/main.rs index bdfb345..ae4c3b6 100755 --- a/src/main.rs +++ b/src/main.rs @@ -14,7 +14,7 @@ use gtk::prelude::*; use gtk::{gdk, gdk_pixbuf, gio, glib}; use gtk::{AboutDialog, Dialog, Entry, MessageDialog}; -use sysinfo::{Networks, Pid, RefreshKind}; +use sysinfo::{Networks, Pid, ProcessesToUpdate, RefreshKind}; use std::cell::RefCell; use std::collections::{HashMap, HashSet}; @@ -243,7 +243,7 @@ fn setup_timeout(rfs: &RequiredForSettings) { let sleep_dur = Duration::from_millis( *process_refresh_timeout.lock().expect("failed to lock process refresh mutex") as _); thread::sleep(sleep_dur); - sys.lock().expect("failed to lock to refresh processes").refresh_processes(); + sys.lock().expect("failed to lock to refresh processes").refresh_processes(ProcessesToUpdate::All, false); sender.send_blocking(()).expect("failed to send data through process refresh channel"); } }), diff --git a/src/process_dialog.rs b/src/process_dialog.rs index 039358b..2cd4ac7 100644 --- a/src/process_dialog.rs +++ b/src/process_dialog.rs @@ -180,7 +180,8 @@ pub fn create_process_dialog(process: &sysinfo::Process, total_memory: u64) -> P let popup = gtk::Window::new(); - popup.set_title(Some(&format!("Information about {}", process.name()))); + let name = process.name().to_string_lossy(); + popup.set_title(Some(&format!("Information about {name}"))); popup.set_transient_for(get_main_window().as_ref()); popup.set_destroy_with_parent(true); @@ -197,7 +198,7 @@ pub fn create_process_dialog(process: &sysinfo::Process, total_memory: u64) -> P let labels = gtk::Box::new(gtk::Orientation::Vertical, 0); - create_and_add_new_label(&labels, "name", process.name()); + create_and_add_new_label(&labels, "name", &name); create_and_add_new_label(&labels, "pid", &process.pid().to_string()); let memory_peak = process.memory(); let memory_usage = @@ -232,7 +233,7 @@ pub fn create_process_dialog(process: &sysinfo::Process, total_memory: u64) -> P process .cmd() .iter() - .map(|x| format!("\"{}\"", x)) + .map(|x| format!("\"{}\"", x.to_string_lossy())) .collect::>() .join(", ") ), @@ -272,6 +273,7 @@ pub fn create_process_dialog(process: &sysinfo::Process, total_memory: u64) -> P append_text_column(&env_tree, 1); for env in process.environ() { + let env = env.to_string_lossy(); let mut parts = env.splitn(2, '='); let name = match parts.next() { Some(n) => n, From 7120f0d287d37b24c1c35cfbce77261fd39ce002 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sun, 10 Nov 2024 22:56:04 +0100 Subject: [PATCH 2/2] Update minimum supported rust version to 1.74 --- .github/workflows/CI.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index cd6663c..0d9b5bf 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -26,7 +26,7 @@ jobs: - stable - beta - nightly - - "1.70" # Minimum supported version (from gtk-rs) + - "1.74" # Minimum supported version (from sysinfo) os: - ubuntu-22.04 - macos-latest